基於Grafana+Prometheus 實現Windows服務器,MySQL數據庫監控
目前市面上的主流是以Liunx系統服務器為主,但是仍存在使用windows系統服務器的企業,下面的內容將介紹如何基於Grafana+Prometheus 實現windows服務器,數據庫監控。
一、簡介
- Grafana: 是一個開源的時序性統計和監控平台,支持例如 elasticsearch、graphite、influxdb 等眾多的數據源,並以功能強大的界面編輯器著稱
- Prometheus:最初在SoundCloud上構建的開源系統監視和警報工具包,擁有一個完整的監控和趨勢系統,包括基於時間序列數據的內置和主動抓取,存儲,查詢,繪圖和警報。
二、下載安裝
1、Windows系統性能指標采集器
#下載地址:https://github.com/martinlindhe/wmi_exporter/releases #選擇最新msi文件下載安裝即可。通過訪問http://ip+默認端口9182(如:http://localhost:9182) 出現下圖,即代表安裝采集數據成功。
2、Mysql數據指標采集器
#下載地址:https://prometheus.io/download/ #找到mysqld_exporter采集器,選擇windows 版本即可 (如:mysqld_exporter-0.11.0.windows-amd64.tar.gz)
,在mysqld_exporter.exe的同級目錄下創建.my.cnf 並啟動
.my.cnf中內容:
[client] host=127.0.0.1 #mysql ip user=root #賬號 password=123456 #密碼
3、Prometheus
#下載地址:https://prometheus.io/download/ #選擇windows 版本即可
a.下載解壓后,修改配置文件,修改新增mysql、windows數據采集器配置:
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'windows' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9182'] - job_name: 'mysql' static_configs: - targets: ['localhost:3306']
b、啟動,cmd進入安裝目錄(& – -> 后台運行)
prometheus.exe --config.file=prometheus.yml --web.listen-address=:9090 &
c、訪問 http://ip:9090 ,(如:http://localhost:9090)出現如下界面即為prometheus安裝成功、數據采集器驗證成功 (PS: up為成功,down 為不成功。)
3、Grafana
#下載地址:https://grafana.com/grafana/download #選擇windows 版本即可
解壓完成,進入bin目錄啟動grafana-server.exe 打開瀏覽器訪問 http://ip:3000,(如:http://localhost:3000) 用戶名/密碼 admin/admin
三、性能數據展示
1、配置數據源
Configuration -- Add data source --- Prometheus , 輸入名稱,prometheus的訪問url ,點擊保存測試,驗證是否成功
2、選擇監控儀表盤模板導入。
訪問地址:https://grafana.com/dashboards --- serch框輸入windows ---- 選擇心儀模板 (注意模板所支持的數據源為prometheus) ----- 進行 ID 或者JOSN文件兩種方式導入。
3、展示數據
模板導入成功即可看到監控數據
PS : MySQL性能數據展示步驟一致。