https://github.com/prometheus/prometheusnode
Prometheus Server 負責從 Exporter 拉取和存儲監控數據,並提供一套靈活的查詢語言(PromQL)供用戶使用。mysql
Exporter 負責收集目標對象(host, container…)的性能數據,並經過 HTTP 接口供 Prometheus Server 獲取。linux
監控數據的可視化展示對於監控方案相當重要。之前 Prometheus 本身開發了一套工具,不事後來廢棄了,由於開源社區出現了更爲優秀的產品 Grafana。Grafana 可以與 Prometheus 無縫集成,提供完美的數據展現能力。git
用戶能夠定義基於監控數據的告警規則,規則會觸發告警。一旦 Alermanager 收到告警,會經過預約義的方式發出告警通知。支持的方式包括 Email、PagerDuty、Webhook 等.github
target能夠自動發現或手工配置sql
其組件以下,符合功能模塊化. exporter是各類app的採集者.docker
https://prometheus.io/download/json
prometheus alertmanager blackbox_exporter consul_exporter graphite_exporter haproxy_exporter memcached_exporter statsd_exporter mysqld_exporter -本次用來採集mysql的指標 ,收集Mysql數據 node_exporter -本次用來採集node節點的指標,收集系統數據 pushgateway
參考segmentfault
- 下載軟件 https://prometheus.io/download/ mysqld_exporter-0.10.0.linux-amd64.tar.gz node_exporter-0.15.2.linux-amd64.tar.gz prometheus-2.0.0.linux-amd64.tar.gz - 解壓prometheus [root@n1 prometheus-2.0.0.linux-amd64]# ls console_libraries consoles data LICENSE NOTICE prometheus prometheus.yml prometheus.yml.default promtool - 修改prometheus.yml $ cat prometheus.yml global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: linux static_configs: - targets: ['192.168.14.11:9100'] labels: instance: db1 - job_name: mysql static_configs: - targets: ['192.168.14.11:9104'] labels: instance: db1 注: 0,啓動後自帶dashboard,經過http://192.168.14.11:9090來訪問 1.這裏添加2個targets 2.普羅經過配置文件主動去找explore
- 解壓 $ tar xf node_exporter-0.15.2.linux-amd64.tar.gz $ ls LICENSE node_exporter NOTICE - 啓動二進制便可 $ ./node_exporter
- 解壓 $ tar xf mysqld_exporter-0.10.0.linux-amd64.tar.gz $ ls LICENSE mysqld_exporter NOTICE - 啓動mysql docker run -d \ -p 3306:3306 \ -v /data/mysql:/var/lib/mysql \ -v /etc/localtime:/etc/localtime \ --name mysql5 \ --restart=always \ -e MYSQL_ROOT_PASSWORD=123456 \ mysql:5.6.23 --character-set-server=utf8 --collation-server=utf8_general_ci - 啓動mysqld_exporter $ cat > .my.cnf<<EOF [client] user=root password=123456 EOF $ ./mysqld_exporter -config.my-cnf=".my.cnf" 注意: 首先要建立一個.my.conf的配置,默認讀取的是 /root/.my.cnf ,能夠指定路徑
咱們再次回到Status->Targets頁面,能夠看到兩個Target的狀態已經變成UP了:
api
- 下載解壓 wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.3.linux-x64.tar.gz tar -zxvf grafana-4.6.3.linux-x64.tar.gz - 修改配置 392 [dashboards.json] 393 enabled = true 394 path = /var/lib/grafana/dashboards - 下載mysql dashboard mkdir -p /var/lib/grafana/ && cd /var/lib/grafana/ git clone https://github.com/percona/grafana-dashboards.git - dashboard包含了,能夠參考他的github, 具體配置promethues很全,還有效果圖 Amazon RDS OS metrics (CloudWatch datasource) Cross Server Graphs Disk Performance Disk Space MongoDB Cluster Summary MongoDB Overview MongoDB ReplSet MongoDB RocksDB MongoDB WiredTiger MongoDB MMAPv1 MySQL InnoDB Metrics MySQL InnoDB Metrics Advanced MySQL MyISAM/Aria Metrics MySQL Overview MySQL Performance Schema MySQL Query Response Time MySQL Replication MySQL Table Statistics MySQL TokuDB Graphs MySQL User Statistics PXC/Galera Cluster Overview PXC/Galera Graphs Prometheus ProxySQL Overview Summary Dashboard System Overview Trends Dashboard $ tree /var/lib/grafana/ /var/lib/grafana/ └── dashboards ├── Advanced_Data_Exploration.json ├── Amazon_RDS___Aurora_MySQL__Metrics.json ├── Cross_Server_Graphs.json ├── Disk_Performance.json ├── Disk_Space.json ├── MongoDB_Cluster_Summary.json ├── MongoDB_InMemory.json ├── MongoDB_MMAPv1.json ├── MongoDB_Overview.json ├── MongoDB_ReplSet.json ├── MongoDB_RocksDB.json ├── MongoDB_WiredTiger.json ├── MySQL_InnoDB_Metrics_Advanced.json ├── MySQL_InnoDB_Metrics.json ├── MySQL_MyISAM_Aria_Metrics.json ├── MySQL_MyRocks_Metrics.json ├── MySQL_Overview.json ├── MySQL_Performance_Schema.json ├── MySQL_Query_Response_Time.json ├── MySQL_Replication.json ├── MySQL_Table_Statistics.json ├── MySQL_TokuDB_Metrics.json ├── MySQL_User_Statistics.json ├── Prometheus.json ├── ProxySQL_Overview.json ├── PXC_Galera_Cluster_Overview.json ├── PXC_Galera_Graphs.json ├── Summary_Dashboard.json ├── System_Overview.json └── Trends_Dashboard.json - 啓動grafana-server bin/grafana-server
下載dashboard前
下載dashboard後(無需經過dashboard導入了)
注意: 名字必定要是Prometheus,由於你下載別人的dashboard,內置的源就是這個名字
節點
mysql
啓動node_exporter後本質上是暴漏節點app的metric.
啓動了相關的explore便可以經過相關的url訪問到其metric.
- 解壓 $ tar xf node_exporter-0.15.2.linux-amd64.tar.gz $ ls LICENSE node_exporter NOTICE - 啓動二進制便可 $ ./node_exporter
直觀上他們是經過端口來區分的.
本質是對應的二進制是訪問某個app指標api的一個封裝程序包
- 直接啓動 docker run --name prometheus -d -p 9090:9090 quay.io/prometheus/prometheus - 須要預置配置文件 docker run -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \ -v /tmp/prometheus-data:/prometheus-data \ prom/prometheus - 訪問 http://localhost:9090 /訪問。