- 修改 application-local.properties 配置文件,主要是数据库;或者自己指定配置文件
- 地址:http://{ip:localhost}t:{port:8080}/sbp/v1/actuator/prometheus
- 查看指标: http://{ip:localhost}t:{port:8080}/sbp/v1/actuator/metrics
- Maven
<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Micormeter core dependecy -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
- Config
# 根据自己需求去查配置修改
management.endpoints.web.exposure.include=metrics,prometheus
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
- prometheus是由谷歌研发的一款开源的监控软件,目前CNCF孵化中,是继k8s托管的第二个项目,在云原生的开发中是使用最常见的监控系统,事实上的下一代监控系统
- 管理方便,部署灵活
- 易集成,主流语言SDK可以轻松实现对Java Go Python等主流语言的程序监控
- 存储灵活
- 高效灵活的查询语句,满足个性化的数据需求
- Exporter丰富能覆盖大部分主流的Server和中间件(DB Cache 等)
- 高可用,扩展性高
- 覆盖了监控报警和展示等功能
- Demo 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: 'spring'
metrics_path: '/sbp/v1/actuator/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['192.168.87.208:8080']
docker pull prom/prometheus
docker run -d \
-p 19090:9090 \
-v /tools/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
启动后访问:http://localhost:19090/graph 就可以看到指标
docker pull google/cadvisor
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=28080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
在prometheus.yml文件中追加
- job_name: cadvisor
static_configs:
- targets:
- IP:{port:8080}
- Node: https://github.com/prometheus/node_exporter
- Mysql: https://github.com/prometheus/mysqld_exporter
- Redis: https://github.com/oliver006/redis_exporter Other: Github上查找
- 命令:mvn clean test org.jacoco:jacoco-maven-plugin:0.8.3:prepare-agent
- H2数据库和mysql等有些创建表语法不一致,可使用 Test包中的Transform 工具转换表语句