DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Enterprise AI Trend Report: Gain insights on ethical AI, MLOps, generative AI, large language models, and much more.

2024 Cloud survey: Share your insights on microservices, containers, K8s, CI/CD, and DevOps (+ enter a $750 raffle!) for our Trend Reports.

PostgreSQL: Learn about the open-source RDBMS' advanced capabilities, core components, common commands and functions, and general DBA tasks.

AI Automation Essentials. Check out the latest Refcard on all things AI automation, including model training, data security, and more.

Related

  • How Grafana 10 Makes Observability Easier for Developers
  • Integrating Blackbox Exporter in Datadog, Prometheus, and Grafana for Custom Metrics
  • Dynatrace Perform: Day Two
  • How Observability Is Redefining Developer Roles

Trending

  • Deploying to Heroku With GitLab CI/CD
  • C4 PlantUML: Effortless Software Documentation
  • AWS Fargate: Deploy and Run Web API (.NET Core)
  • The Impact of Biometric Authentication on User Privacy and the Role of Blockchain in Preserving Secure Data
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Monitoring and Observability
  4. Introduction to Grafana, Prometheus, and Zabbix

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.

By 
Babul Bansal user avatar
Babul Bansal
·
Feb. 06, 24 · Tutorial
Like (1)
Save
Tweet
Share
2.2K Views

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:

  1. Relational Databases
  2. Cloud Services like Google Cloud Monitoring, Amazon Cloud Watch, Azure Cloud
  3. Time Series Databases like InfluxDB for memory and CPU Usage graphs
  4. 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. 

  1. Zabbix Server is used for gathering the data.
  2. The Zabbix agent collects and sends the data to the Zabbix Server.
  3. Frontend is a Web Interface for configuration.

Comparison Between Zabbix and Prometheus

Features/Aspects

Prometheus

Zabbix

Primary Use Case

Collection of metrics of the servers and services.

Comprehensive monitoring of network, servers, and applications.

Data Collection

Collection of metrics in numbers and can be viewed via HTTP Endpoints.

Agents (Zabbix Agent) for collecting performance data, SNMP, IPMI, and JMX support. Supports agentless monitoring for certain scenarios.

Logging

Cannot collect or analyze logs.

Centralized logging analysis is not possible with Zabbix. You can monitor log files, but no analysis possibilities are available.

Data Visualization

Data visualization is possible through numbers and graphs.

Graphical representation of monitored data through charts, graphs, maps, and dashboards.

Application Metrics

Application metrics can be collected if Prometheus is integrated with the web application.

No Application-related metrics/dashboards/Alerts are available at this moment.

Service Metrics

Prometheus can collect metrics from web applications.

Zabbix can monitor services like haproxy, databases MySQL, PostgreSQL, HTTP services, etc., and require configurations/integrations.

Custom Metrics

Custom metrics can be collected through the exporters.

The Anomaly Detection feature is available from version 6.0.

Alerting System

Alerting is not possible via Prometheus.

Robust alerting system with customizable triggers, actions, escalations, and notification channels.

Alerts can trigger E-mail Notifications, Slack, Pagerduty, Jira, etc.

Service Availability

Not possible.

Zabbix has a built-in feature to generate Service Availability Reports. Planned and unplanned outage windows require manual input to the script, which generates a service availability report.

Retention Policy

Prometheus can retain the metrics for 1 day to multiple days.

Zabbix persists all the data in its own database.

Security Features

Prometheus and most exporters support TLS. Including authentication of clients via TLS client certificates. Details on configuring Prometheus are here. The Go projects share the same TLS library based on the Go crypto/tls library.

Robust user roles and permissions, granular control over user access, and secure communication between components.

Kubernetes Compatibility

Prometheus can be fully integrated with Kubernetes clusters. It takes full advantage of exporters to collect the metrics and show them on the UI.

Compatibility

Zabbix is compatible with K8s and can be used to monitor various aspects of the K8s environment.


No Logging using K8s Log Forwarder

Application logs cannot be forwarded to the Zabbix server.


Container Monitoring with Zabbix 

The Zabbix Server can be configured to collect data from Zabbix Agents deployed on K8s nodes and applications.


Scalability

Zabbix also scales horizontally, making it suitable for large K8s deployments with a growing number of nodes and applications.



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. 

Prerequisites

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:

  1. First, navigate to the sidebar and open the context menu. Then click on Configurations and then Data Sources.
  2. To create a data source, add it first. Click on the Connections from the menu and create a data source.
  3. 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.
  4. Provide the connection details that are required and were collected in pre-requisites.
  5. 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

Assumptions

  1. Operating System: Centos 7 Linux Virtual Machine
  2. Internet is available to access the packages
  3. Root Access to the VM
  4. Single Machine setup: Grafana, Prometheus, and Node Exporter are installed on a single VM
  5. Node Exporter

Install Grafana

Disable Selinux and Firewall

Plain Text
 
systemctl stop firewalld
systemctl disable firewalld


Add yum.repo for Grafana

Plain Text
 
 [grafana]
 name=grafana
 baseurl=https://packages.grafana.com/oss/rpm
 repo_gpgcheck=1
 enabled=1
 gpgcheck=1
 gpgkey=https://packages.grafana.com/gpg.key
 sslverify=1
 sslcacert=/etc/pki/tls/certs/ca-bundle.crt
Plain Text
 
[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

Uncomment 
# 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.

Grafana Web UI

Image 1: Grafana Web UI

Install Prometheus and Node-Exporter

Download Package for Prometheus

Location.

Plain Text
 
yum install wget
wget https://github.com/prometheus/prometheus/releases/download/v2.49.1/prometheus-2.49.1.linux-amd64.tar.gz
Saving to: ‘prometheus-2.49.1.linux-amd64.tar.gz’ 

Installation

useradd --no-create-home --shell /bin/false prometheus
mkdir /etc/Prometheus
mkdir /var/lib/Prometheus
chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus 


Extract the package.

Plain Text
 
[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.

Plain Text
 
global:
  scrape_interval: 10s 
scrape_configs:
  - job_name: 'prometheus_master'
	scrape_interval: 5s
	static_configs:
  	- targets: ['localhost:9090']


Create a Linux Service file for Prometheus.

Plain Text
 
vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
 
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
 
[Install]
WantedBy=multi-user.target


Start the service.

Plain Text
 
systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus


Access Prometheus Web UI.

Prometheus Web UI

Image 2: Prometheus Web UI

Prometheus Web UI

Image 3: Prometheus Web UI

Monitor Linux Server Using Prometheus and Integration With node_exporter


Download the Setup

Plain Text
 
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
[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


Setup Instructions

Plain Text
 
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

Plain Text
 
vim /etc/systemd/system/node_exporter.service
 
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=nodeusr
Group=nodeusr
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target


Reload the System Daemon and Start Node Exporter Service

Plain Text
 
systemctl daemon-reload
systemctl restart node_exporter
systemctl enable node_exporter


View the metrics browsing node exporter URL.

node_exporter Web UI

Image 4: node_exporter Web UI

Integrate node_exporter With Prometheus

Login to the Prometheus server and modify the prometheus.yml configuration file. Add the following configurations under the scrape config.

Plain Text
 
vim /etc/prometheus/prometheus.yml
 - job_name: 'node_exporter_centos'
	scrape_interval: 5s
	static_configs:
  	- targets: ['TARGET_SERVER_IP:9100']


Restart Prometheus service.

Plain Text
 
systemctl restart prometheus


Login to Prometheus Server Web Interface, and Check Targets

Follow this link.

node_exporter in Prometheus

Image 5: node_exporter in Prometheus

node_exporter in Prometheus

Image 6: node_exporter in Prometheus

You can click the graph and query any server metrics and click execute to show output. It will show the console output.

Image 7: Metrics from the VM

Image 7: Metrics from the VM

Building Graph from the Query Metrics

Image 8: Building Graph from the Query Metrics

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.

Add a new data source

Image 9: Add a new data source

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.

Grafana Dashboard

Image 10: Grafana Dashboard

Next Steps

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.

Big data Grafana Observability

Opinions expressed by DZone contributors are their own.

Related

  • How Grafana 10 Makes Observability Easier for Developers
  • Integrating Blackbox Exporter in Datadog, Prometheus, and Grafana for Custom Metrics
  • Dynatrace Perform: Day Two
  • How Observability Is Redefining Developer Roles

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: