Prometheus 配置文件與核心功能
#全局配置選項(xiàng)
global:
? # 采集被監(jiān)控端的一個(gè)周期 默認(rèn)一分鐘采集一次
? [ scrape_interval: <duration> | default = 1m ]
? # 采集時(shí)的超時(shí)候就 請求接口10s里面沒有響應(yīng)就是失敗的
? [ scrape_timeout: <duration> | default = 10s ]
? # 告警的評估周期 默認(rèn)是一分鐘
? [ evaluation_interval: <duration> | default = 1m ]
? #web標(biāo)簽
? external_labels:
? ? [ <labelname>: <labelvalue> ... ]
? [ query_log_file: <string> ]
#指定規(guī)則監(jiān)控告警規(guī)則
rule_files:
? [ - <filepath_glob> ... ]
# A list of scrape configurations.
#配置被監(jiān)控指標(biāo)
scrape_configs:
? [ - <scrape_config> ... ]
#配置告警
alerting:
? alert_relabel_configs:
? ? [ - <relabel_config> ... ]
#配置告警組件的連接地址 也可以對告警重新打標(biāo)簽
? alertmanagers:
? ? [ - <alertmanager_config> ... ]
# 寫
remote_write:
? [ - <remote_write> ... ]
# 讀
remote_read:
? [ - <remote_read> ... ]?
relabel_configs
? ? ? static_configs:
? ? - targets: ['localhost:9090']
? ? relabel_configs: #配置規(guī)則
? ? - action: replace #重寫
? ? ? source_labels: ['job'] #標(biāo)簽重新命名
? ? ? regex: (.*) #正則匹配
? ? ? replacement: $1 #使用正則匹配第一個(gè)變量
? ? ? target_label: idc #job修改成IDC
? 統(tǒng)計(jì)機(jī)房cpu使用總和
? ? sum(process_cpu_seconds_total{job="bj"})
relabel_configs 動作
action:重新標(biāo)簽動作
? replace:默認(rèn),通過regex匹配source_label的值,使用replacement來引用表達(dá)式匹配的分組
? keep:刪除regex與連接不匹配的目標(biāo) source_labels
? drop:刪除regex與連接匹配的目標(biāo) source_labels
? labeldrop:刪除regex匹配的標(biāo)簽
? labelkeep:刪除regex不匹配的標(biāo)簽
? hashmod:設(shè)置target_label為modulus連接的哈希值source_labels
? labelmap:匹配regex所有標(biāo)簽名稱。然后復(fù)制匹配標(biāo)簽的值進(jìn)行分組,replacement分組引用(${1},${2},…)替代?
選擇采集目標(biāo)?(監(jiān)控端)
drop 過濾不需要采集的目標(biāo)
keep 過濾需要采集的目標(biāo)
labeldrop 實(shí)例
? - action: labeldrop
? ? ? regex: job
刪除job
=======================================================
#基于文件的服務(wù)發(fā)現(xiàn)
? azure_sd_configs
? consul_sd_configs
? dns_sd_configs
? ec2_sd_configs
? openstack_sd_configs
? file_sd_configs
? gce_sd_configs
? kubernetes_sd_configs
? marathon_sd_configs
? nerve_sd_configs
? serverset_sd_configs
? triton_sd_configs
=======================================================
文件服務(wù)發(fā)現(xiàn)
? file_sd_configs:
? ? ? - files: ['/usr/local/prometheus/sd_config/*.yml']
? ? ? ? #文件路徑
? ? ? ? refresh_interval: 5s
? ? ? ? #服務(wù)發(fā)現(xiàn)時(shí)間
服務(wù)發(fā)現(xiàn)文件配置
? - targets: ['localhost:9090']
? labels:
? ? idc: CD
總結(jié)
? 當(dāng)你實(shí)例很多時(shí) 有很多動態(tài)縮容擴(kuò)容這樣非常適合 動態(tài)發(fā)現(xiàn)的
? Prometheus會定期去掃文件看有沒有修改 有修改就添加新的實(shí)例進(jìn)來