search
HomeJavajavaTutorialHow to use Prometheus+Grafana to monitor Springboot applications

1 Introduction

The more the project progresses, the more I feel that operation and maintenance monitoring is too important for any system that goes online.

Prometheus is an excellent open source monitoring, alarm and time series database combination system. In the most common Kubernetes container management system, it is usually paired with PrometheusMonitor.

2.1 Introduction to Springboot

Introduce Prometheus into dependencies as follows:

<dependency>
 <groupid>io.micrometer</groupid>
 <artifactid>micrometer-registry-prometheus</artifactid>
</dependency>

For Springboot, enable Actuator and open Corresponding Endpoint:

management.endpoints.web.exposure.include=*
# 或者
management.endpoints.web.exposure.include=prometheus

After starting Springboot, you can check whether the monitoring data can be obtained correctly through the following URL:

localhost :8080/actuator/prometheus

The data is obtained successfully, indicating that Springboot can provide monitoring data normally.

2.2 Using Docker

For convenience, use Docker to start Prometheus:

# 拉取docker镜像
docker pull prom/prometheus

Preparation Configuration file prometheus.yml:

scrape_configs:
# 可随意指定
- job_name: 'spring'
 # 多久采集一次数据
 scrape_interval: 15s
 # 采集时的超时时间
 scrape_timeout: 10s
 # 采集的路径
 metrics_path: '/actuator/prometheus'
 # 采集服务的地址,设置成Springboot应用所在服务器的具体地址
 static_configs:
 - targets: ['hostname:9000','hostname:8080']

Start the docker instance:

# The port is 9090, specify the configuration file
docker run -d -p 9090 :9090 -v ~/temp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

2.3 Testing and Viewing

After successful startup, you can open the web page to view it and display it graphically. The URL is http://localhost:9090/.

How to use Prometheus+Grafana to monitor Springboot applications

As shown in the picture above, after opening the web page, select a corresponding monitoring indicator and parameter and click Execute to view it.

3 Grafana

Grafana is an open source measurement analysis and visualization suite, a front-end tool developed purely in JavaScript. Display custom reports, display charts, etc. by accessing libraries (such as InfluxDB). Its UI is very flexible, rich in plug-ins and templates, and powerful. Generally used in monitoring time series data.

3.1 Docker installation and startup

# 拉取镜像
docker pull grafana/grafana
# 运行实例
docker run -d -p 3000:3000 grafana/grafana

After successful startup, visit http://localhost:3000 to check whether it is successful. The initial administrator account password is admin /admin.

3.2 Configure the data source

GrafanaTo display data, you need to configure the corresponding data source. In this article, configure the that was installed and enabled before. Prometheus data source, the specific configuration is shown in the figure below:

How to use Prometheus+Grafana to monitor Springboot applications

It should be noted that Access must select Browser mode , otherwise the data cannot be obtained normally. After the configuration is completed, click Save & Test.

3.3 Template application

After you can obtain the data, you can customize the data visualization display. But if you add one indicator at a time, it will be very troublesome. In fact, Grafana provides many excellent templates, which can be found on the web page https://grafana.com/grafana/dashboards.

This article uses the Spring Boot 2.1 Statistics template. The import method is as follows:

Click on the number--> Import - -> Enter the template link or ID --> Click Load.

How to use Prometheus+Grafana to monitor Springboot applications

After successful import, you can monitor the data, and the interface is really nice:

How to use Prometheus+Grafana to monitor Springboot applications

Example in this article The software version information is as follows:

springboot.version=2.2.5
micrometer-registry-prometheus=1.3.5
prometheus.version=2.16
grafana.version=6.7.0-beta1

The above is the detailed content of How to use Prometheus+Grafana to monitor Springboot applications. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)