Fetching Cryptocurrency Prices from Coingecko and Displaying them on Grafana

Overview

cryptocurrency-prices-grafana

Fetching Cryptocurrency Prices from Coingecko and Displaying them on Grafana

About

This stack consists of:

  • Prometheus (timeseries database)
  • Pushgateway (introduces a /metrics endpoint for prometheus to scrape)
  • Grafana (the best)
  • Redis (k/v in memory store)
  • Python Script that pulls crypto market data, publishes to pushgateway for prometheus to scrape, and stores market data in Redis
  • Flask API to fetch market prices for other projects

I'm using coingecko's api which gives me 50 free calls per minute.

Walkthrough

Clone the repo:

git clone https://github.com/ruanbekker/cryptocurrency-prices-grafana

Change to the directory and build/start the containers:

cd cryptocurrency-prices-grafana
docker-compose up -d --build

Accessing Grafana, for me its locally on http://grafana.127.0.0.1.nip.io:3000

image

Using username admin and password admin.

Accessing Prometheus on http://prometheus.127.0.0.1.nip.io:9090, we can see we can fetch our metrics using promql:

  • cryptocurrency_price{provider="coingecko"}

image

When we access Pushgateway on http://pushgateway.127.0.0.1.nip.io:9091, we can see that prometheus is scraping pushgateway correctly:

image

When we create a Grafana Dashboard:

image

  • Query: cryptocurrency_price{provider="coingecko"}
  • Legend: {{coin}}

To add dashboard variables: Settings -> Variables -> Add New Variable

image

Head back to the dashboard and update your query to include the coin that you select from the dropdown at the top, which will be referenced as the variable:

cryptocurrency_price{provider="coingecko", coin=~"$coin"}

Which will introduce this:

image

Then it should look like this:

image

After some customization:

image

Coingecko allows 50 calls a minute, so for my own use-case I am fetching the data once a minute and store it in the redis cache, so that the api fetches the data from cache, so I can call my api as much as I want, the only downside is that the data will be a minute old.

We can see from redis that our data was cached:

docker exec -it rates-cache sh -c "redis-cli -n 1 keys \*"
1) "MATIC_TO_USD"
2) "LINK_TO_USD"
3) "DOGE_TO_USD"
4) "XRP_TO_USD"
5) "ADA_TO_USD"
6) "VET_TO_USD"
7) "TRX_TO_USD"
8) "ETH_TO_USD"
9) "BTC_TO_USD"

And to get the value of BTC in USD:

docker exec -it rates-cache sh -c "redis-cli -n 1 get BTC_TO_USD"
"49272"

Our Flask API uses the redis cache to fetch the values, and can be accessed like this:

curl http://api.127.0.0.1.nip.io:5000/coins/btc
{"acronymm":"BTC","current_price_in_usd":"49533"}

curl http://api.127.0.0.1.nip.io:5000/coins/matic
{"acronymm":"MATIC","current_price_in_usd":"2.32"}
Owner
Ruan Bekker
DevOps, AWS, Linux, Containers, Python, Automation, Systems Development, Blockchain and Open Source Enthusiast.
Ruan Bekker
FastAPI-PostgreSQL-Celery-RabbitMQ-Redis bakcend with Docker containerization

FastAPI - PostgreSQL - Celery - Rabbitmq backend This source code implements the following architecture: All the required database endpoints are imple

Juan Esteban Aristizabal 54 Nov 26, 2022
A fast and durable Pub/Sub channel over Websockets. FastAPI + WebSockets + PubSub == ⚡ 💪 ❤️

⚡ 🗞️ FastAPI Websocket Pub/Sub A fast and durable Pub/Sub channel over Websockets. The easiest way to create a live publish / subscribe multi-cast ov

8 Dec 06, 2022
Stac-fastapi built on Tile38 and Redis to support caching

stac-fastapi-caching Stac-fastapi built on Tile38 to support caching. This code is built on top of stac-fastapi-elasticsearch 0.1.0 with pyle38, a Pyt

Jonathan Healy 4 Apr 11, 2022
A RESTful API for creating and monitoring resource components of a hypothetical build system. Built with FastAPI and pydantic. Complete with testing and CI.

diskspace-monitor-CRUD Background The build system is part of a large environment with a multitude of different components. Many of the components hav

Nick Hopewell 67 Dec 14, 2022
Complete Fundamental to Expert Codes of FastAPI for creating API's

FastAPI FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3 based on standard Python type hints. The key featu

Pranav Anand 1 Nov 28, 2021
This project shows how to serve an ONNX-optimized image classification model as a web service with FastAPI, Docker, and Kubernetes.

Deploying ML models with FastAPI, Docker, and Kubernetes By: Sayak Paul and Chansung Park This project shows how to serve an ONNX-optimized image clas

Sayak Paul 104 Dec 23, 2022
A dynamic FastAPI router that automatically creates CRUD routes for your models

⚡ Create CRUD routes with lighting speed ⚡ A dynamic FastAPI router that automatically creates CRUD routes for your models

Adam Watkins 950 Jan 08, 2023
Opinionated authorization package for FastAPI

FastAPI Authorization Installation pip install fastapi-authorization Usage Currently, there are two models available: RBAC: Role-based Access Control

Marcelo Trylesinski 18 Jul 04, 2022
FastAPI Server Session is a dependency-based extension for FastAPI that adds support for server-sided session management

FastAPI Server-sided Session FastAPI Server Session is a dependency-based extension for FastAPI that adds support for server-sided session management.

DevGuyAhnaf 5 Dec 23, 2022
A Sample App to Demonstrate React Native and FastAPI Integration

React Native - Service Integration with FastAPI Backend. A Sample App to Demonstrate React Native and FastAPI Integration UI Based on NativeBase toolk

YongKi Kim 4 Nov 17, 2022
Get MODBUS data from Sofar (K-TLX) inverter through LSW-3 or LSE module

SOFAR Inverter + LSW-3/LSE Small utility to read data from SOFAR K-TLX inverters through the Solarman (LSW-3/LSE) datalogger. Two scripts to get inver

58 Dec 29, 2022
FastAPI backend for Repost

Repost FastAPI This is the FastAPI implementation of the Repost API. Installation Python 3 must be installed and accessible through the use of a termi

PC 7 Jun 15, 2021
api versioning for fastapi web applications

fastapi-versioning api versioning for fastapi web applications Installation pip install fastapi-versioning Examples from fastapi import FastAPI from f

Dean Way 472 Jan 02, 2023
Prometheus exporter for metrics from the MyAudi API

Prometheus Audi Exporter This Prometheus exporter exports metrics that it fetches from the MyAudi API. Usage Checkout submodules Install dependencies

Dieter Maes 7 Dec 19, 2022
Instrument your FastAPI app

Prometheus FastAPI Instrumentator A configurable and modular Prometheus Instrumentator for your FastAPI. Install prometheus-fastapi-instrumentator fro

Tim Schwenke 441 Jan 05, 2023
Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI

FastAPI Ariadne Example Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI - GitHub ###Запуск на локальном окру

ZeBrains Team 9 Nov 10, 2022
Lazy package to start your project using FastAPI✨

Fastapi-lazy 🦥 Utilities that you use in various projects made in FastAPI. Source Code: https://github.com/yezz123/fastapi-lazy Install the project:

Yasser Tahiri 95 Dec 29, 2022
Repository for the Demo of using DVC with PyCaret & MLOps (DVC Office Hours - 20th Jan, 2022)

Using DVC with PyCaret & FastAPI (Demo) This repo contains all the resources for my demo explaining how to use DVC along with other interesting tools

Tezan Sahu 6 Jul 22, 2022
CURSO PROMETHEUS E GRAFANA: Observability in a real world

Curso de monitoração com o Prometheus Esse curso ensina como usar o Prometheus como uma ferramenta integrada de monitoração, entender seus conceitos,

Rafael Cirolini 318 Dec 23, 2022
CLI and Streamlit applications to create APIs from Excel data files within seconds, using FastAPI

FastAPI-Wrapper CLI & APIness Streamlit App Arvindra Sehmi, Oxford Economics Ltd. | Website | LinkedIn (Updated: 21 April, 2021) fastapi-wrapper is mo

Arvindra 49 Dec 03, 2022