How to Monitor Cryptocurrencies with Docker & Prometheus

By Brian Christner | February 28, 2018


Cryptocurrency Tracker Dashboard


The Crypto craze has not hit full saturation until I release some tool to monitor it. Since I enjoy building monitoring projects, I felt it was the right time to re-purpose the Docker Prometheus stack for something even more significant. Enter stage right, Monitoring Cryptocurrencies.

I happen to live in what is called Crypto Valley, Switzerland. We have more Crypto startups per-capita than anywhere else in the world. What is lacking in “the Valley” is a Crypto Monitoring Project from me. Well, the wait is over.

The Cryptocurrency Tracker

I bought a few different Cryptocurrencies but the platforms which I purchased them through leave a lot to be desired when it comes to data visualizations. The idea of the CryptoCurrency Tracker project is to collect Crypto data, store it, and create some trend visualizations. I reviewed several API’s, but they all seem to focus on real-time or trading data. The data available via the CoinMarketCap.com API is exactly what I am looking for.

CoinMarketCap Data

Below is example API data available for BitCoin. The API is quite powerful and contains a lot of useful data which we can visualize. 

    "rank": "1",
    "price_usd": "573.137",
    "price_btc": "1.0",
    "24h_volume_usd": "72855700.0",
    "market_cap_usd": "9080883500.0",
    "available_supply": "15844176.0",
    "total_supply": "15844176.0",
    "percent_change_1h": "0.04",
    "percent_change_24h": "-0.3",
    "percent_change_7d": "-0.57",
    "last_updated": "1472762067"

However, in order for this data to be useful inside Prometheus it should be converted to the Prometheus Exporter format. That’s when I discovered Bill Cawthra wrote a Prometheus Exporter which does exactly that.

CoinMarketCap Docker Stack

Cryptocurrency Tracker Architecture

The stack is based on the tried, tested, and several times repurposed Docker Prometheus stack. The focus of this stack is only to pull the CoinMarketCap data and nothing more.  The CoinMarketCap exporter queries the API and exposes the results in the form of Prometheus metrics. Prometheus then scrapes the metrics and is visualized by Grafana. Alerts can be configured either by Prometheus or Grafana, but we will address Alerting in the next release.

Cryptocurrency Tracker Quick Start

Would you like to try the Crypto Currency Tracker without having to install Docker? I created an easy, quick start which installs the entire stack to Play-With-Docker (PWD). PWD is is a browser-based Docker playground for testing things or training purposes. It deploys virtual instances that remain active for 4 hours free of charge. The only requirement is that you need to create a login for Docker which is also free. The quick start will deploy and install Docker, Docker Swarm, Prometheus, Grafana and the CoinMarketCap exporter. 

Here’s the Quickstart → Crypto Currency Quick Start

Once the install completes carry on to configuration steps below.


Install & Configure Crypto Currency Tracker

For those of you that prefer to install and configure Crypto Currency Tracker yourself this section is for you. We will be utilizing the code from the Crypto Currency Tracker Repo for those that want to look at the code first.

Pre-requisites

Before we get started. Ensure you install the latest version of Docker and docker swarm on your Docker host machine. Docker Swarm is installed automatically when using Docker for Mac or Docker for Windows.

  1. Clone the Repo Clone the Repo from GitHub to your Docker host machine.

    $ git clone https://github.com/vegasbrianc/crypto-currency-tracker.git

  2. Deploy the stack Change to the crypto-currency-tracker directory and run the following command:

    $ HOSTNAME=$(hostname) docker stack deploy -c docker-compose.yml crypto

    That’s it the docker stack deploy command deploys the entire Docker, Prometheus, Grafana and CoinMarketCap stack automagically to the Docker Swarm. 

    Wait a minute for everything to download and install

  3. Check the Status To check the status of the newly created stack:

    $ docker stack ps crypto
    

    View running services:

    $ docker service ls
    

    View logs for a specific service

    $ docker service logs crypto_<service_name>
    

Configure Grafana

The Grafana interface is now accessible via: http://:3000 for example http://192.168.10.1:3000

username - admin
password - foobar (Password is in the `config.monitoring` env file)

Now we need to create the Prometheus Datasource to connect Grafana to Prometheus 

  • Click the Grafana Menu at the top left corner (looks like a fireball)
  • Click Data Sources
  • Click the green button Add Data Source

Add the data source precisely as the screenshot below:

Install Grafana Dashboard

I updated the projects Dashboard to add a little bit more flair. You can have a look at the dashboard Grafana Docker Dashboard To install, simply import the dashboard and select from the Grafana menu -> Dashboards -> Import and use the Dashboard ID 4893 and select “Prometheus” as the data source..

Select the drop-down menu “Home” at the upper left of Grafana. Select the Crypto Currency Tracker Dashboard. Next, you will see a filter at the top of the dashboard. It will provide all the currencies which we monitor. Select BitCoin to start. 

The upper right-hand corner of the Grafana UI you will find the Time Range. Here we can select the time frame which the dashboards display. The longer the stack runs the longer we can display data. For example, one month.

It could take a moment before data starts populating.

Security Considerations

This project is intended to be a quick-start to get up and running monitoring Crypto Currencies with Docker, Prometheus, and Grafana. Security is not considered in this project. It is the user’s responsibility to implement Firewall/IP Tables, SSL, and access control. Since this is a template to get started Prometheus and Alerting services are exposing their ports to allow for easy troubleshooting and understanding of how the stack works.


Summary

You should be well on your way to monitoring Cryptocurrencies with the Crypto Currency Tracker. We have deployed the stack, configured the dashboard, and now we can sit back and watch the Crypto metrics roll in.

Docker and Prometheus make this astonishing feat actually seem very simple. Looking at the architecture a lot is going on behind the curtain, but it is deployed with one command.

Next Steps

Now that we have the first version of the Cryptocurrency Tracker in the wild we will slowly start adding features to the stack like alerting and actions based on metrics. Stay tuned and star the repo to keep track of the progress.

Find out more about 56K.Cloud

We love Cloud, Containers, DevOps, and Infrastructure as Code. If you are interested in chatting connect with us on Twitter or drop us an email: info@56K.Cloud We hope you found this article helpful. If there is anything you would like to contribute or you have questions, please let us know!