> ## Content Index
> Fetch the complete content index at: https://brianchristner.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Monitor your GitHub Repos with Docker and Prometheus
- URL: https://brianchristner.io/monitor-your-github-repos-with-docker/
- Published: 2017-02-21T15:49:00.000Z
- Updated: 2024-08-13T19:03:05.000Z
- Author: Brian Christner
- Tags: Docker, Monitoring

GitHub is full of great code, information, and interesting statistics. GitHub repositories are full of statistics that make perfect candidates to graph with Grafana. 

> , which produces

Prometheus contains an impressive list of [Exporters](https://prometheus.io/docs/instrumenting/exporters/?ref=brianchristner.io). These Exporters range from APIs to IoT. They can also integrate with Prometheus and Grafana, which produce 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](https://github.com/vegasbrianc/github-monitoring?ref=brianchristner.io) from the previous [Docker Monitoring article](https://brianchristner.io/how-to-setup-docker-monitoring/). This contains a Docker compose file which makes this stack simplified and easy to start.

## Getting Started

**Prerequisite*: ensure you have a Docker host running the latest versions of the Docker engine and compose.*** 

If you are running Docker for Mac/Windows, you are already set. Next, clone the [GitHub-Monitoring](https://github.com/vegasbrianc/github-monitoring?ref=brianchristner.io) 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](https://github.com/vegasbrianc/github-monitoring/blob/master/prometheus/prometheus.yml?ref=brianchristner.io) 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']

```

## Configuration

Create a GitHub token for this project. This will prevent us from hitting GitHub's API limits for non-authenticated traffic.

Navigate to [Create GitHub Token](https://github.com/settings/personal-access-tokens/new?ref=brianchristner.io) where we will create a token for this project.

- Provide the token with a description.
- Select scopes: our project only requires the `repo` permissions.
- Click the generate token button.
- Copy the token ID and store it in a safe place. This is the equivalent of a password, so don't store it in a public place.

![GitHub Token](https://storage.ghost.io/c/29/50/2950930d-60f2-422c-90aa-232fbd4873b6/content/images/2017/02/github_token.png)

Edit the [docker-compose.yml](https://github.com/vegasbrianc/github-monitoring/blob/master/docker-compose.yml?ref=brianchristner.io) file with your favorite editor. Scroll to the end of the file where you will find the `metrics`service section.

First, replace `GITHUB_TOKEN=<GitHub API Token see README> `with the token you generated earlier. Next, replace it with the REPOS `, I REPOS`you want to track. In my example, I 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 initially elected to run docker-compose without the `-d` flag flag. This makes it easier to troubleshoot and see logs printed to the terminal.

The Grafana Dashboard is now accessible via: `http://<Host IP Address>:3000` for example [http://localhost:3000](http://localhost:3000/?ref=brianchristner.io)

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

## Post Configuration

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

- Click the `Grafana` The menu at the top left corner (looks like a fireball)
- Click `Data Sources`
- Click the green button `Add Data Source`.

!\[Add Grafana Data Source\](/content/images/2017/02/Grafana\_Add\_Data\_Source-1.png)

## Install Dashboard

I created a dashboard template that is available on the [GitHub Stats Dashboard](https://grafana.net/dashboards/1559?ref=brianchristner.io). Download the dashboard and select from the Grafana menu -> Dashboards -> Import.

This dashboard is a starting point for graphing your GitHub Repos. If you have any changes you would like to see in the Dashboard, let me know so I can update the Grafana site as well.

![GitHub Grafana Dashboard](https://storage.ghost.io/c/29/50/2950930d-60f2-422c-90aa-232fbd4873b6/content/images/2017/02/GitHub_Grafana_Dashboard.png)

## Conclusion

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.

### Follow me

If you liked this article, [Follow Me](https://twitter.com/idomyowntricks?ref=brianchristner.io) on Twitter to stay updated!

## Sign up for BrianChristner.io

I write Dockerfiles, Build Products, Share Ideas, and crash Mountain Bikes

Subscribe 

Email sent! Check your inbox to complete your signup. 

No spam. Unsubscribe anytime.