prometheus+grafana安裝步驟
-
安裝prometheus
官網下載安裝包https://prometheus.io/download/,下載並解壓prometheus-2.24.0.windows-amd64.zip。默認端口為9090,可進行修改。 -
安裝grafana
官網下載安裝包https://grafana.com/grafana/download,下載后安裝。默認端口是3000,可進行修改。
tomcat監控
- 下載jmx_exporter
https://github.com/prometheus/jmx_exporter 下載jar包:jmx_prometheus_javaagent-0.14.0.jar - 配置tomcat.yaml, 在github上有示例:
https://github.com/prometheus/jmx_exporter/tree/master/example_configs
---
lowercaseOutputLabelNames: true
lowercaseOutputName: true
rules:
- pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'
name: tomcat_$3_total
labels:
port: "$2"
protocol: "$1"
help: Tomcat global $3
type: COUNTER
- pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount):'
name: tomcat_servlet_$3_total
labels:
module: "$1"
servlet: "$2"
help: Tomcat servlet $3 total
type: COUNTER
- pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'
name: tomcat_threadpool_$3
labels:
port: "$2"
protocol: "$1"
help: Tomcat threadpool $3
type: GAUGE
- pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'
name: tomcat_session_$3_total
labels:
context: "$2"
host: "$1"
help: Tomcat session $3 total
type: COUNTER
- 將jmx_prometheus_javaagent-0.14.0.jar和tomcat.yaml拷貝至需要被監控tomcat的bin目錄下。
Java Options中增加參數:
-javaagent:D:\Program Files\Apache Software Foundation\Tomcat 7.0_Tomcat7-SPDPRE/bin/jmx_prometheus_javaagent-0.14.0.jar=30018:D:\Program Files\Apache Software Foundation\Tomcat 7.0_Tomcat7-SPDPRE/bin/tomcat.yaml
重啟tomcat后瀏覽器打開http://ip:33018 可進行驗證。 - 在prometheus根目錄下添加tomcat.yml,文件內容:
- targets:
- 192.168.0.139:30018
labels:
instance: test_tomcat
service: tomcat
- 修改prometheus根目錄下的prometheus.yml文件,添加如下配置:
- job_name: 'java'
file_sd_configs:
- files: [D:\Program Files\prometheus-2.24.0.windows-amd64\tomcat.yml]
refresh_interval: 15s
- 重啟prometheus,進入grafana http://ip:3000
選擇菜單:create->import
輸入8563,點擊load加載,再點擊import完成導入。
接下來就可以進入dashboard查看監控的界面了。
mysql監控
- 下載mysqld_exporter https://github.com/prometheus/mysqld_exporter/releases
(https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0-rc.0/mysqld_exporter-0.13.0-rc.0.windows-amd64.zip) - 在mysqld_exporter.exe同目錄下添加.my.cnf文件,內容:
[client]
host=127.0.0.1 #mysql ip
port=3306
user=root #賬號
password=yourpassword #密碼
- 啟動
cmd進入mysqld_exporter.exe目錄下,運行:
mysqld_exporter.exe --config.my-cnf=.my.cnf - 驗證
在瀏覽器打開:localhost:9104/metrics - 修改prometheus根目錄下的prometheus.yml文件,添加如下配置:
- job_name: 'Mysql'
static_configs:
- targets: ['192.168.0.xxx:9104']
windows監控
- 下載windows_exporter:
https://github.com/prometheus-community/windows_exporter/releases ,下載msi文件,完成安裝后,會自動創建一個開機自啟的服務。 - 驗證
在瀏覽器打開:localhost:9182/metrics - 修改prometheus根目錄下的prometheus.yml文件,添加如下配置:
- job_name: 'Windows'
static_configs:
- targets: ['192.168.0.xxx:9182']
labels:
instance: Windows