“Prometheus”的版本间的差异

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索
 
(未显示同一用户的23个中间版本)
第1行: 第1行:
 
'''Prometheus'''是一個[[TSDB]]。
 
'''Prometheus'''是一個[[TSDB]]。
 +
 +
== 概要 ==
 +
 +
Prometheus本身是一個TSDB(Time series database),會主動到目標機器上蒐集資料後寫入資料庫,另外Prometheus可以設定警示條件送進Alertmanager,由Alertmanager送到外部服務通知(像是[[Slack]],或是[[PagerDuty]])。
  
 
== 安裝 ==
 
== 安裝 ==
 +
 +
[[Ubuntu]] 20.04系統內的Prometheus太舊(2.15),加上沒有適合的PPA可以用,這邊使用官方的binary安裝:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
cd /tmp; wget https://github.com/prometheus/prometheus/releases/download/v2.16.0/prometheus-2.16.0.linux-amd64.tar.gz; tar zxvf prometheus-2.16.0.linux-amd64.tar.gz; cd prometheus-2.16.0.linux-amd64; sudo cp prometheus promtool tsdb /usr/bin; sudo mkdir /etc/prometheus; sudo cp prometheus.yml /etc/prometheus/; sudo cp -R consoles/ console_libraries/ /etc/prometheus/
+
export PROMETHEUS_VERSION=2.23.0; cd /tmp; wget https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz; tar xvf prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz; cd prometheus-${PROMETHEUS_VERSION}.linux-amd64; sudo cp -f prometheus promtool /usr/bin; sudo mkdir /etc/prometheus; sudo cp prometheus.yml /etc/prometheus/; sudo cp -R consoles/ console_libraries/ /etc/prometheus/; sudo useradd -r -U prometheus; sudo mkdir /var/lib/prometheus; sudo chown prometheus:prometheus /var/lib/prometheus; echo -e "[Unit]\nDescription=Prometheus Time Series Collection and Processing Server\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=/usr/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /lib/systemd/system/prometheus.service; sudo systemctl daemon-reload; sudo systemctl enable prometheus; sudo service prometheus start
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
另外一起裝Alertmanager:
 +
 +
<syntaxhighlight lang="bash">
 +
export ALERTMANAGER_VERSION=0.23.0; cd /tmp; wget https://github.com/prometheus/alertmanager/releases/download/v${ALERTMANAGER_VERSION}/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz; tar xvf alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz; cd alertmanager-${ALERTMANAGER_VERSION}.linux-amd64; sudo cp -f alertmanager amtool /usr/bin; sudo mkdir /etc/amtool /var/lib/alertmanager; sudo chown prometheus:prometheus /var/lib/alertmanager; sudo cp alertmanager.yml /etc/amtool; echo -e "[Unit]\nDescription=Prometheus Alertmanager\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=/usr/bin/alertmanager --config.file /etc/amtool/alertmanager.yml --storage.path /var/lib/alertmanager\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /lib/systemd/system/alertmanager.service; sudo systemctl daemon-reload; sudo systemctl enable alertmanager; sudo service alertmanager start
 +
</syntaxhighlight>
 +
 +
== 設定 ==
 +
 +
要注意官方安裝檔內的<code>prometheus.yml</code>中<code>scrape_interval</code>與<code>evaluation_interval</code>預設是<code>15s</code>(但不設定時預設是<code>1m</code>),正常情況下<code>5m</code>應該是夠用,可以考慮指定<code>5m</code>降低頻率。
  
 
== 外部連結 ==
 
== 外部連結 ==

2021年9月25日 (六) 12:30的最新版本

Prometheus是一個TSDB

概要

Prometheus本身是一個TSDB(Time series database),會主動到目標機器上蒐集資料後寫入資料庫,另外Prometheus可以設定警示條件送進Alertmanager,由Alertmanager送到外部服務通知(像是Slack,或是PagerDuty)。

安裝

Ubuntu 20.04系統內的Prometheus太舊(2.15),加上沒有適合的PPA可以用,這邊使用官方的binary安裝:

export PROMETHEUS_VERSION=2.23.0; cd /tmp; wget https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz; tar xvf prometheus-${PROMETHEUS_VERSION}.linux-amd64.tar.gz; cd prometheus-${PROMETHEUS_VERSION}.linux-amd64; sudo cp -f prometheus promtool /usr/bin; sudo mkdir /etc/prometheus; sudo cp prometheus.yml /etc/prometheus/; sudo cp -R consoles/ console_libraries/ /etc/prometheus/; sudo useradd -r -U prometheus; sudo mkdir /var/lib/prometheus; sudo chown prometheus:prometheus /var/lib/prometheus; echo -e "[Unit]\nDescription=Prometheus Time Series Collection and Processing Server\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=/usr/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus/ --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /lib/systemd/system/prometheus.service; sudo systemctl daemon-reload; sudo systemctl enable prometheus; sudo service prometheus start

另外一起裝Alertmanager:

export ALERTMANAGER_VERSION=0.23.0; cd /tmp; wget https://github.com/prometheus/alertmanager/releases/download/v${ALERTMANAGER_VERSION}/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz; tar xvf alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz; cd alertmanager-${ALERTMANAGER_VERSION}.linux-amd64; sudo cp -f alertmanager amtool /usr/bin; sudo mkdir /etc/amtool /var/lib/alertmanager; sudo chown prometheus:prometheus /var/lib/alertmanager; sudo cp alertmanager.yml /etc/amtool; echo -e "[Unit]\nDescription=Prometheus Alertmanager\nWants=network-online.target\nAfter=network-online.target\n\n[Service]\nUser=prometheus\nGroup=prometheus\nType=simple\nExecStart=/usr/bin/alertmanager --config.file /etc/amtool/alertmanager.yml --storage.path /var/lib/alertmanager\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /lib/systemd/system/alertmanager.service; sudo systemctl daemon-reload; sudo systemctl enable alertmanager; sudo service alertmanager start

設定

要注意官方安裝檔內的prometheus.ymlscrape_intervalevaluation_interval預設是15s(但不設定時預設是1m),正常情況下5m應該是夠用,可以考慮指定5m降低頻率。

外部連結