By brief introduction

Logical relationship

Results demonstrate

Quick start

1. Spring Boot application exposed monitoring indicators [version 1.5.7.release]

First, add the following dependencies:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_spring_boot</artifactId> The < version > 0.0.26 < / version > < / dependency >Copy the code

Then add the following annotation to the startup class application.java:

@SpringBootApplication @EnablePrometheusEndpoint @EnableSpringBootMetricsCollector public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}Copy the code

Finally, configure the default login account and password in application.yml:

security:
  user:
    name: user
    password: pwdCopy the code

Hint: it is not recommended configuration management. Security. Enabled: false

After starting the application, you will see the following list of Mappings

Mappings

Using the account password to http://localhost:8080/application/prometheus, you can see Prometheus index data format

The index data

2. Prometheus collects Spring Boot indicator data

First, get Prometheus’s Docker image:

$ docker pull prom/prometheusCopy the code

Then, write the configuration file prometheus.yml:

global: scrape_interval: 10s scrape_timeout: 10s evaluation_interval: 10m scrape_configs: - job_name: spring-boot scrape_interval: 5s scrape_timeout: 5s metrics_path: /application/prometheus scheme: http basic_auth: Username: user password: PWD Static_configs: -targets: -127.0.0.1:8080 # Enter the IP address + port number of the Spring Boot applicationCopy the code

Next, start Prometheus:

$ docker run -d \
--name prometheus \
-p 9090:9090 \
-m 500M \
-v "$(pwd)/prometheus.yml":/prometheus.yml \
-v "$(pwd)/data":/data \
prom/prometheus \
-config.file=/prometheus.yml \
-log.level=infoCopy the code

Finally, visit http://localhost:9090/targets, check the Spring Boot collection status is normal.

Acquisition state

3. Visualized monitoring data of Grafana

First, get the Docker image of Grafana:

$ docker pull grafana/grafanaCopy the code

Then, launch Grafana:

$ docker run --name grafana -d -p 3000:3000 grafana/grafanaCopy the code

Next, visit http://localhost:3000/ to configure the Prometheus data source:

Grafana Login account admin Password admin

Configure the DataSource

Finally, configure the visual monitoring panel of a single indicator:

Choose the Graph

The editor

Configure indicators to be monitored

Prompt, here can’t fill in any, can only fill the existing index point, specific can see on the front page of Prometheus, i.e. http://localhost:9090/graph

indicators

After configuring more indicators, the following effects can be achieved:

Grafana monitor interface

Reference documentation

  • Official documentation for Prometheus
  • Grafana Docker installation
  • Spring Boot official documentation

© copyright belongs to the author, reprint or content cooperation please contact the author

Original link:

This article is published by OpenWrite!