How to add Prometheus Data Source in Grafana

In this article we are going to cover How to add Prometheus Data Source in Grafana

What is Grafana?

How to add Prometheus Data Source in Grafana 1

Grafana is an open source tool for performing data analytics, retrieving metrics that make sense of large amounts of data, and monitoring our apps using nice configurable dashboards.

Grafana integrates with a wide range of data sources, including Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL, and others. When connected to supported data sources, it provides web-based charts, graphs, and alerts.

What is Prometheus?

How to add Prometheus Data Source in Grafana 2

Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability in modern, dynamic environments. Developed by the Cloud Native Computing Foundation, Prometheus excels at collecting and storing time-series data, allowing users to gain valuable insights into the performance and health of their applications and infrastructure.

With its powerful query language and support for multi-dimensional data, Prometheus has become a popular choice for monitoring systems within cloud-native ecosystems.

Advantages of Grafana with Prometheus as the Data Source

  • A user can visualize the time series directly in Prometheus Web UI, similar to Grafana.
  • Prometheus provides a functional query language called ‘PromQL’ that lets users select and aggregate time-series data in real-time.
  • Prometheus can discover targets dynamically and automatically scrap new targets on demand. It offers a variety of service discovery options for scrape targets, including K8s.

What is prometheus.yml file?

The prometheus.yml file is the configuration file for Prometheus, specifying parameters like target endpoints for data scraping, alerting rules, and storage configurations. This YAML file is crucial for tailoring Prometheus to monitor specific services and defining how data should be collected and processed for effective monitoring and alerting.

Default prometheus.yml file include:
# A scrape configuration scraping a Node Exporter and the Prometheus server
# itself.
scrape_configs:
  # Scrape Prometheus itself every 5 seconds.
  - job_name: 'prometheus'
    scrape_interval: 5s
    target_groups:
      - targets: ['13.233.178.170:9090']

Certainly, let’s break down the provided Prometheus configuration snippet:

Scrape Configuration:

   scrape_configs:
  • This section denotes the start of scrape configurations, defining how Prometheus collects data from various targets.

Job Definition:

 - job_name: 'prometheus'
   scrape_interval: 5s
  • job_name specifies the label for this job as ‘prometheus’. Jobs help organize and manage related targets.
  • scrape_interval sets the frequency at which Prometheus collects data for this job, which is every 5 seconds.

Target Group Definition:

 target_groups:
   - targets: ['13.233.178.170:9090']
  • target_groups is where you define the targets (endpoints) for data collection.
  • Here, there is one target specified: ‘13.233.178.170:9090’. This means Prometheus will collect metrics from the Prometheus server running at IP address 13.233.178.170 on port 9090.

In summary, this configuration instructs Prometheus to:

  • Group the targets under the label ‘prometheus’.
  • Collect metrics from the specified target (Prometheus server at IP address 13.233.178.170, port 9090).
  • Perform this data collection every 5 seconds.

Prerequisites

To follow this tutorial, you will need:

How to add Prometheus Data Source in Grafana

Step#1:Adding Prometheus as a Grafana Data Source

In this section, we will configure Grafana to access your Prometheus server as a data source. Each Prometheus server is a separate data source, and if you are configuring more than one Prometheus server, repeat this section for each.

Go to the Grafana main view at http://your_server_ip:3000/, and log into your admin account.

Click the Grafana icon in the top left corner to show the main menu. Select Data Sources to navigate to the data source list page. Click Add New in the top navigation bar. You should see the following:

How to add Prometheus Data Source in Grafana 3
How to add Prometheus Data Source in Grafana 4
How to add Prometheus Data Source in Grafana 5

Use the following values to create a new data source:

  • Name: Prometheus
  • Type: Prometheus
  • URL: http://<your_server_ip>:9090, (default port is 9090)
  • Access: proxy
  • Basic Auth: Enabled or Disabled, as your Prometheus server is configured.

Click Add to add your data source, and then click Test Connection to verify everything is working properly.

How to add Prometheus Data Source in Grafana 6

Step#2:Click on Explore view

Below Page will be loaded:-

How to add Prometheus Data Source in Grafana 7

Step#3:Visualize Prometheus Data in Grafana

  1. Select Metric as process_virtual_memory_bytes and also you can select any metric you want such as process_cpu_seconds_total
  2. Then, Select Label Filters as Instance
  3. Select value as localhost:9090
  4. Click on Run Query
  5. Click on Bars
How to add Prometheus Data Source in Grafana 8
How to add Prometheus Data Source in Grafana 9

What is process_virtual_memory_bytes and process_cpu_seconds_total metrics in Prometheus?

  1. process_virtual_memory_bytes:
    • Definition: Represents the total virtual memory usage of a process.
    • Example: process_virtual_memory_bytes{job=”web-server”, instance=”example.com:9090″}
    • Use Case: Monitoring the virtual memory consumption of a specific process, helping to assess its resource utilization.
  2. process_cpu_seconds_total:
    • Definition: Indicates the total CPU time consumed by a process, measured in seconds.
    • Example: process_cpu_seconds_total{job=”web-server”, instance=”example.com:9090″}
    • Use Case: Tracking the cumulative CPU time expended by a process, providing insights into its computational workload.

These metrics are crucial for understanding the resource utilization and performance characteristics of processes in a system. The process_virtual_memory_bytes metric gives insights into the memory usage, while process_cpu_seconds_total quantifies the CPU time consumption, both essential for effective monitoring and optimization.

Conclusion:

In conclusion, this guide empowers users to seamlessly integrate Prometheus metrics into Grafana, fostering the creation of enhanced monitoring dashboards. By harnessing the combined power of Prometheus and Grafana, users gain a robust solution for real-time insights and effective visualization, elevating their monitoring capabilities and overall system observability.

Related Articles:

How to Install Prometheus on Ubuntu 22.04 LTS

Secure Grafana with Nginx, Reverse Proxy and Certbot

Reference:

Grafana Installation official page

Akash Bhujbal

Hey, I am Akash Bhujbal, I am an aspiring DevOps and Cloud enthusiast who is eager to embark on a journey into the world of DevOps and Cloud. With a strong passion for technology and a keen interest in DevOps and Cloud based solutions, I am driven to learn and contribute to the ever-evolving field of DevOps and Cloud.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap