Spring Boot監控(中)

步驟 安裝Prometheus/Grafana 設定Prometheus設定向我們spring boot application位置 # 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_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'My-Spring-Boot-Application' # Override the global default and scrape targets from this job every 5 seconds....

2021-10-03 October Sunday · 1 分鐘 · Tony

Spring Boot監控(上)

前言 常在河邊走那裡不失鞋,當一個後端工程師,常常會遇到上線Application server突然無法壞掉的問題,因此我們需要一個監控的Server來輔助我們上線的Application,本篇將使用Prometheus監控server當作範例來做為展示 步驟 Spring boot 安裝Prometheus Client 在pom.xml上新增兩個dependency spring-boot-starter-actuator: spring boot內建的監控library micrometer-registry-prometheus: 在spring boot上提供prometheus metrics格式 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> Spring boot 調整設定檔 在applcation.yml 新增下列設定 management: endpoint: health: show-details: always prometheus: enabled: true endpoints: web: exposure: include: prometheus,health metrics: tags: application: ${spring.application.name} health: diskspace: enabled: true defaults: enabled: false 設定好,啟動spring boot即可在http://:/actuator/prometheus看到metrics 參考連結 Spring boot Spring boot Actuator Micrometer Registry Prometheus

2021-09-22 September Wednesday · 1 分鐘 · Tony