Grafana is open source platform for visualization and analytics of the metrics. It helps you to query, alert on, visualize, and explore your metrics from different data sources such as Prometheus, Influx DB, JSON, etc. It offers you the ability to transform your time-series database (TSDB) data into stunning graphs and visualizations. For visualization of all target metrics it can be easily integrated with Prometheus.
In this blog we will learn,
installation of Grafana on a Linux server,
adding Prometheus data source,
creating a custom dashboard for Prometheus data source
importing predefined Grafana dashboard templates.
To continue with this blog and learn it better, there are some prerequisites which are required.
You must have a Prometheus Server setup configured with Node Exporter as we are going to query Node Exporter metrics in Grafana.
Grafana should be able to access Prometheus server for 9090 port.
Install and Configure Grafana
Visit the official downloads page of Grafana and get the latest rpm download link.
After the installation, start and enable the Grafana server.
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Check the grafana service status. It should be active.
sudo systemctl status grafana-server
Now, the Grafana service is up and running, we can access it on the browser. It uses TCP port 3000 to show the Grafana UI. If you are not able to access it, please check if you have white listed your IP for port 3000 on Grafana server firewall or not.
The default credentials admin/admin as username and password to login. After the first login, you will be prompted to create the new password. Enter the new password and proceed.
Add Prometheus Source to Grafana
In this section of the blog, you will learn how to add Prometheus time series database (TSDB) as the data source to Grafana. Data source is the origin where our data is stored and Grafana can use it to query the required metrics.
Note: Please make sure that you can access the Prometheus endpoint from Grafana server.
On the Grafana dashboard homepage, press the “Settings” button, then the “Data Sources” link.
Select “Prometheus” as data source from the list and add the name, Prometheus endpoint details as shown below and save it.
Now, data source is set up and we can use it further for querying metrics in dashboards.
Create Dashboards from Prometheus Source
In this section, you learn how to create dashboards where you can visualize and monitor metrics. Dashboards allows you to visualize metrics over a period. You can also modify this time frame according to your requirements and understand the patterns. You can organize these dashboards in different folders categorically. In a dashboard, you can create different types of panels like Graph, Stat, Gauge, Table, Text, Heatmap, Dashboard List, etc.
Go to “+” icon and click on “Dashboard” under “Create” as shown below and click on add Panel.
Give the title to the panel and select the visualization type as Graph. You can select any visualization type depending upon your query and the required output.
Now under the Query section, select the Prometheus data source from the drop down and enter the Prometheus expression (query) under the metrics tab that must be graphed. In the settings, under the general tab, you can assign a name for the dashboard. Apply and Save the dashboard after preview. These expressions are the queries of Prometheus to fetch data from the TSDB (Time Series Database). Here we have used a query to show Memory utilization of the server. To learn more about how to write a query, click here.
Similarly, you can create more panels in a dashboard according to your requirement. To find all the saved dashboards, go to home page of Grafana and click drop down under the “Home” option.
Also, you can perform many operations to manage and organize your dashboards under different folders based on your needs. You can create new folders or you can move your dashboards under the existing folders.
Importing Predefined Grafana Dashboard Templates
In this section, you will learn how to import predefined templates to your Grafana server. Till now, we have seen how to create dashboards but Grafana provides us flexibility to import templates which are predefined by the Grafana community and you can use them for free. You can also create your own templates and share them in the community which can be used by others. These shared community dashboards can be found from Grafana Shared Templates. To import these templates to your Grafana server is very simple. You can use a dashboard ID or the JSON file as shown below.
Now from your Grafana server home page, click on the import option as shown below.
As you can see in the below screenshot, there are two supported import options. Either you can add the dashboard ID which you can get from Grafana community website or upload the JSON file or paste the JSON in the text box.
Then just add a dashboard name, select the data source as Prometheus, select any existing destination dashboard folder and click on import. Your new dashboard will be available now.
The purpose of this blog was to make you familiar with the basic setup of Grafana and integration with Prometheus. But Grafana offers us a lot of options and functionalities to play around like creating alerts, annotations, variables, versioning, and many more. So off course, you can explore more and be familiar with all other options.
If you want to learn more about Prometheus go to our website and check more courses on DevOps.
Saurabh Kumar Jain is a Subject Matter Expert working with CloudThat. He has experience in AWS, Microsoft Azure, and DevOps technologies. He is specialized in cloud security and architecture design. He also holds experience on various cloud and DevOps projects based on the cloud maturity model. He is an AWS Certified Security Speciality, AWS Certified Solutions Architect - Associate, Microsoft certified Azure Administrator and a certified Terraform Associate.