This intended to be a multi-part series on how to host Grafana safely, and cheaply on Azure, and how to get some decent visbility from Azure Monitor/App Insights through it. Hopefully parts of this will be useful.
- Part 1 – Hosting/Configuration (this post)
- Part 2 – Azure MySQL storage
- Part 3 – SSL with LetsEncrypt
- Part 4 – Azure AD Login
- Part 5 – Azure Monitor Datasource (Coming Soon)
Overview
In this first post, we’ll look at building a Grafana Instance with a managed MySQL instance using Azure MySQL.
The aim simplicity, speed of deployment, reduced management overhead and cost.
There as a balancing act to be done here. Speed and simplicity could be achieved using a database on the machine, that’s then backed up, at the expense of management overhead. Reduced Management could be achieved using ACI or App Service, at the expense of cost (unless you already have a container infrastructure). The solution here, I believe, gives a fair balance
Why Grafana
Grafana has been my go-to tool for a long time and therefore where I’m comfortable. I’m sure that some or all of what I’m doing here could be achieved with Azure Dashboard, but I haven’t learnt this yet.
Grafana is a graphing tool that allows you represent data from multiple sources. In modern development, we don’t use just a single provider for our platforms, therefore visualisation needs to be able to draw in multiple sources.
Grafana Cloud
A quick note on Grafana Cloud. This is Grafana’s Managed Service offering and provides an easy way to get up and running without hosting it yourself. The pricing is a little expensive once you get to 20-30 users, which the installation I’m proposing can handle. For 10 users, at $49/month, it’s a steal, and I’d recommend that route. If you want to start pushing these dashboards out to business stakeholders, every developer, it can start to get expensive.
There is also now an AWS Managed version, which is even more expensive at $9/month/user, https://aws.amazon.com/grafana/pricing/. This seems very expensive to me, especially as that doesn’t include the enterprise plugins like Timestream.
_ Note : for Grafana staff, you should should look at adding unlimited “View Only” users, or a 4:1 ratio of free to paid users just for viewing dashboards like stackholders and wallboards._
Step 1 – Create the Azure Virtual Machine
Grafana requires VERY little resources, unless you’re running this at scale. This is because, for the most part, it’s just proxying queries from the user’s browser to the Analytics backend (e.g. InfluxDB, AppInsights, CloudWatch, etc.). This changes as you add support for alerting, but it’s still not a massive amount, and as we’ll be using Azure analytics, most of the alerting will come from there.
For this tutorial, I’ve successfully run this using a B1Ls which is currently ~£5/month. We’ll be using Ubuntu, so all the commands and paths will be based on that. For this we’ll be using Ubuntu 20.04.
Create a standard B1LS virtual machine with Ubuntu 20.04, you’ll need to open up port 22, and have access to the SSH key. It’s out of scope of this post to explain how to create VMs.
Step 2 – Install Grafana
SSH onto the machine
nano install-grafana.sh
Then paste this into the file.
#!/bin/sh
sudo apt install -y software-properties-common
#add grafana to list of allowed software
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt update && apt install -y grafana
sudo systemctl enable grafana-server.service
sudo systemctl start grafana-server
You’ll notice from the above that it’s adding a respository. This is adding grafana’s package respository that will override the default ubuntu packages. This means you’ll be getting the very latest version of Grafana.
Save the file (Ctrl+X) and then we need to make the file executable
chmod +x install-grafana.sh
As the script will be installing some things, you’ll need to run it with super user permissions.
sudo ./install-grafana.sh
That will get you a running grafana instance, with a local sqlite database on the machine. Meaning that if the machine dies, and you haven’t used persistent disks, you’ll lose all of the data. Obviously we could stop here and use persistent disks, but that would mean we’d lose the ability to scale-out, and also the ability to image the machine in case of corruption, etc. You’re stuck with “fixing” the machine’s image, which isn’t the cloud way.
Once you’ve run the above you’ll need to open up grafana’s default Port (3000).
Once that port has been opened up, you should be able to access the grafana instance using the following
http://<ip>:3000/
The default credentials are admin/admin, and once you’ve put those in, you’ll need to set a new password for admin. In a further step we’ll add Azure AD credentials for logging, but for now, this will be what is used to login.
Conclusion
This is post shows the basics of getting a Grafana instance working on an Azure VM. In the next posts we’ll work on making this more resilient and secure.
You can stop at this point and have a fully functioning grafana instance that you can configure and use. You can mitigate outages by making the disk persistent so it can be restored into another VM. However, in the next post, you’ll see how we can leverage Azure MySQL PaaS to host the database so the VM will become largely irrelevant.
Top comments (0)