一、概述
Prometheus 是什么?
Prometheus是一套開源的監控&報警&時間序列數據庫的組合,起始是由SoundCloud公司開發的。隨着發展,越來越多公司和組織接受采用Prometheus,社區也十分活躍,他們便將它獨立成開源項目,並且有公司來運作。google SRE的書內也曾提到跟他們BorgMon監控系統相似的實現是Prometheus。現在最常見的Kubernetes容器管理系統中,通常會搭配Prometheus進行監控。
Prometheus 的優點
非常少的外部依賴,安裝使用超簡單
已經有非常多的系統集成 例如:docker HAProxy Nginx JMX等等
服務自動化發現
直接集成到代碼
設計思想是按照分布式、微服務架構來實現的
Prometheus 的特性
自定義多維度的數據模型
非常高效的存儲 平均一個采樣數據占 ~3.5 bytes左右,320萬的時間序列,每30秒采樣,保持60天,消耗磁盤大概228G。
強大的查詢語句
輕松實現數據可視化
等等
相對於Graphite這種產品,還是有不少優點的。最讓我覺得不錯的是非常優秀的寫性能和讀取性能,它數據結構實現和OpenTSDB是有相似之處,有興趣可以看看這個文檔
二、安裝Prometheus
下載http://cactifans.hi-www.com/prometheus/prometheus-2.1.0.linux-amd64.tar.gz
prometheus安裝比較簡單,下載編譯好的二進制文件,修改好配置文件,直啟動即可
下載之后解壓
tar zxvf prometheus-2.1.0.linux-amd64.tar.gz
mv prometheus-2.1.0.linux-amd64 /usr/local/rometheus
解壓之后,會有一個默認的配置文件,可以直接使用這個配置文件啟動
cd /usr/local/prometheus
./prometheus --config.file=prometheus.yml
即可啟動prometheus,默認端口為9090.通過瀏覽器可以看到如下頁面,表示prometheus啟動正常。
prometheus自帶的繪圖功能比較弱,如何才能使展示效果高大上呢?這里就要使用Grafana.借助與Grafana可以完全自定義屬於自己的Dashboard監控視圖。
使用Yum安裝Grafana
yum install https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
這將以包安裝期間創建grafana-server
的grafana
用戶身份啟動進程。默認HTTP端口是3000
,默認用戶和組是admin
。
默認登錄名和密碼admin
/admin
systemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server
#!/bin/bash
#stop prometheus
pidnum=$(sudo ps -ef|grep prometheus|grep -v grep|awk -F " " '{print $2}')
sudo kill -9 ${pidnum}
#start prometheus
sudo nohup /opt/prometheus-2.8.0/prometheus --config.file /data/prometheus/conf/prometheus.yml --storage.tsdb.path /data --storage.tsdb.retention 30d --web.console.templates /opt/prometheus-2.8.0/consoles/ --web.console.libraries /opt/prometheus-2.8.0/console_libraries &