Introduction to Grafana, Prometheus, and Zabbix
This article discusses three observability tools, demonstrates their integration, how to collect the metrics, and how to show them in the dashboard.
Join the DZone community and get the full member experience.Join For Free
What Is Grafana?
Grafana is an open-source tool to visualize the metrics and logs from different data sources. It can query those metrics, send alerts, and can be actively used for monitoring and observability, making it a popular tool for gaining insights. The metrics can be stored in various DBs, and Grafana supports most of them, like Prometheus, Zabbix, Graphite, MySQL, PostgreSQL, Elasticsearch, etc. If the data sources are not available then customized plugins can be developed to integrate these data sources. Grafana is used widely these days to monitor and visualize the metrics for 100s or 1000s of servers, Kubernetes Platforms, Virtual Machines, Big Data Platforms, etc. The key feature of Grafana is its ability to share these metrics in visual forms by creating dashboards so that the teams can collaborate for data analysis and provide support in real-time.
Various platforms that are supported by Grafana today:
- Relational Databases
- Cloud Services like Google Cloud Monitoring, Amazon Cloud Watch, Azure Cloud
- Time Series Databases like InfluxDB for memory and CPU Usage graphs
- Other Data Sources like Elasticsearch and Graphite
What Is Prometheus?
It’s an open-source data source that is used for infrastructure monitoring and observability. It stores the time-series data, which is collected from various sources like applications developed in various programming languages, virtual machines, databases, servers, Kubernetes clusters, etc. To query these metrics, it uses a query language called PromQL that can be used to explore these metrics for various times and intervals and ensure insights into the health of the systems mentioned above. To create dashboards, send alerts, and ensure observability, tools like Grafana are used.
What Is Zabbix?
Zabbix is used for comprehensive monitoring which ensures the reliability and efficiency of the IT infrastructure like network, servers, and applications. It has three components: Zabbix Server, Zabbix Agent, and Frontend.
- Zabbix Server is used for gathering the data.
- The Zabbix agent collects and sends the data to the Zabbix Server.
- Frontend is a Web Interface for configuration.
Comparison Between Zabbix and Prometheus
Adding a Data Source in Grafana
A data source is the location from where the metrics are being sourced. These metrics are integrated into Grafana for visualization and other purposes.
You need to have an ‘administrator’ role in Grafana to make these changes.
You need to have connection details of the data source, like database name, login details, URL and port number of the database, and other relevant information.
The below steps can be used to add a custom source:
- First, navigate to the sidebar and open the context menu. Then click on Configurations and then Data Sources.
- To create a data source, add it first. Click on the Connections from the menu and create a data source.
- Now, select the type of data source where the metrics are being sourced from. If it’s a custom data source, then click on custom data source.
- Provide the connection details that are required and were collected in pre-requisites.
- Save and Test the connectivity and ensure there are no errors. Once the data source is saved, you can explore the metrics and also create the dashboards.
Demo on How To Integrate Grafana and Prometheus to Monitor the Metrics of a Server
- Operating System: Centos 7 Linux Virtual Machine
- Internet is available to access the packages
- Root Access to the VM
- Single Machine setup: Grafana, Prometheus, and Node Exporter are installed on a single VM
- Node Exporter
Disable Selinux and Firewall
systemctl stop firewalld
systemctl disable firewalld
yum.repo for Grafana
[root@vm-grafana ~]# yum install grafana
[root@vm-grafana ~]# vim /etc/sysconfig/grafana-server
Edit the Grafana configuration file to add the port and IP where Grafana is installed.
[root@vm-grafana ~]# vim /etc/grafana/grafana.ini
# The http port to use
http_port = 3000
# The public facing domain name used to access grafana from a browser
domain = 127.0.0.1
Restart Grafana Server Service and Check Logs
Log file location.
[root@vm-grafana ~]# tail -f /var/log/grafana/grafana.log
[root@vm-grafana ~]# systemctl restart grafana-server
[root@vm-grafana ~]# systemctl status grafana-server
Connect to the Web UI
Grafana will connect to Port 3000.
Install Prometheus and Node-Exporter
Download Package for Prometheus
yum install wget
Saving to: ‘prometheus-2.49.1.linux-amd64.tar.gz’
useradd --no-create-home --shell /bin/false prometheus
chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus
Extract the package.
[root@vm-grafana ~]# tar zxvf prometheus-2.49.1.linux-amd64.tar.gz
mv prometheus-2.49.1.linux-amd64 prometheuspackage
cp prometheuspackage/prometheus /usr/local/bin/
cp prometheuspackage/promtool /usr/local/bin/
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
cp -r prometheuspackage/consoles /etc/prometheus
cp -r prometheuspackage/console_libraries /etc/Prometheus
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries
chown prometheus:prometheus /etc/prometheus/prometheus.yml
Edit configuration file.
- job_name: 'prometheus_master'
- targets: ['localhost:9090']
Create a Linux Service file for Prometheus.
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
Start the service.
systemctl start prometheus
systemctl status prometheus
Access Prometheus Web UI.
Monitor Linux Server Using Prometheus and Integration With
Download the Setup
[root@vm-grafana ~]# tar zxvf node_exporter-1.7.0.linux-amd64.tar.gz
[root@vm-grafana ~]# ls -ld node_exporter-1.7.0.linux-amd64
drwxr-xr-x. 2 prometheus prometheus 56 Nov 13 00:03 node_exporter-1.7.0.linux-amd64
useradd -rs /bin/false nodeusr
mv node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/
Create a Service File for the Node Exporter
Reload the System Daemon and Start Node Exporter Service
systemctl restart node_exporter
systemctl enable node_exporter
View the metrics browsing node exporter URL.
node_exporter With Prometheus
Login to the Prometheus server and modify the prometheus.yml configuration file. Add the following configurations under the scrape config.
- job_name: 'node_exporter_centos'
- targets: ['TARGET_SERVER_IP:9100']
Restart Prometheus service.
systemctl restart prometheus
Login to Prometheus Server Web Interface, and Check Targets
Follow this link.
You can click the graph and query any server metrics and click execute to show output. It will show the console output.
Add Prometheus as DataSource in Grafana
Click on Add a new data source and add Prometheus as the data source by entering the Prometheus URL.
Import a pre-built dashboard from Grafana using this link and ID.
Dashboard ID: 10180
Click on Dashboard and go to the imported dashboard. You should now be able to see all the metrics of the server.
Users can explore more on setting up alerts, adding Role Based Access Control, importing metrics from a remote server, and Grafana Administration as the next steps.
Opinions expressed by DZone contributors are their own.