Prometheus
Prometheus是一個開源監(jiān)控解決方案,用于收集和聚合指標作為時間序列數(shù)據(jù)。更簡單地說,Prometheus 商店中的每個項目都是一個指標事件,并帶有它發(fā)生的時間戳。
mac 搭建Prometheus
地址:https://prometheus.io/
Mac 安裝
brew install prometheus
默認安裝路徑:
/usr/local/Cellar/prometheus
默認配置文件:
/usr/local/etc/prometheus.yml
啟動
prometheus --config.file=/usr/local/etc/prometheus.yml
訪問:http://localhost:9090
Spring boot 結(jié)合
springboot的web項目,pom依賴:
<dependencies>
<!-- web 依賴 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
Yml配置文件:
server:
port: 8080
# 暴露監(jiān)控端點
management:
endpoints:
web:
exposure:
include: '*'
監(jiān)控端點:
http://127.0.0.1:8080/actuator/prometheus
# HELP executor_queued_tasks The Approximate number of tasks that are queued for execution
# TYPE executor_queued_tasks gauge
executor_queued_tasks{name="applicationTaskExecutor",} 0.0
# HELP executor_pool_max_threads The maximum allowed number of threads in the pool
# TYPE executor_pool_max_threads gauge
executor_pool_max_threads{name="applicationTaskExecutor",} 2.147483647E9
# HELP jvm_gc_pause_seconds Time spent in GC pause
# TYPE jvm_gc_pause_seconds summary
jvm_gc_pause_seconds_count{action="end of major GC",cause="Metadata GC Threshold",} 1.0
jvm_gc_pause_seconds_sum{action="end of major GC",cause="Metadata GC Threshold",} 0.072
jvm_gc_pause_seconds_count{action="end of minor GC",cause="Metadata GC Threshold",} 1.0
jvm_gc_pause_seconds_sum{action="end of minor GC",cause="Metadata GC Threshold",} 0.014
# HELP jvm_gc_pause_seconds_max Time spent in GC pause
# TYPE jvm_gc_pause_seconds_max gauge
jvm_gc_pause_seconds_max{action="end of major GC",cause="Metadata GC Threshold",} 0.0
jvm_gc_pause_seconds_max{action="end of minor GC",cause="Metadata GC Threshold",} 0.0
# HELP jvm_classes_loaded_classes The number of classes that are currently loaded in the JAVA virtual machine
# TYPE jvm_classes_loaded_classes gauge
jvm_classes_loaded_classes 7566.0
# HELP jvm_gc_memory_promoted_bytes_total Count of positive increases in the size of the old generation memory pool before GC to after GC
# TYPE jvm_gc_memory_promoted_bytes_total counter
jvm_gc_memory_promoted_bytes_total 3235200.0
# HELP Tomcat_sessions_active_current_sessions
# TYPE tomcat_sessions_active_current_sessions gauge
tomcat_sessions_active_current_sessions 0.0
# HELP executor_pool_size_threads The current number of threads in the pool
配置 prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
# 創(chuàng)建job
- job_name: "tomato-study-prometheus"
scrape_interval: 5s
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ["localhost:8080"]
重啟 prometheus:
http://localhost:9090/targets
安裝 grafana
展示各種漂亮的圖表。
Mac 安裝
brew install grafana
默認安裝路徑:
/usr/local/Cellar/grafana/
啟動:
grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana --packaging=brew cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins
注:如需修改默認端口,可修改
/usr/local/etc/grafana/grafana.ini
訪問:http://localhost:3000/ admin/admin
使用前必須更改密碼 admin/123qwe
配置 grafana
grafana只是一個圖表展示工具,必須添加數(shù)據(jù)源,才能讀取到數(shù)據(jù)。
配置 Grafana DashBoard文件
推薦的 Grafana DashBoard:
JVM (Micrometer)-(https://grafana.com/grafana/dashboards/4701)
Spring Boot 2.1 Statistics -(https://grafana.com/grafana/dashboards/10280)
Node Exporter - (https://grafana.com/grafana/dashboards/8919)
Druid - https://grafana.com/grafana/dashboards/11157
主機基礎(chǔ)監(jiān)控-(
https://grafana.com/grafana/dashboards/9276)
最終展示效果: