Docker方式
mkdir -p /opt/prometheus/{config,data}
chmod 777 /opt/prometheus/data
cd /opt/prometheus/config
wget -O prometheus.yml http://download.zhufunin.com/prometheus.yml
docker run -d --restart=always --name prometheus -p 9090:9090 -v /opt/prometheus/config:/etc/prometheus -v /opt/prometheus/data:/prometheus prom/prometheus
二進制安裝
useradd prometheus -s /sbin/nologin
tar zxvf prometheus-2.14.0.linux-amd64.tar.gz -C /usr/local/
mv prometheus-2.14.0.linux-amd64 /usr/local/prometheus
chown prometheus:prometheus -R /usr/local/prometheus
#加入系統(tǒng)服務(wù)
vi /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network.target
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus/data
User=prometheus
[Install]
WantedBy=multi-user.target
#開機啟動蛋勺,啟動服務(wù)
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus
image.png
配置文件
prometheus.yml
? global:全局配置
scrape_interval: 15s # 采集數(shù)據(jù)時間間隔
evaluation_interval: 15s # 評估告警規(guī)則時間間隔颅拦,默認(rèn)1分鐘
scrape_timeout: 5s # 采集數(shù)據(jù)超時時間,默認(rèn)10秒
? rule_files:告警規(guī)則
? scrape_configs:配置被監(jiān)控端,稱為target撮胧,每個target用
job_name分組管理,又分為靜態(tài)配置和服務(wù)發(fā)現(xiàn)
? alerting:告警配置
? remote_write/remote_read:從遠程數(shù)據(jù)庫讀寫
其中被監(jiān)控端部分:
目標(biāo)(targets):被監(jiān)控端
實例(Instances):每個被監(jiān)控端稱為實例
作業(yè)(Job):具有相同目標(biāo)的實例集合稱為作業(yè)
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['192.168.1.10:9090']
監(jiān)控指標(biāo)數(shù)據(jù)模型
數(shù)據(jù)模型:
? Prometheus將所有數(shù)據(jù)存儲為時間序列钢猛;
? 具有相同度量名稱以及標(biāo)簽屬于同一個指標(biāo)锈嫩;
? 每個時間序列都由度量標(biāo)準(zhǔn)名稱和一組鍵值對(稱為標(biāo)簽)唯一標(biāo)識,通過標(biāo)簽查詢指定指標(biāo)甥角。
指標(biāo)格式:
<metric name>{<label name>=<label value>,...}