簡介
Prometheus通過命令列和組態檔共同進行配置,一般用命令列配置來配置不變更的屬性,如資料存盤位置、資料存盤時間、存盤大小等,具體的命令列引數可通過 ./prometheus -h查看,組態檔主要用來對資料抓取資訊、規則資訊進行配置,
Prometheus可以在運行時對組態檔的內容進行重新reload,從而實作配置資訊的動態更新,如果組態檔格式有問題,Prometheus會繼續采用舊的配置項,
重新加載配置項有如下兩種方式
-
通過向Prometheus行程發送HUP信號
$ ps -elf |grep -e PID -e prometheus $ kill -s HUP ${pid} #上一步驟找出來的pid如果Prometheus用systemctl進行控制啟動,服務檔案中有ExecReload=/bin/kill -s HUP $MAINPID配置項,可以采用如下命令重新加載配置
$ systemctl reload prometheus.service -
通過Prometheus暴露的rest介面,需要在啟動時指定--web.enable-lifecycle引數
$ curl -XPOST http://192.168.0.107:9090/-/reloadhttp://192.168.0.107:9090是Prometheus服務器地址
組態檔
在啟動Prometheus服務時,通過--config.file引數來設定讀取的組態檔,Prometheus組態檔用yaml格式編輯,配置格式如下
global:
# How frequently to scrape targets by default.
[ scrape_interval: <duration> | default = 1m ]
# How long until a scrape request times out.
[ scrape_timeout: <duration> | default = 10s ]
# How frequently to evaluate rules.
[ evaluation_interval: <duration> | default = 1m ]
# The labels to add to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
[ <labelname>: <labelvalue> ... ]
# File to which PromQL queries are logged.
# Reloading the configuration will reopen the file.
[ query_log_file: <string> ]
# Rule files specifies a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
[ - <filepath_glob> ... ]
# A list of scrape configurations.
scrape_configs:
[ - <scrape_config> ... ]
# Alerting specifies settings related to the Alertmanager.
alerting:
alert_relabel_configs:
[ - <relabel_config> ... ]
alertmanagers:
[ - <alertmanager_config> ... ]
# Settings related to the remote write feature.
remote_write:
[ - <remote_write> ... ]
# Settings related to the remote read feature.
remote_read:
[ - <remote_read> ... ]
- global 全域性配置,如Prometheus拉取指標資料的間隔,Prometheus根據rule檔案進行計算的周期等
- rule_files 配置rule檔案的路徑位置
- scrape_configs Prometheus拉取指標資訊配置項
- alerting 報警配置資訊
- remote_write 將指標資料寫入到外部時間序列資料庫(influxdb等)對應的配置資訊
- remote_read 從外部時間序列庫讀取資料的配置資訊
此處主要說明一下啊scrape_configs,其他配置的具體資訊可參考configuration
在scrape_configs下可以配置多個scrape_config,每一個scrape_config可以配置一系列的監控物件、以及從這些物件拉取監控資料的引數,例如
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['localhost:9100','node2:9100']
- job_name: 'spring-boot'
metrics_path: /actuator/prometheus
static_configs:
- targets: ['192.168.0.108:8080']
其中監控物件可以通過static_configs靜態配置一個監控串列,也可以采用動態服務發現技術來自動發現被監控的物件,如kubernetes_sd_configs、dns_sd_configs、file_sd_configs
file_sd_configs是最通用的一種服務發現方式,可以很方便幫助我們實作自定義的服務發現功能,其核心思想是通過disk watches持續觀察此屬性指定的檔案串列,當任一檔案中的targets串列發生變更后,立即更新Prometheus的拉取指標資料物件,從變更后的targets串列中獲取指標資料,例如Docker Swarm、Packet等都是通過這個機制來進行自動發現監控物件的,
完整配置例子 example file
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/36620.html
標籤:其他
上一篇:Promethues(二)安裝
