GitHub網址:https://github.com/prometheus/prometheus
軟件下載地址:https://prometheus.io/download/
第三方中文介紹:https://github.com/1046102779/prometheus
prometheus介紹
Prometheus是一個開源的系統監控和報警的工具包,最初由SoundCloud發布。
特點:
- 多維數據模型(有metric名稱和鍵值對確定的時間序列)
- 靈活的查詢語言
- 不依賴分布式存儲
- 通過pull方式采集時間序列,通過http協議傳輸
- 支持通過中介網關的push時間序列的方式
- 監控數據通過服務或者靜態配置來發現
- 支持圖表和dashboard等多種方式
組件:
- Prometheus 主程序,主要是負責存儲、抓取、聚合、查詢方面。
- Alertmanager 程序,主要是負責實現報警功能。
- Pushgateway 程序,主要是實現接收由Client push過來的指標數據,在指定的時間間隔,由主程序來抓取。
- *_exporter 這類是不同系統已經實現了的集成。
架構:
prometheus部署
1、下載安裝包prometheus-1.6.2.linux-amd64.tar.gz
https://github.com/prometheus/prometheus/releases/tag/v1.6.2
2、解壓
tar -xvf prometheus-1.6.2.linux-amd64.tar.gz cd prometheus-1.6.2.linux-amd64
3、配置prometheus.yml
- scrape_interval: 15s # 默認15秒到目標處抓取數據
4、啟動
nohup ./prometheus -config.file=prometheus.yml & 或 nohup /opt/prometheus-1.6.2.linux-amd64/prometheus &
5、WEB頁面訪問http://localhost:9090/ ,可以看到Prometheus的graph頁面。
備注:參考文章 http://www.cnblogs.com/vovlie/p/Prometheus_install.html
grafana部署
http://docs.grafana.org/installation/rpm/
1、安裝
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.2.0-1.x86_64.rpm sudo yum install initscripts fontconfig -y sudo rpm -Uvh grafana-4.2.0-1.x86_64.rpm
2、啟動服務service grafana-server start
3、訪問頁面http://localhost:3000 ,默認賬號、密碼admin/admin
4、Prometheus 和 Grafana 的對接
https://prometheus.io/docs/visualization/grafana/
參考文章:http://www.cnblogs.com/sfnz/p/6566951.html
MySQL的dashboards(Grafana)
https://github.com/percona/grafana-dashboards
git clone https://github.com/percona/grafana-dashboards.git cp -r grafana-dashboards/dashboards /var/lib/grafana/dashboards
編輯Grafana配置文件
vi /etc/grafana/grafana.ini [dashboards.json] enabled = true path = /var/lib/grafana/dashboards
重啟service grafana-server restart
mysql監控部署
在需要監控的mysql上安裝 node_exporter和 mysqld_exporter
下載 https://prometheus.io/download/
tar -xvf node_exporter-0.14.0.linux-amd64.tar.gz cd node_exporter-0.14.0.linux-amd64 nohup ./node_exporter &
tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz cd mysqld_exporter-0.10.0.linux-amd64 vi .my.cnf [client] user=root password=root ./mysqld_exporter -config.my-cnf=".my.cnf" &
服務端配置,文件prometheus.yml
scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'mysql' static_configs: - targets: ['10.10.83.162:9104'] labels: instance: db-10.10.83.162
redis監控部署
下載 https://github.com/oliver006/redis_exporter/releases
tar -xvf redis_exporter-v0.11.linux-amd64.tar.gz nohup /opt/redis_exporter -redis.addr "redis://10.10.83.162:16379" &
grafana配置
下載 redis_exporter-0.11.tar.gz
tar -xvf redis_exporter-0.11.tar.gz cd redis_exporter-0.11 cp *json /var/lib/grafana/dashboards/
服務端配置,文件prometheus.yml
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] - job_name: 'mysql' static_configs: - targets: ['10.10.83.162:9104'] labels: instance: db-10.10.83.162 - job_name: redis_exporter static_configs: - targets: ['10.10.83.162:9121'] labels: instance: redis-10.10.83.162