選用方式
?? Prometheus+Grafans的方式進(jìn)行監(jiān)控憋肖,Prometheus作為一個數(shù)據(jù)源進(jìn)行數(shù)據(jù)采集,而Grafans作為一個圖形化界面增加性能指標(biāo)癌蓖、通知等瞬哼。為什么記錄
??在現(xiàn)有的微服務(wù)架構(gòu)下實現(xiàn)服務(wù)性能指標(biāo)監(jiān)控,服務(wù)注冊中心使用eureka租副,springCloud版本為Edgware.SR3,springBoot版本是1.5.12.RELEASE坐慰。由于版本停留在1.5.X,spring官方在2.0 開始對actuator做了更多的集成工作,Prometheus 官方文檔上只提供了對consul的支持用僧、-
開始集成
- eureka增加依賴
<dependency> <groupId>at.twinformatics</groupId> <artifactId>eureka-consul-adapter</artifactId> <version>0.0.1</version> </dependency>
eureka-consul-adapter的版本需要注意:
| 版本 | Spring Boot | Spring Cloud | | --- | :-: | :-: | | 1.1.x | 2.1.x | Greenwich | | 1.0.x | 2.0.x | Finchley | | 0.x | 1.5.x | Edgware |
-
Client的修改
- 增加依賴
<!--使用 Micrometer 的通用 API 來收集性能指標(biāo)--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.1.1</version> </dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-spring-legacy</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
```
* 修改配置``` management: metrics: distribution: percentiles-histogram: true # 監(jiān)控 security: false #開發(fā)環(huán)境開啟结胀,生產(chǎn)環(huán)境需要關(guān)閉 ``` 到這里代碼代碼上的集成結(jié)束,啟動eureka和client责循。
-
啟動Prometheus
?? 下載對于的Prometheus版本糟港,mac需要狹隘darwin版本。解壓后修改prometheus.yml文件增加springCloud的監(jiān)控節(jié)點院仿。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'] //prometheus的web地址 - job_name: 'SPRING_CLOUD' //名稱 scheme: http //請求協(xié)議 metrics_path: '/prometheus' //路徑 actuator1.0的路徑是/prometheus秸抚,2.0的路徑為/actuator/prometheus。 consul_sd_configs: #consul 地址 - server: '127.0.0.1:8888' //eureka的地址 scheme: http services: [GIFTCARD] //要監(jiān)聽的服務(wù)名稱歹垫,必須和eureka web頁面上展示的一致 ```
?? 在解壓的目錄下剥汤,啟動prometheus,啟動完成后打開 localhost:9090,展開 status-Targets標(biāo)簽排惨,可以看到新增的監(jiān)控源吭敢。
   到這里Prometheus 也配置結(jié)束。
- 配置Grafana
?? 下載解壓后啟動暮芭,mac下可以使用brew安裝鹿驼,brew server start grafana啟動服務(wù),默認(rèn)的端口是3000辕宏,默認(rèn)用戶名與密碼都是admin畜晰,進(jìn)入后修改密碼。
?? 在dashboards下載需要展示的模板瑞筐,選擇+舷蟀、選擇import,導(dǎo)入json選擇Prometheus數(shù)據(jù)源。
image.png
參考鏈接: