GitHub is full of great code, information, and interesting statistics. GitHub repositories are full of statistics that make perfect candidates to graph with Grafana. The best way to graph this data is of course with Docker and Prometheus.
Prometheus contains an impressive list of Exporters. These Exporters range from APIs to IoT. They can also integrate with Prometheus and Grafana which produce some beautiful graphs.
Docker, Prometheus, and Grafana
My base setup for anything monitoring related is the Docker, Prometheus, and Grafana stack. This is the baseline I work from and add components like Exporters. I have created the GitHub-Monitoring Repo. This contains a Docker compose file which makes this stack simplified and easy to start.
Prerequisite Ensure you have a Docker host running the latest versions of Docker engine and compose. If you are running Docker for Mac/Windows you are already set. Next, clone the GitHub-Monitoring project to your Docker machine.
We can start configuring the project based on your requirements. If you need to track additional Exporters or targets then edit the Prometheus Targets section located in the static configs section at the end of the file. The Exporter uses the name metrics with port 9171.
static_configs: - targets: ['node exporter:9100','localhost:9090', 'metrics:9171']
Create a GitHub token to use for this project. This prevents us from hitting API limits imposed by GitHub for non-authenticated traffic.
Navigate to Create GitHub Token where we will create a token for this project.
- Provide the token a description.
- Select scopes, our project only requires the
- Click the generate token button
- Copy the token ID and store in a safe place. This is the equivalent of a password so don't store in a public place
Edit the docker-compose.yml file with your favorite editor. Scroll to the end of the file where you will find the
First, replace the
GITHUB_TOKEN=<GitHub API Token see README>with the token you generated earlier. Next, replace the
REPOS with your desired REPOS with which you want to track. In my example I have selected the Docker and freeCodeCamp REPOS as they offer lots of movement and stats.
metrics: tty: true stdin_open: true expose: - 9171 image: infinityworks/github-exporter:latest environment: - REPOS=freeCodeCamp/freeCodeCamp,docker/docker - GITHUB_TOKEN=<GitHub API Token see README> networks: - back-tier
Once configurations are complete let's start it up. From the /github-monitoring project directory run the following command:
$ docker-compose up
That's it. docker-compose builds the entire Grafna and Prometheus stack automagically. The compose file also connects the new GitHub Exporter to our baseline stack. I have elected to run docker-compose without the
-d flag initially. This makes it easier for troubleshooting to see logs printed to the terminal.
The Grafana Dashboard is now accessible via:
http://<Host IP Address>:3000 for example http://localhost:3000
username - admin
password - foobar (The password is in the
config.monitoring env file)
Now we need to create the Prometheus Datasource to connect Grafana to Prometheues
- Click the
GrafanaMenu at the top left corner (looks like a fireball)
- Click the green button
Add Data Source.
I created a Dashboard template which is available on GitHub Stats Dashboard. Download the dashboard and select from the Grafana menu -> Dashboards -> Import
This dashboard is a starting point to help you get started with graphing your GitHub Repos. If you have any changes you would like to see in the Dashboard let me know so I can update Grafana site as well.
Prometheus in combination with Docker is a powerful yet simple to manage. The GitHub Exporter is one of the many amazing Exporters available to Prometheus. The next few articles I will select several more Exporters to show how easy they are to connect and graph data. Stay tuned.
Subscribe to BrianChristner.io
Get the latest posts delivered right to your inbox