prometheus监控SpringBoot应用
2024-09-24 06:29:30 阅读次数:248
prometheus,SpringBoot
1.依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.7.3</version>
</dependency>
2.配置
server:
port: 10200
servlet:
context-path: /
spring:
application:
name: lys-openstack
devtools:
remote:
restart:
enabled: true
thymeleaf:
cache: false
prefix: classpath:/templates
encoding: UTF-8
suffix: .html
mode: LEGACYHTML5
management:
endpoints:
web:
exposure:
include: "*"
metrics:
tags:
application: lys-openstack
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
info:
enabled: true
3.修改启动类
package com.lys;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(
@Value("${}") String applicationName) {
return (registry) -> registry.config().commonTags("application", applicationName);
}
}
4.验证
5.Prometheus配置
# 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:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
#通过配置file 获取target,这里以lys-web项目进行举例
- job_name: 'lys-other'
#metrics_path: /metrics
file_sd_configs:
- files:
- host.json
- job_name: 'container'
static_configs:
- targets: ['10.6.8.184:8080'] # 本地 cadvisor 访问地址
- job_name: 'rds'
metrics_path: /actuator/prometheus
static_configs:
- targets: ['10.6.9.35:10200'] # 本地 springboot 访问地址
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/liuyunshengsir/5998270,作者:liuyunshengsir,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:SpringBoot上传文件到后端服务器
下一篇:SpringBoot简介&IDEA在线创建一个SpringBoot项目