prometheus监控SpringBoot应用

prometheus监控SpringBoot应用,第1张

prometheus监控SpringBoot应用 1.依赖

			org.springframework.boot
			spring-boot-starter-actuator
		
		
			io.micrometer
			micrometer-registry-prometheus
			1.7.3
		
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 configurer(
			@Value("${spring.application.name}") String applicationName) {
		return (registry) -> registry.config().commonTags("application", applicationName);
	}
}

4.验证

http://localhost:10200/actuator/prometheus

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=` 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://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.endpoints.enabling

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5433945.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存