網(wǎng)站建設(shè)與域名建設(shè)國際時事新聞最新消息
首先確保Linux已安裝Docker,如未安裝請先參考:Linux安裝Docker
1.安裝準(zhǔn)備
創(chuàng)建掛載目錄
/opt/prometheus/data目錄,準(zhǔn)備用來掛載放置prometheus的數(shù)據(jù)
/opt/prometheus/config目錄,準(zhǔn)備用來放置prometheus的配置文件
/opt/prometheus/rules目錄,準(zhǔn)備用來掛載放置prometheus的規(guī)則文件
mkdir -p /opt/prometheus/{data,config,rules}
授權(quán)相關(guān)權(quán)限
chmod -R 777 /opt/prometheus/data
chmod -R 777 /opt/prometheus/config
chmod -R 777 /opt/prometheus/rules
2.配置文件
文件內(nèi)容
文件放入新建的config目錄下
global:# 數(shù)據(jù)采集間隔scrape_interval: 45s# 告警檢測間隔evaluation_interval: 45s
# 啟用alertmanager
alerting:alertmanagers:- static_configs:- targets:- 192.168.250.132:9093
# 告警規(guī)則
rule_files:# 這里匹配指定目錄下所有的.rules文件- /prometheus/rules/*.rules# 采集配置
scrape_configs:# 采集項(prometheus)- job_name: 'prometheus'static_configs:# prometheus自帶了對自身的exporter監(jiān)控程序,所以不需額外安裝exporter就可配置采集項- targets: ['192.168.250.132:9090','192.168.250.132:8080','192.168.250.132:9100']- job_name: 'springboot-order'metrics_path: '/actuator/prometheus'static_configs:- targets: ['192.168.250.124:7080']
配置含義
global:全局配置 (如果有內(nèi)部單獨(dú)設(shè)定,會覆蓋這個參數(shù))
alerting:告警插件定義。這里會設(shè)定alertmanager這個報警插件
rule_files:告警規(guī)則。 按照設(shè)定參數(shù)進(jìn)行掃描加載,用于自定義報警規(guī)則,其報警媒介和route路由由alertmanager插件實(shí)現(xiàn)
scrape_configs:采集配置。配置數(shù)據(jù)源,包含分組job_name以及具體target。又分為靜態(tài)配置和服務(wù)發(fā)現(xiàn)
remote_write:用于遠(yuǎn)程存儲寫配置
remote_read:用于遠(yuǎn)程讀配置
啟動
啟動命令
docker run --name prometheus -d \-p 9090:9090 \-v /etc/localtime:/etc/localtime:ro \-v /opt/prometheus/data:/prometheus/data \-v /opt/prometheus/config:/prometheus/config \-v /opt/prometheus/rules:/prometheus/rules \prom/prometheus --config.file=/prometheus/config/prometheus.yml --web.enable-lifecycle
查看啟動情況
docker ps -a
看到Prometheus的狀態(tài)為UP,證明正在運(yùn)行,端口9090,接下來可以到瀏覽器訪問
訪問Prometheus
URL:ip:端口號
IP為Linux網(wǎng)卡IP,端口號為我們設(shè)置的為9090
看到下面的界面,訪問成功
操作結(jié)束
同系列文章
Linux安裝Docker
Docker拉取并配置Grafana
Docker安裝并配置Node-Exporter
Docker安裝并配置cAdvisor
Docker安裝并運(yùn)行Alertmanager
Prometheus+Grafana+AlertManager監(jiān)控Linux主機(jī)狀態(tài)
Prometheus+Grafana+AlertManager監(jiān)控SpringBoot項目并發(fā)送郵件告警通知