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
Пример использования GraphQL Ariadne с FastAPI и сравнение его с GraphQL Graphene FastAPI

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

ZeBrains Team 9 Nov 10, 2022
A simple Redis Streams backed Chat app using Websockets, Asyncio and FastAPI/Starlette.

redis-streams-fastapi-chat A simple demo of Redis Streams backed Chat app using Websockets, Python Asyncio and FastAPI/Starlette. Requires Python vers

ludwig404 135 Dec 19, 2022
FastAPI interesting concepts.

fastapi_related_stuffs FastAPI interesting concepts. FastAPI version :- 0.70 Python3 version :- 3.9.x Steps Test Django Like settings export FASTAPI_S

Mohd Mujtaba 3 Feb 06, 2022
스타트업 개발자 채용

스타트업 개발자 채용 大 박람회 Seed ~ Series B에 있는 스타트업을 위한 채용정보 페이지입니다. Back-end, Frontend, Mobile 등 개발자를 대상으로 진행하고 있습니다. 해당 스타트업에 종사하시는 분뿐만 아니라 채용 관련 정보를 알고 계시다면

JuHyun Lee 58 Dec 14, 2022
Cube-CRUD is a simple example of a REST API CRUD in a context of rubik's cube review service.

Cube-CRUD is a simple example of a REST API CRUD in a context of rubik's cube review service. It uses Sqlalchemy ORM to manage the connection and database operations.

Sebastian Andrade 1 Dec 11, 2021
Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.

The Mixer is a helper to generate instances of Django or SQLAlchemy models. It's useful for testing and fixture replacement. Fast and convenient test-

Kirill Klenov 871 Dec 25, 2022
Flood Detection with Google Earth Engine

ee-fastapi: Flood Detection System A ee-fastapi is a simple FastAPI web application for performing flood detection using Google Earth Engine in the ba

Cesar Aybar 69 Jan 06, 2023
FastAPI Skeleton App to serve machine learning models production-ready.

FastAPI Model Server Skeleton Serving machine learning models production-ready, fast, easy and secure powered by the great FastAPI by Sebastián Ramíre

268 Jan 01, 2023
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
Sample-fastapi - A sample app using Fastapi that you can deploy on App Platform

Getting Started We provide a sample app using Fastapi that you can deploy on App

Erhan BÜTE 2 Jan 17, 2022
A simple example of deploying FastAPI as a Zeit Serverless Function

FastAPI Zeit Now Deploy a FastAPI app as a Zeit Serverless Function. This repo deploys the FastAPI SQL Databases Tutorial to demonstrate how a FastAPI

Paul Weidner 26 Dec 21, 2022
OpenAPI for Todolist RESTful API

swagger-client OpenAPI for Todolist RESTful API This Python package is automatically generated by the Swagger Codegen project: API version: 1 Package

Iko Afianando 1 Dec 19, 2021
Ansible Inventory Plugin, created to get hosts from HTTP API.

ansible-ws-inventory-plugin Ansible Inventory Plugin, created to get hosts from HTTP API. Features: Database compatible with MongoDB and Filesystem (J

Carlos Neto 0 Feb 05, 2022
Local Telegram Bot With FastAPI & Ngrok

An easy local telegram bot server with python, fastapi and ngrok.

Ömer Faruk Özdemir 7 Dec 25, 2022
Twitter API monitor with fastAPI + MongoDB

Twitter API monitor with fastAPI + MongoDB You need to have a file .env with the following variables: DB_URL="mongodb+srv://mongodb_path" DB_URL2=

Leonardo Ferreira 3 Apr 08, 2022
Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⭐

FRDP Boilerplate code for quick docker implementation of REST API with JWT Authentication using FastAPI, PostgreSQL and PgAdmin ⛏ . Getting Started Fe

BnademOverflow 53 Dec 29, 2022
Signalling for FastAPI.

fastapi-signals Signalling for FastAPI.

Henshal B 7 May 04, 2022
A minimum reproducible repository for embedding panel in FastAPI

FastAPI-Panel A minimum reproducible repository for embedding panel in FastAPI Follow either This Tutorial or These steps below ↓↓↓ Clone the reposito

Tyler Houssian 15 Sep 22, 2022
🚀 Cookiecutter Template for FastAPI + React Projects. Using PostgreSQL, SQLAlchemy, and Docker

FastAPI + React · A cookiecutter template for bootstrapping a FastAPI and React project using a modern stack. Features FastAPI (Python 3.8) JWT authen

Gabriel Abud 1.4k Jan 02, 2023
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python Examples. The beyonic APIs Doc Reference: https://apidocs.beyonic.com/ To start using the Beyonic API Python API, you need to start

Harun Mbaabu Mwenda 46 Sep 01, 2022