1、 Prometheus 是一個開源的服務監控系統和時間序列數據庫。:node
官方GitHub地址爲:https://github.com/prometheus/prometheus mysql
官方地址:https://prometheus.io/linux
官方拓撲圖以下git
特性:github
高維度數據模型web
自定義查詢語言sql
可視化數據展現數據庫
高效的存儲策略json
易於運維centos
提供各類客戶端開發庫
警告和報警
數據導出
2、安裝Prometheus(服務器環境爲Centos7.2,本實驗服務端跟被監控MySQL在同一臺服務器)
前提條件請關閉SELinux與Firewalld(centos6 爲iptables)
下載安裝prometheus $ wget https://github.com/prometheus/prometheus/releases/download/v1.7.1/prometheus-1.7.1.linux-amd64.tar.gz $ mkdir /opt/prometheus $ tar zxf prometheus-1.7.1.linux-amd64.tar.gz -C /opt/prometheus --strip-components=1 編輯配置prometheus.yml文件,內容以下: global: scrape_interval: 15s evaluation_interval: 15s external_labels: monitor: 'codelab-monitor' rule_files: scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['192.168.1.199:9090'] - job_name: linux static_configs: - targets: ['192.168.1.199:9100'] labels: instance: db1 - job_name: mysql static_configs: - targets: ['192.168.1.199:9104'] labels: instance: db1 後臺啓動prometheus nohup /opt/prometheus/prometheus -config.file=prometheus.yml & tail -200f nohup.out time="2017-06-12T11:51:16+08:00" level=info msg="Starting prometheus (version=1.7.0, branch=master, revision=bfa37c8ee39d11078662dce16c162a61dccf616c)" source="main.go:88" time="2017-06-12T11:51:16+08:00" level=info msg="Build context (go=go1.8.3, user=root@7a6329cc02bb, date=20170607-09:43:48)" source="main.go:89" time="2017-06-12T11:51:16+08:00" level=info msg="Host details (Linux 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 monitor (none))" source="main.go:90" time="2017-06-12T11:51:16+08:00" level=info msg="Loading configuration file prometheus.yml" source="main.go:252" time="2017-06-12T11:51:16+08:00" level=info msg="Loading series map and head chunks..." source="storage.go:428" time="2017-06-12T11:51:16+08:00" level=info msg="2200 series loaded." source="storage.go:439" time="2017-06-12T11:51:16+08:00" level=info msg=" source="web.go:259"
Prometheus提供一個內置的web界面。咱們能夠經過http://192.168.1。199:9090訪問
在 Status
-> Targets
頁面下,咱們能夠看到咱們配置的兩個Target,它們的 State
3、接下來咱們安裝client客戶端
一、安裝client $ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz $ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz $ mkdir /opt/prometheus_exporters $ tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1 && tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /opt/prometheus_exporters --strip-components=1 二、啓動os監控client nohup /opt/prometheus_exporters/node_exporter & tail -200f nohup.out time="2017-06-12T11:28:52+08:00" level=info msg=" - hwmon" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info msg=" - netstat" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info msg=" - stat" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info msg=" - vmstat" source="node_exporter.go:162" time="2017-06-12T11:28:52+08:00" level=info source="node_exporter.go:186" 三、mysqld_exporter須要鏈接到MySQL,須要受權 mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'monitor'@'localhost' identified by 'test123'; mysql> GRANT SELECT ON performance_schema.* TO 'monitor'@'localhost'; 四、建立 .my.cnf 文件並運行mysqld_exporter [root@monitor prometheus_exporters]# cat .my.cnf [client] user=monitor password=test123 [root@monitor prometheus_exporters]# export DATA_SOURCE_NAME="monitor:test123@(monitor:3306)/" #####(monitor:3306)/此monitor爲主機名 啓動mysqld_exporter nohup /opt/prometheus_exporters/mysqld_exporter -config.my-cnf=".my.cnf" & tail -200f nohup.out time="2017-06-12T11:30:07+08:00" level=info msg="Starting mysqld_exporter (version=0.10.0, branch=master, revision=80680068f15474f87847c8ee8f18a2939a26196a)" source="mysqld_exporter.go:460" time="2017-06-12T11:30:07+08:00" level=info msg="Build context (go=go1.8.1, user=root@3b0154cd9e8e, date=20170425-11:24:12)" source="mysqld_exporter.go:461" time="2017-06-12T11:30:08+08:00" level=info msg=" source="mysqld_exporter.go:479"
咱們回到192.168.1.199:9090,能夠看到
Status
-> Targets
頁面
4、安裝和運行Grafana
一、安裝Grafana #wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.2-1.x86_64.rpm #yum localinstall grafana-4.3.2-1.x86_64.rpm 替換grafana的dashboards Grafana 並無太多的配置好的圖表模板,除了 Percona 開源的一些外,不少須要自行配置。 下載dashboards(https://github.com/percona/grafana-dashboards) git clone https://github.com/percona/grafana-dashboards.git cp -r grafana-dashboards/dashboards /var/lib/grafana/ 二、編輯配置文件 /etc/grafana/grafana.ini ,修改 dashboards.json 段落下兩個參數的值: [dashboards.json] enabled = true path = /var/lib/grafana/dashboards 二、運行 Grafana systemctl start grafana-server # [root@monitor prometheus_exporters]# ps aux |grep grafana root 3211 0.0 0.0 112664 972 pts/1 S+ 11:40 0:00 grep --color=auto grafana grafana 21241 0.3 0.8 805720 39620 ? Ssl 6月12 4:42 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile= cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins
咱們可經過 http://192.168.1.199:3000 訪問Grafana網頁界面(缺省的賬號/密碼爲admin/admin):
登陸並設置數據源
至此大功告成
咱們能夠看到os與數據庫監控數據了