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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
  1. DZone
  2. Data Engineering
  3. Data
  4. Set Up and Integrate Prometheus With Grafana for Monitoring

Set Up and Integrate Prometheus With Grafana for Monitoring

In this tutorial, we'll learn how to set up and configure Prometheus and Grafana to enable application performance monitoring for REST applications.

Satish Sharma user avatar by
Satish Sharma
·
May. 24, 18 · Tutorial
Like (10)
Save
Tweet
Share
60.24K Views

Join the DZone community and get the full member experience.

Join For Free

As we know, Prometheus and Grafana can be used to monitor a vast range of applications. In this article, we will learn how to set up Prometheus and Grafana. We will also see how to integrate Prometheus as a data source in Grafana.

For collecting metrics, we shall be targeting the REST application we created in our previous article. This application has exposed a metrics endpoint at "http://localhost:9000/actuator/prometheus" using Spring Boot Actuator.

Note: The steps mentioned in this article are for Windows operating systems. For other environments, the steps may vary.

1. Set Up Prometheus

Download Prometheus distributions for your environment.

Extract the distribution in your selected directory in the file system.

In Prometheus, all configurations are done using configuration files, which are written in YAML format. Prometheus is distributed with a sample configuration file with the name prometheus.yml. You can use this file to configure applications to be monitored or you can create new files. I have created a new file named person-app.yml with the below content:

#Global configurations
global:
  scrape_interval:     5s # Set the scrape interval to every 5 seconds.
  evaluation_interval: 5s # Evaluate rules every 5 seconds.

scrape_configs:
  - job_name: 'person-app'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:9000']


Start the Prometheus server by using the command perometheus.exe --config.file=YAML_FILE_PATH. Image title

Test the server by browsing to the URL http://localhost:9090/. If you are able to see the page below, then you have the Prometheus server running and scraping the metrics for you, which is based on the configuration you made using person-app.yml while starting the server.prometheus home page

2. Set Up Grafana

Download the Grafana distribution for your environment.

Extract the distribution to your file system.

In Grafana, all the configurations are made using ".ini" files, which are placed in the "conf" directory. Grafana is distributed with "defaults.ini" and "sample.ini." You can change/override the configurations (port, security, etc) using this file. For the sake of simplicity, let us proceed with the default settings, which will configure "admin/admin" as the username and password.

Caution: Do not rename the existing or new configuration file as "defaults.ini" unless you are very sure of what properties you are changing and what effects it may have on the server.

The executable to start the server is placed in the "bin" directory of the Grafana distribution. Start the server by executing grafana-server.exe from the bin directory of the distribution.Image title

Log in to Grafana by browsing to http://localhost:3000. The username and password are "admin/admin" (remember that we used the defaults). You can change this anytime using the .ini file we discussed in an earlier step.Image title

3. Add Prometheus as a Data Source in Grafana

Grafana allows you to query, visualize, and alert your metrics from about 30+ open source and commercial data sources. In the next steps, we shall be describing how to add Prometheus as a data source in Grafana.

  • Log into Grafana with the username and password configured (the default is admin/admin).
  • Click the gear icon in the left sidebar and from the menu select "Data Sources." This will list all the configured data sources (if you have configured any).
  • Click on "Add Data Source." This will open a page to add a data source.
    • Give a suitable name to this new data source, as this will be used while creating visualizations. I am using "prometheus-local."
    • Select Prometheus in the "type" drop down.
    • The URL shall be "http://localhost:9090" as we have Prometheus running on local host on port 9090.
    • Fill other details if you have any security or HTTP related settings.
    • Click "Save & Test."
    • If Grafana is able to make connections to Prometheus instance with the details provided, then you will get a message saying "Data source is working." If you get any errors, review your values.Image title

In this article, we have seen how to set up and integrate Prometheus and Grafana. In the next article, we shall be creating a visualization in Grafana that will display the hit count of the API exposed in our REST application.

You can get the person-app.yml file and the application we used for the Prometheus setup from this GitHub repository.

Grafana Integration application Data (computing)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 2023 Software Testing Trends: A Look Ahead at the Industry's Future
  • How to Configure AWS Glue Job Using Python-Based AWS CDK
  • Best Practices for Writing Clean and Maintainable Code
  • Handling Virtual Threads

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: