Monitoring Framework - prometheus

1. About Prometheus

Prometheus is an open source tool to monitor the application based on the metrics. I believe that many projects are using it to monitor For detailed information, you can view the official website: https://prometheus.io/docs/introduction/overview/ .

2. about Grafana

Grafana is an open source monitoring tool, as shown in FIG.

Can be seen from the figure, using Grafana on very large monitors, it provides many visual icons.

Official website address: https://grafana.com/

3.SpringBoot use Prometheus

3.1 rely on content

Prometheus use in SpringBoot in fact, very simple, no need to configure a lot of things, adding depend in pom file as complete as follows.

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.dalaoyang</groupId> <artifactId>springboot2_prometheus</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot2_prometheus</name> <description>springboot2_prometheus</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.1.3</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

3.2 configuration files

Adding configure profile, here only some simple configuration, management.metrics.tags.application properties are herein provided with Grafana the Dashboard, as follows:

spring.application.name=springboot_prometheus
management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}

3.3 Settings application

Modifying the boot class, as follows.

@SpringBootApplication
public class Springboot2PrometheusApplication {

    public static void main(String[] args) { SpringApplication.run(Springboot2PrometheusApplication.class, args); } @Bean MeterRegistryCustomizer<MeterRegistry> configurer( @Value("${spring.application.name}") String applicationName) { return (registry) -> registry.config().commonTags("application", applicationName); } }

SpringBoot project here on the configuration is complete, start the project, visit HTTP: // localhost: 8080 / Actuator / Prometheus , as shown, you can see some of the metrics.

4.Prometheus Configuration

4.1 Configuration Application

In prometheus configured to monitor our SpringBoot application, complete configuration is shown below.

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting:  alertmanagers:  - static_configs:  - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs:  - job_name: 'prometheus'  static_configs:  - targets: ['127.0.0.1:9090'] ###以下内容为SpringBoot应用配置  - job_name: 'springboot_prometheus'  scrape_interval: 5s  metrics_path: '/actuator/prometheus'  static_configs:  - targets: ['127.0.0.1:8080']

4.2 Start Prometheus

Start Prometheus, browser access, view Prometheus page, as shown.

Click the position as shown, you can view the application Prometheus surveillance.

UP page list is an example of survival, as shown in FIG.

You can also view a lot of the index, as shown below.

5.Grafana Configuration

启动Grafana,配置Prometheus数据源,这里以ID是4701的Doshboard为例(地址:https://grafana.com/dashboards/4701)如图。

在Grafana内点击如图所示import按钮

在如图所示位置填写4701,然后点击load。

接下来导入Doshboard。

导入后就可以看到我们的SpringBoot项目对应的指标图表了,如图。

6.源码

源码地址:https://gitee.com/dalaoyang/springboot_learn/tree/master/springboot2_prometheus

Guess you like

Origin www.cnblogs.com/JiangWJ/p/10949249.html