Prometheus簡介
Prometheus是最初在SoundCloud上構建的開源系統監視和警報工具包。 自2012年成立以來,許多公司和組織都采用了Prometheus,該項目擁有非常活躍的開發人員和用戶社區。它是一個獨立的開源項目,並且獨立於任何公司進行維護。 為了強調這一點並闡明項目的治理結構,Prometheus在2016年加入了Cloud Native Computing Foundation,這是繼Kubernetes之后的第二個托管項目。
Prometheus服務,可以直接通過目標拉取數據,或者間接地通過中間網關拉取數據。它在本地存儲抓取的所有數據,並對這些數據運行規則,以匯總和記錄現有數據中的新時間序列,或生成警報。 Grafana或其他API使用者可用於可視化收集的數據。
組件
服務器抓取並存儲時間序列數據客戶端庫以檢測應用程序代碼
一個支持短暫工作的推送網關
支持以下HAProxy,StatsD,Graphite等服務接口
告警
大多數Prometheus組件都是用Go編寫的,因此易於構建和部署為靜態二進制文件。
場景
適用場景
Prometheus非常適合記錄任何純數字時間序列。它既適用於面向服務器等硬件指標的監控,也適合於高度動態的面向服務的體系結構的監視。 在微服務世界中,它對多維數據收集和查詢的支持是一種特別的優勢。
Prometheus的設計旨在提高可靠性,使其成為中斷期間要使用的系統,以使您能夠快速診斷問題。 每個Prometheus服務器都是獨立的,而不依賴於網絡存儲或其他遠程服務。 當服務出現故障時,它可以使你快速定位和診斷問題。它的搭建過程對硬件和服務沒有很強的依賴關系
不適用場景
Prometheus,主要在於可靠性,在很惡劣的環境下,都可以隨時訪問它和查看系統服務各種指標的統計信息。 如果你對統計數據需要100%的精確,它並不適用,例如:實時計費系統
安裝方式
二進制)
1.獲取源碼包
wget https://github.com/prometheus/prometheus/releases/download/v2.17.1/prometheus-2.17.1.linux-amd64.tar.gz
國內鏡像
wget https://mirrors.tuna.tsinghua.edu.cn/github-release/prometheus/prometheus/2.17.1%20_%202020-03-26/prometheus-2.17.1.linux-amd64.tar.gz
2.解壓,運行
tar zxvf prometheus*.gz 默認啟動占用9090端口,開啟防火牆 firewall-cmd --add-port=9090/tcp --permanent firewall-cmd --reload 啟動 ./prometheus --config.file=prometheus.yml
3.輸入ip:9090即可訪問
Docker)
后台運行:
1)后台運行&
./prometheus --config.file=prometheus.yml --web.enable-lifecycle > /prometheus.log 2>&1 &
2)systemctl方式
新增prometheus.service
[Unit] Description=prometheus Documentation=https://prometheus.io/docs/introduction/overview/ After=network.target [Service] #User=root #Group=root Type=simple # 啟動腳本 ExecStart=/opt/prometheus-2.30.1.linux-amd64/prometheus \ --config.file=/opt/prometheus-2.30.1.linux-amd64/prometheus.yml \ --web.enable-lifecycle ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target
重新加載配置
systemctl daemon-reload
開機啟動
systemctl enable prometheus.service
啟動服務
systemctl start prometheus.service
查看啟動狀態
systemctl status prometheus
熱加載
Prometheus配置信息的熱加載有兩種方式:
第一種熱加載方式:查看Prometheus的進程id,發送SIGHUP
信號:
kill -HUP <pid>
第二種熱加載方式:發送一個POST請求到/-/reload
,需要在啟動時給定--web.enable-lifecycle
選項:
curl -X POST http://localhost:9090/-/reload
如果配置熱加載成功,Prometheus會打印出下面的log:
msg="Loading configuration file" filename=prometheus.yml