云技術(shù)在網(wǎng)站建設(shè)中的應(yīng)用免費(fèi)網(wǎng)絡(luò)推廣軟件
前提環(huán)境:
- Docker環(huán)境
涉及參考文檔:
- 安裝Prometheus
- 開始 Prometheus
- node_exporter Agent組件
一、部署Prometheus
1、啟動容器將文件拷貝出來
docker run -d prom/prometheus
2、容器將文件拷貝出來
docker cp 容器ID:/usr/share/prometheus/console_libraries /usr/share/prometheus/docker cp 容器ID:/usr/share/prometheus/consoles/ /usr/share/prometheus/docker cp 容器ID:/etc/prometheus /data/docker_data/Promthues/confdocker cp 容器ID:/prometheus /data/docker_data/Promthues/data
3、修改數(shù)據(jù)存儲權(quán)限。 默認(rèn)容器中是nobody:nobody 只能修改為777
chmod 777 /data/docker_data/Promthues/data
4、啟動docker
docker run --name prometheus -d \
-v /data/docker_data/Promthues/data:/prometheus \
-v /data/docker_data/Promthues/conf:/etc/prometheus \
-p 9090:9090 prom/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--web.listen-address="0.0.0.0:9090" \
--storage.tsdb.path=/prometheus \
--web.console.libraries=/usr/share/prometheus/console_libraries \
--web.console.templates=/usr/share/prometheus/consoles \
--storage.tsdb.retention=30d \
--web.enable-lifecycle
二、訪問WEB控制臺
訪問URL : IP+9090
三、安裝node_exporter 組件
docker run -d --name node_exporter \--restart=always \--net="host" \--pid="host" \-v "/proc:/host/proc:ro" \-v "/sys:/host/sys:ro" \-v "/:/rootfs:ro" \prom/node-exporter \--path.procfs=/host/proc \--path.rootfs=/rootfs \--path.sysfs=/host/sys \--collector.textfile.directory=/data/docker_data/Promthues/prom \--collector.filesystem.ignored-mount-points='^/(sys|proc|dev|host|etc)($$|/)'
四、配置 Prometheus 以監(jiān)視自身
global: #全局scrape_interval: 15s # 默認(rèn)情況下即拉取業(yè)務(wù)監(jiān)控數(shù)據(jù)的間隔時間,默認(rèn)一分鐘scrape_timeout: 10s # 即拉取業(yè)務(wù)監(jiān)控數(shù)據(jù)接口的超時時間evaluation_interval: 15s # 默認(rèn)評估規(guī)則的頻率,默認(rèn)一分鐘# Attach these labels to any time series or alerts when communicating with# external systems (federation, remote storage, Alertmanager).external_labels:monitor: 'codelab-monitor'scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: 'prometheus'# Override the global default and scrape targets from this job every 5 seconds.scrape_interval: 5sstatic_configs:- targets: ['localhost:9090']labels:name: Prometheus
五、控制臺抓取數(shù)據(jù)
1、重新查看當(dāng)前Prometheus的標(biāo)簽
2、重新查看當(dāng)前Prometheus的標(biāo)簽
avg by (job, instance, mode) (rate(node_cpu_seconds_total{instance="10.1.32.231"}[5m]))
3、修改Prometheus 主配置文件
mkdir -p /data/docker_data/Promthues/conf/rules
global: #全局scrape_interval: 15s # 默認(rèn)情況下即拉取業(yè)務(wù)監(jiān)控數(shù)據(jù)的間隔時間,默認(rèn)一分鐘scrape_timeout: 10s # 即拉取業(yè)務(wù)監(jiān)控數(shù)據(jù)接口的超時時間evaluation_interval: 15s # 默認(rèn)評估規(guī)則的頻率,默認(rèn)一分鐘# Attach these labels to any time series or alerts when communicating with# external systems (federation, remote storage, Alertmanager).external_labels:monitor: 'codelab-monitor'rule_files:- "rules/*.yml" # 指定自定義規(guī)則文件存放目錄scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: 'prometheus'# Override the global default and scrape targets from this job every 5 seconds.scrape_interval: 5sstatic_configs:- targets: ['localhost:9090']labels:name: Prometheus
4、配置Prometheus記錄規(guī)則
vim /data/docker_data/Promthues/conf/rules/cpu-node.yml
groups:
- name: cpu-noderules:- record: job_instance_mode:node_cpu_seconds:avg_rate5mexpr: avg by (job, instance, mode) (rate(node_cpu_seconds_total{instance="10.1.32.231"}[5m]))
5、熱加載Prometheus 服務(wù)
檢查語法是否符合
docker exec -it prometheus promtool check config /etc/prometheus/prometheus.ym
熱加載配置文件
curl -XPOST http://localhost:9090/-/reload
6、重新登錄Web控制臺
點(diǎn)擊匹配規(guī)則,自動跳轉(zhuǎn)到Web 查詢界面
匹配規(guī)則作為告警閾值進(jìn)行釘釘通知告警
, 后面篇章會記錄學(xué)習(xí)筆記。