Spring Boot 2.1X+Prometheus +Grafana实现监控及可视化
看了网上存在的普遍的版本,却在整合过程中出现了prometheus监控不到项目数据的情况。然后决定写此版本。
Prometheus
官方文档:https://prometheus.io/docs/introduction/overview/
下载并运行Prometheus
官方下载最新的Prometheus,下载地址:https://prometheus.io/download/
这里以linux 2.13.1版本为例,下载解压:
tar xvfz prometheus-2.13.1.linux-amd64.tar.gz
cd prometheus-2.13.1.linux-amd64
配置Prometheus
Prometheus配置保存为名为的文件prometheus.yml:
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# 默认监视其自身的健康状况
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
# 需要监控的项目
#项目名
- job_name: 'xxx'
metrics_path: '/prometheus'
#需监控项目地址
static_configs:
- targets: ['localhost:8080']
启动Prometheus