概述
Prometheus是一個開源的服務(wù)監(jiān)控系統(tǒng),它通過HTTP協(xié)議從遠(yuǎn)程的機(jī)器收集數(shù)據(jù)并存儲在本地的時序數(shù)據(jù)庫上。它提供了一個簡單的網(wǎng)頁界面、一個功能強(qiáng)大的查詢語言以及HTTP接口等等。Prometheus通過安裝在遠(yuǎn)程機(jī)器上的exporter來收集監(jiān)控數(shù)據(jù),這里用到了以下兩個exporter:
Grafana是一個開源的功能豐富的數(shù)據(jù)可視化平臺,通常用于時序數(shù)據(jù)的可視化。它內(nèi)置了以下數(shù)據(jù)源的支持:

并可以通過插件擴(kuò)展支持的數(shù)據(jù)源。
架構(gòu)圖
下面是本次部署的架構(gòu)圖

安裝并運(yùn)行Prometheus
1.在 Monitor 上安裝 Prometheus
安裝至/opt/prometheus
| $ wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5.2.linux-amd64.tar.gz$ tar zxvf prometheus-1.5.2.linux-amd64.tar.gz$ mv prometheus-1.5.2.linux-amd64 /opt/prometheus | 
2.在安裝目下編輯配置文件 prometheus.yml
| vim /opt/prometheus/prometheus.yml | 
| # my global configglobal: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'codelab-monitor'# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files: # - "first.rules" # - "second.rules"# A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.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: linux static_configs: - targets: ['172.30.251.214:9100'] labels: instance: db1 - job_name: mysql static_configs: - targets: ['172.30.251.214:9104'] labels: instance: db1 | 
其中:172.30.251.214是MySQL的IP,端口則是對應(yīng)的exporter的監(jiān)聽端口。
3.啟動Prometheus
| [loya@centos6 prometheus]$ ./prometheusINFO[0000] Starting prometheus (version=1.5.2, branch=master, revision=bd1182d29f462c39544f94cc822830e1c64cf55b) source=main.go:75INFO[0000] Build context (go=go1.7.5, user=root@a8af9200f95d, date=20170210-14:41:22) source=main.go:76INFO[0000] Loading configuration file prometheus.yml source=main.go:248INFO[0000] Loading series map and head chunks... source=storage.go:373INFO[0000] 0 series loaded. source=storage.go:378INFO[0000] Starting target manager... source=targetmanager.go:61INFO[0000] Listening on :9090 source=web.go:259 |