Prometheus for Spring Boot

前面两篇文章已经介绍如何搭建Prometheus和Grafana,本文介绍如何快速监控Spring Boot进程

Prometheus监控系列

快速接入

  • 引入Jar包(pom.xml
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
  • 配置metrics(application.properties
#Metrics related configurations
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
prometheus监控指标
  • 修改Prometheus配置(prometheus.yml
#Global configurations
global:
  scrape_interval:     5s # Set the scrape interval to every 5 seconds.
  evaluation_interval: 5s # Evaluate rules every 5 seconds.
scrape_configs:
  - job_name: 'spring-boot'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8080']
  • 重启Prometheus
./perometheus --config.file=prometheus.yml

配置Grafana

  • 配置指标jvm_memory_committed_bytes

    image.png

  • 再配置更多指标

    • jvm_threads_states_threads
    • jvm_memory_used_bytes
    • process_cpu_usage
    • rate(http_server_requests_seconds_sum[5m])
    • jvm_gc_pause_seconds_count

参考

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。