Beginning visualization with GRAFANA and INFLUXDB
We are dealing with a huge amount of data in our daily life. It adds good value if we can visualize our data and make some relation between them. Data visualization and analytic provide more control over data and give us the power to control this data efficiently.
Grafana is an open-source, feature-rich metrics dashboard, and graph editor. Grafana supports over 30 open source and commercial data sources including Graphite, Elasticsearch, OpenTSDB, Prometheus, and InfluxDB. Grafana has a plethora of visualization options to help and understand data beautifully. Another alternative of Grafana is Kabana. In this tutorial, I will discuss how to start Grafana with InfluxDB. So let’s get started.
Installation of Grafana is fairly simple. Go to https://grafana.com/get site, you will find two options: You run it or We host it. The first option is to run your own machine, you can click on the download button and according to your OS, just follow their installation note. The second hosted option has several free and commercial plans. For testing purposes, it is best to register and start the free available option.
In this tutorial, I will use a free hosted version but if you want you can install and download the desktop version. Both of them work similarly. So at this point, let’s install InfluxDB. Just go to the download page of InfluxDB: https://portal.influxdata.com/downloads and download according to your OS. Installation is simple and straight. After that, start InfluxDB service and you are ready to go.
To show available databases, write the following command in the InfluxDB prompt:
There is only one system database named _internal. We can create a new database,
CREATE DATABASE testdata
It will produce no output in the command prompt but will generate our first database named firstData. To view,
Now it shows the name of our new database. But this database is empty. To fill with data, we have to select this database,
After that, we can fill the database with our own data,
INSERT temp,Name=data1 value=1.5
We can use SHOW command to view data,
SELECT * FROM temp
Here influxdb will automatically insert a timestamp. To exit, use
Now we want to create some sample data, for this purpose, we will use some script to fill the sample data.
Download sample data from the following link:
To import this data, we have to write this command
influx -import -path=NOAA_data.txt -precision=s -database=NOAA_water_database
Check our newly created database,
Use the newly created database and show measurements
Select 5 data from the database
SELECT * FROM h2o_temperature LIMIT 5
Now we will create the visualization part in Grafana, let’s go to the Grafana dashboard and create our first visualizer.
We have to define the data source first,
Click Configuration->Data Source and select a proper value:
If everything is okay, it will show Data Source is working message.
After that create a new dashboard.
Click Panel Title->Edit
In the lower part, from Metrics tab select data source as NOAA_water_database and data field as h2o_temparature
You can also write your query in the toggle edit mode option.
Select time range from the upper right corner and it will show a visualization of your data.
This visualization will update if you add new data to the database.
Hope this will give you a basic idea about Grafana and Influxdb. Please let me know if you have any questions.