Azure IoT Edge – using Grafana on the Edge
Tags: azure, docker, grafana, azureiot
Published: 2020-05-03 10:43:45

---
title: Azure IoT Edge – using Grafana on the Edge
published: true
date: 2020-05-02 03:37:06 UTC
tags: azure,docker,grafana,azureiot
canonical_url: 
---


#Series
<a href="https://dev.to/chris_mckelt/azure-iot-edge-who-is-cooler-dotnet-node-or-python-369m" > 
Part 1 - dotnet vs python vs node - temperature emission - who is cooler?</a>
<a href="https://dev.to/chris_mckelt/azure-iot-edge-developing-custom-modules-df3" >Part 2 - Developing modules</a>
<a href="https://dev.to/chris_mckelt/azure-iot-edge-3rd-party-containers-3mi3" >Part 3 - Custom Containers using Apache Nifi</a>
<a href="https://dev.to/chris_mckelt/azure-iot-edge-using-timescaledb-on-the-edge-2ec1" >Part 4 - Custom Module using TimescaleDB</a>
<a href="https://dev.to/chris_mckelt/azure-iot-edge-using-grafana-on-the-edge-26na" >Part 5 - Custom Module using Grafana</a>
<h1>Intro</h1>
<p>This is part 5 in a series starting <a href="https://dev.to/chris_mckelt/azure-iot-edge-who-is-cooler-dotnet-node-or-python-369m">here</a> that runs through building an <a href="https://docs.microsoft.com/en-us/azure/iot-edge/about-iot-edge">Azure IOT Edge</a> solution. This post will run through setting up <a href="https://grafana.com/" target="_blank">Grafana</a> to visualise temperature readings sent from the dot net, python and node custom edge modules.</p>
<p>The code is located at: <a href="https://github.com/chrismckelt/edgy">https://github.com/chrismckelt/edgy</a></p>
<blockquote>
<p><a href="https://grafana.com/" target="_blank">Grafana</a> is the open source analytics and monitoring solution for every database</p>
</blockquote>
<h2>Steps to add the module</h2>
<h3>1. add a new <a href="https://github.com/chrismckelt/edgy/tree/master/modules/Grafana">custom module</a>&nbsp;</h3>
<p><img alt="" src="https://user-images.githubusercontent.com/662868/80546306-e1627c00-89e7-11ea-8ceb-434b79aed040.png"></p>
<h3>2. add a new <a href="https://github.com/chrismckelt/edgy/blob/master/deployment.debug.grafana.template.json">deployment file</a> just for Grafana (and amend the <a href="https://github.com/chrismckelt/edgy/blob/master/deployment.debug.template.json">full solution file</a>)</h3>
<p><img alt="" src="https://user-images.githubusercontent.com/662868/80546722-03a8c980-89e9-11ea-8735-051f381f16a3.png"></p>
<h3>3. create the <a href="https://github.com/chrismckelt/edgy/blob/master/modules/Grafana/Dockerfile.amd64.debug">docker file</a></h3>
<h6>FROM grafana/grafana:latest</h6>
<h6># login with admin and below password to web interface</h6>
<h6>ENV GF_SECURITY_ADMIN_PASSWORD [<em>YOUR_GRAFANA_PASSWORD_HERE]</em></h6>
<h6>ENV GF_AUTH_LDAP_ENABLED=false</h6>
<h6>ENV GF_DATABASE_TYPE postgres</h6>
<h6>ENV GF_DATABASE_HOST timescaledb</h6>
<h6>ENV GF_DATABASE_NAME grafana</h6>
<h6>ENV GF_DATABASE_USER grafana</h6>
<h6>ENV GF_DATABASE_PASSWORD [<em>YOUR_DATABASE_PASSWORD_HERE]</em></h6>
<h6>COPY ldap.toml /etc/grafana/</h6>
<h6>COPY custom.ini /etc/grafana/</h6>
<h3>4. create the <a href="https://github.com/chrismckelt/edgy/blob/master/modules/Grafana/custom.ini">custom.ini</a></h3>
<p>make sure to enter the database password on line 75</p>
<h3>5. build and run IoT Edge solution in simulator</h3>
<h6><img alt="" src="https://user-images.githubusercontent.com/662868/80850862-d5c5be00-8c50-11ea-8cda-67a65caf058f.png"></h6>
<h3>6. Navigate to <a href="http://localhost:8082/">http://localhost:8082/</a> and login (admin + your grafana password)</h3>
<p>The Grafana setup board should appear as below</p>
<p><img alt="" src="https://user-images.githubusercontent.com/662868/80850936-36ed9180-8c51-11ea-9152-9714976a00f7.png"></p>
<h3>7. Add data source –&gt; PostgreSQL</h3>
<p><img alt="" src="https://user-images.githubusercontent.com/662868/80851051-de6ac400-8c51-11ea-9b9c-9498307fcbef.png"></p>
<h3>8. Add a dashboard query &amp; set the query as below</h3><p><img src="https://user-images.githubusercontent.com/662868/80911764-144f9b80-8d6b-11ea-96cb-1f1c24432b4f.png"></p><p>A time series graph will display the 3 temperature readings over time.</p><p><img src="https://user-images.githubusercontent.com/662868/80911783-2598a800-8d6b-11ea-9a48-b21db723b8f0.png"></p>
<h1>Outro</h1>
<p>Here we have added Grafana to our IoT Edge solution and created a dashboard from the data stored in <a href="https://www.timescale.com/">TimescaleDB</a>. The generated temperature sent from the 3 modules is analysed by <a href="https://dev.to/chris_mckelt/azure-iot-edge-3rd-party-containers-3mi3" target="_blank">Apache Nifi</a>. When the temperature is greater than 25 degrees a request is sent back to the specific module to activate the air conditioner, which makes the temperature randomly decrease over time.</p>
<p>Think I would prefer the Python room as it appears the <a href="https://user-images.githubusercontent.com/662868/80854122-2bf22b80-8c68-11ea-919c-4833ac0847b8.png" target="_blank">coolest!</a></p>