Prometheus監控軟體部署方法
背景:負責基於區塊鏈的某公正專案的狀態上報模組設計編碼,基於Prometheus進行二次開發
1、說明
Prometheus 是一個開源的服務監控軟體,它通過 HTTP 協議從遠端機器收集資料並存儲在本
地的時序資料庫上。Prometheus 通過安裝在遠端機器上的 exporter 來收集監控資料。
目前用到兩個 exporter:
a、node exporter,用於收集系統資料
b、mysqld exporter, 用於收集 Mysql 資料
下面本地的相關路徑、使用者名稱、密碼、引數配置僅作例子。
2、安裝 Prometheus
a、下載
https://github.com/prometheus/prometheus/releases/download/v1.6.3/prometheus-
1.6.3.linux-amd64.tar.gz -O prometheus-1.6.3.linux-amd64.tar.gz
b、解壓
mkdir /usr/local/services/prometheus
tar zxf prometheus-1.6.3.linux-amd64.tar.gz -C /usr/local/services/prometheus –
strip-components=1
3、配置 Prometheus
在安裝目錄下編輯配置檔案 prometheus.yml,host 是主機 IP,埠對應 exporter 監
聽埠
global:
scrape_interval:
15s
evaluation_interval: 15s
scrape_configs:
- job_name: XXX1system
static_configs:
- targets: ['host:9103']
labels:
instance: XXX 1system
- job_name: XXX 1mysql
static_configs:
- targets: ['host:9104']
labels:
instance: XXX 1mysql
- job_name: XXX 2system
static_configs:
- targets: ['host:9103']
labels:
instance: XXX 2system
- job_name: XXX 2mysql
static_configs:
- targets: ['host:9104']
labels:
instance: XXX 2mysql
同理。。。。。。。。。。。。。。。。。。。。。。。。。。。。
4、執行 Prometheus
./prometheus -web.listen-address “:9092”
5、部署 exporter
a、下載
wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_expor ter-0.14.0.linux-amd64.tar.gz -O node_exporter-0.14.0.linux-amd64.tar.gz
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_e xporter-0.10.0.linux-amd64.tar.gz -O mysqld_exporter-0.10.0.linux-amd64.tar.gz
b、解壓
tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1
tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C/usr/local/services/prometheus_exporters –strip-components=1
c、執行
cd /usr/local/services/prometheus_exporters
node exporter 直接執行即可
./node_exporter -web.listen-address “:9103”
cd /usr/local/services/prometheus_exporters
建立.my.cnf 檔案
cat << EOF > .my.cnf
[client]
user=root
password=1qaz@WSX3edc$RFVyl
EOF
現在可以執行 mysqld exporter
./mysqld_exporter -config.my-cnf=".my.cnf"
6、檢驗
Prometheus 內建了一個 web 介面,我們可以通過 http://FBAAR 的 ip:9092 進行訪問。訪問介面,在
Status->Targets 下,看到 Target 的狀態變為 up 時,說明 Prometheus 可正常接收 exporter 的資料
了