經過以前的文章咱們使用Prometheus監控了應用服務器node_exporter,數據庫mysqld_exporter,今天咱們來監控一下你的應用。(本文以SpringBoot 2.1.9.RELEASE 做爲監控目標)node
使用Prometheus監控SpringBoot應用只須要在pom文件添加以下兩個依賴:mysql
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
複製代碼
修改application.properties或者application.yml文件,對外暴露監控端點web
spring.application.name = blog
management.endpoints.web.exposure.include = prometheus
management.metrics.tags.application = ${spring.application.name}
複製代碼
訪問http://localhost:50378/actuator/
查看開放端點 spring
訪問http://localhost:50378/actuator/prometheus
查看Metrics sql
以前的文章中都是監控一個實例,此次我們把端口設置成隨機,啓動兩個實例,等下看看監控效果。數據庫
修改prometheus.yml,增長監控任務bash
- job_name: 'SpringBoot'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['10.1.61.10:50378','10.1.61.10:50822']
複製代碼
重啓Prometheus,查看監控狀態。 服務器
直接從grafana官網尋找JVM監控DashBoard,而後導入到Grafana中(在環境搭建篇中已經講述了操做過程,這裏就再也不贅述)。 微信
查看效果app
咱們關掉其中一個SpringBoot實例,等2分鐘,而後郵箱會收到這樣一封告警郵件
怎麼實現的呢?我們下期有緣再見!
相關文章
獲取更多內容請關注公衆號:JAVA日知錄