A MacBook (laptop) displaying code being edited in VSCode. A glass and bottle of red wine located next to the MacBook.

GitHub maintains a lot of data on activity taking place on GitHub, which means its data rich for a dashboard. Want to know how often a repository sees commits? How long pull requests stay open for? Who the top contributor is? or how long a GitHub Action is taking to run? Then a dashboard can help.

GitHub Dashboard

Rather than clicking through GitHub pages to gather the data, a dashboard allows for it all to be centralised on one page. My example Grafana dashboard for GitHub is being used to show:

  • Number of pull requests created
  • Pull requests awaiting review
  • Number of commits
  • A table of commit details
  • A list of contributors
  • A table of pull request details
  • A gauge to show how long a workflow (GitHub Action) is taking to run
A Grafana dashboard, which contains several panels. The panels include one showing the number of pull requests created, the number of active pull requests, and the number of commits. There is a panel which is a table of commits which shows id, author, committed at date/ time and commit message. A Pull Request table displays pull request number, a title, and the number of additions. A gauge panel is displaying workflow run time. It has 3 green bars lit to indicate that 10 seconds is a good state for the run time. The gauge has a yellow warning state between 90 and 120 seconds, with a red warning state between 120 and 180 seconds.
Grafana GitHub Dashboard

The JSON of the dashboard is stored in my GitHub Repository, it’s over 1000 lines of JSON so a bit too much to post in this blog entry.

GitHub Authentication Required

To use the GitHub dashboard requires some GitHub Authentication. This can either be a GitHub Personal Access Token (PAT) or a GitHub App. Either of these can be set up in the Settings of your GitHub Account. Please make sure to keep the auth details secret once you create them, and where possible make sure to keep the permissions of the PAT/App limited. For my project I’m using a PAT that is limited to read permissions on just my grafana_playground repository.

Docker Environment for GitHub Plugin

I have used an environment variable in my Docker Compose file to install the GitHub Plugin into my Grafana environment:

services:
grafana:
image: grafana/grafana
container_name: grafana
restart: unless-stopped
environment:
- GF_SERVER_ROOT_URL=http://grafana.local
- GF_PLUGINS_PREINSTALL=grafana-github-datasource
ports:
- '3000:3000'
volumes:
- 'grafana_storage:/var/lib/grafana'
volumes:
grafana_storage: {}

Terraform To Deploy GitHub Data Source

With the GitHub plugin installed, I am using Terraform to add a GitHub data source so that Grafana can query GitHub. My GitHub token is being stored in a vars file.

resource "grafana_data_source" "github" {
type = "grafana-github-datasource"
name = "github-geektechstuff"
secure_json_data_encoded = jsonencode({
"selectedAuthType" = "personal-access-token"
"accessToken" = var.github_token
})
}

Terraform To Deploy GitHub Dashboard

The GitHub plugin and data source are in place. I can then either add a dashboard manually, installed one from Grafana, or deploy one using Terraform. I am currently using Terraform to deploy my dashboards.

resource "grafana_folder" "geektechstuff" {
title = "geektechstuff folder"
}
resource "grafana_dashboard" "geektechstuff_github" {
folder = grafana_folder.geektechstuff.id
for_each = fileset("../grafana_dashboards/", "*.json")
config_json = jsonencode(merge(jsondecode(file("../grafana_dashboards/${each.key}")),
{tags = ["TERRAFORM-MANAGED"]} ))
overwrite = true
}

View The Code

Want to see how all this fits in with the rest of my Grafana work? It’s all stored in my Grafana GitHub repository.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Welcome to GeekTechStuff

My home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect