目標(biāo)要求
1、需要展現(xiàn)的儀表盤:
SpringBoot或JVM儀表盤
Centos物理機(jī)服務(wù)器(實(shí)際為物理分割的虛擬服務(wù)器)儀表盤
2、展現(xiàn)要求:
探索Prometheus + Grafana搭建起來的展示效果,盡可能展示能展示的部分。
一、下載軟件包
- 監(jiān)控系統(tǒng)核心:prometheus-2.45.0.linux-amd64.tar
下載地址:https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz - 測試用節(jié)點(diǎn)導(dǎo)出器:node_exporter-1.6.0.linux-amd64.tar
下載地址:https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz - Grafana儀表盤:
下載地址:
https://dl.grafana.com/enterprise/release/grafana-enterprise-10.4.1.linux-amd64.tar.gz
二、安裝及編寫啟動(dòng)腳本
-
新建工作目錄prometheus,將下載的軟件包移動(dòng)到目錄下。
-
使用“tar -zxvf 軟件包包名”命令逐步接下軟件包。
如: tar -zxvf prometheus-2.45.0.linux-amd64.tar.gz -
在每個(gè)解壓后的軟件工作目錄,新建start.sh腳本,按下方表格填入啟動(dòng)命令。保存后,賦予腳本執(zhí)行權(quán)限“chmod +x start.sh”。
關(guān)閉方式 | 啟動(dòng)腳本 | |
---|---|---|
prometheus | kill -9 | nohup ./prometheus --web.enable-lifecycle > log.log 2>&1 & |
grafana | 同上 | nohup ./bin/grafana-server>>./log.log & |
node | 同上 | nohup ./node_exporter --web.listen-address=:9101 > node_log.log 2>&1 & |
三、啟動(dòng)測試
分別執(zhí)行目錄下的啟動(dòng)腳本:start.sh
- promethesu的UI默認(rèn)訪問地址:ip:9090,正常訪問效果圖如下:
- grafana默認(rèn)訪問地址:ip:3000,正常訪問效果圖如下:
初始賬戶密碼:admin/admin
初次安裝需要修改密碼,按照提示修改即可。登錄后正常訪問效果圖如下:
四、JAVA應(yīng)用添加Prometheus支持
JAVA版本:JDK17,Springboot版本:3.1.2
- 配置pom文件:
<!-- prometheus 導(dǎo)出器配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.11.1</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.11.1</version>
</dependency>
- 配置application.yml文件
# prometheus 配置
management:
metrics:
# 下面選項(xiàng)建議打開,以監(jiān)控 http 請(qǐng)求的 P99/P95 等,具體的時(shí)間分布可以根據(jù)實(shí)際情況設(shè)置
distribution:
sla:
http:
server:
requests: 1ms,5ms,10ms,50ms,100ms,200ms,500ms,1s,5s
tags:
application: ${spring.application.name}
endpoints:
prometheus:
enabled: true
web:
base-path: /monitor
exposure:
include: "prometheus"
五、Prometheus配置文件
- 修改Prometheus.yml配置文件如下圖:
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'.
# 添加應(yīng)用節(jié)點(diǎn)
- job_name: 'application'
metrics_path: '/monitor/prometheus'
scrape_interval: 15s
file_sd_configs:
- files: ['./exporter_config/application_target.json']
# 添加硬件節(jié)點(diǎn)
- job_name: 'node'
scrape_interval: 15s
file_sd_configs:
- files: ['./exporter_config/node.json']
static_configs:
- targets: ["localhost:9090"]
- 在prometheus創(chuàng)建目錄“exporter_config”
- 在exporter_config分別創(chuàng)建應(yīng)用配置文件"application_target.json ",節(jié)點(diǎn)配置文件“node.json”。如下圖
- 填寫文件內(nèi)容如下:
10.0.0.1:100x代表節(jié)點(diǎn)、jar包所在的機(jī)器ip以及端口號(hào)
application_target.json
[
{
"targets": [
"10.0.0.1:1001"
],
"labels": {
"instance": "10.0.0.1:1001",
"service": "jar名",
"ip": "10.0.0.1",
"nodeType": "application"
}
}
]
node.json
[
{
"targets":[
"10.0.0.1:1001"
],
"labels":{
"instance":"模擬硬件節(jié)點(diǎn)",
"job":"模擬硬件節(jié)點(diǎn)job",
"ip": "10.0.0.1",
"nodeType":"device"
}
}
]
- 使用postman調(diào)用熱重啟接口,重啟prometheus,如下圖,10.0.0.1:9090代表prometheus安裝IP端口。返回200則代表已發(fā)送重啟命令。
- 訪問Prometheus,地址:ip:9090:,如下圖:
- 第六步正常則代表prometheus監(jiān)控系統(tǒng),已將JAVA應(yīng)用程序?qū)С銎?、node節(jié)點(diǎn)導(dǎo)出器納入監(jiān)控。其它情況則代表未納入監(jiān)控,需要檢查使得納入Prometheus監(jiān)控再往下推進(jìn)。
六、Grafana配置中文與組件兼容
- 修改defaults.ini文件,文件處于./conf目錄下,修改前建議備份。
- 當(dāng)前版本某些組件默認(rèn)不啟用,導(dǎo)致一些開源的儀表盤顯示為空。故需要配置啟用
- 漢化。
七、Grafana連接Prometheus
- 添加新數(shù)據(jù)源
- 配置
- 成功如圖
八、在Grafana配置儀表盤(Dashboard)
1、導(dǎo)入常見的Dashboard
任意Dashboard,無需數(shù)據(jù)源可導(dǎo)入,但是展示的內(nèi)容是默認(rèn)值。
同類型的多個(gè)監(jiān)控目標(biāo),例如node監(jiān)控,可以在適配的Dashboard切換觀看。
- 選擇導(dǎo)入
- 到官方查看官方提供的儀表盤
- 選擇一個(gè)需要的儀表盤
- 下載儀表盤的json配置
- 打開下載的json文件,粘貼到第二步對(duì)應(yīng)的方框內(nèi)。
- 即可生成node常用應(yīng)用程序的儀表盤
- 導(dǎo)入JVM及其它儀表盤:重復(fù)步驟1
3、自定義儀表盤(就是點(diǎn)點(diǎn)點(diǎn))
- 新建儀表盤
- 添加可視化面板
- 選擇數(shù)據(jù)源
- 自定義儀表盤
- 保存或應(yīng)用
文章來源:http://www.zghlxwxcb.cn/news/detail-856256.html
- 效果如圖:添加其它可視化表重復(fù)1~6步
文章來源地址http://www.zghlxwxcb.cn/news/detail-856256.html
到了這里,關(guān)于Prometheus + Grafana 搭建監(jiān)控儀表盤的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!