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

Grafana is a great visualisation tool to help display logs, metrics, and traces, a.k.a the bits observability needs. It has a variety of plugins, data sources, and lots of potential when creating dashboards. Grafana has an open source version, an enterprise version, and a cloud version (with a free tier).

A playground for learning

With all that potential, and so many different plugins / data sources available it can be a little daunting. Grafana offers tutorials and a learning hub, but sometimes its best to get hands on and try to get stuff to work.

As noted in the introduction, Grafana Cloud offers a free tier. So if you’re looking for instant Grafana action that may be your best option. However, I’m going for a new deployment locally.

What does it run on?

As with my previous Grafana posts (has it really been 5 years?) I am deploying Grafana in my homelab. It may take a little configuration change but most of the resources (e.g. docker containers) can be used with a cloud provider, and the infrastructure as code (e.g. Terraform) should work against current instances of Grafana.

For my “Grafana Playground” I am using a Raspberry Pi 4 with 4GB RAM and a 64GB microSD card. The Pi4 is running Raspberry Pi OS Lite (64 bit) which is a port of Debian Trixie.

GitHub Repository

My GitHub repository which relates to this blog post is at: https://github.com/geektechdude/grafana_playground

What’s included?

I’ve added a few components that typical Grafana deployments have, so are good to play around with. Each has its own Docker Compose file as I might not want to run all of them at the same time, or might want to throw some of them onto a different devices (would need to adjust configuration).

Alloy

Grafana Alloy combines collectors together. A Docker compose file brings up Alloy in a container.

Grafana

The visualisation platform. A Docker compose file that starts Grafana running on port 3000.

Loki

A log aggregation system that can be used to store logs, then added to Grafana as a data source allowing Grafana to query them. A Docker compose file runs Loki on port 3100.

Prometheus

Prometheus for time based metrics. A Docker compose file runs Prometheus on port 9090.

Grafana Dashboards

I’m adding dashboards here that I’m building or testing ideas in. They are stored in JSON and can either be manually copied into Grafana, or deployed via Infrastructure as Code with Terraform.

Terraform

Terraform to deploy data sources, dashboards and folders within Grafana. It requires a token creating in Grafana first, but then Terraform can managed Grafana. This instance is not storing the backend state remotely.

Random Code Bits I Found Useful

Not so much a Grafana thing, but I found myself using some code snippets that may be helpful again in future so making a note of them.

Creating Multiple README.md Files

I have added README.md files to each sub-directory within the repository, with the idea being I will fill in each README.md with key information. Creating these could have been a manual create, but instead I used:

for d in */ ; do echo "$d"; touch "${d}README.md"; done

This breaks down into “for sub-directory in current directory”, “echo the sub-directory’s name”, then “create sub-directory/README.md”, done.

Removing Multiple Unused Git Branches

I branch quite a bit when trying and testing new ideas. This sees quite a few branches left on my local machine which have been merged and deleted on the remote repository.

git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d

git fetch -p updates the status of the branches on my machine. git branch –vv shows the very verbose status of those branches. awk then looks for branches that have been marked as gone (deleted on the remote) and passes those branch names through to git branch -d which deletes them.

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