图文简介

快速开始

1、Spring Boot 应用暴露监控指标【版本 1.5.7.RELEASE】

首先,添加依赖如下依赖:

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> <dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.0.26</version>
</dependency>

然后,在启动类 Application.java 添加如下注解:

@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
} }

最后,配置默认的登录账号和密码,在 application.yml 中:

security:
user:
name: user
password: pwd

提示:不建议配置 management.security.enabled: false

启动应用程序后,会看到如下一系列的 Mappings

利用账号密码访问 http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指标数据

2、Prometheus 采集 Spring Boot 指标数据

首先,获取 Prometheus 的 Docker 镜像:

$ docker pull prom/prometheus

然后,编写配置文件 prometheus.yml

global:
scrape_interval: 10s
scrape_timeout: 10s
evaluation_interval: 10m
scrape_configs:
- job_name: spring-boot
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /application/prometheus
scheme: http
basic_auth:
username: user
password: pwd
static_configs:
- targets:
- 127.0.0.1:8080 #此处填写 Spring Boot 应用的 IP + 端口号

接着,启动 Prometheus :

$ docker run -d \
--name prometheus \
-p 9090:9090 \
-m 500M \
-v "$(pwd)/prometheus.yml":/prometheus.yml \
-v "$(pwd)/data":/data \
prom/prometheus \
-config.file=/prometheus.yml \
-log.level=info

最后,访问 http://localhost:9090/targets , 检查 Spring Boot 采集状态是否正常。

3、Grafana 可视化监控数据

首先,获取 Grafana 的 Docker 镜像:

$ docker pull grafana/grafana

然后,启动 Grafana:

$ docker run --name grafana -d -p 3000:3000 grafana/grafana

接着,访问 http://localhost:3000/ 配置 Prometheus 数据源:

Grafana 登录账号 admin 密码 admin

最后,配置单个指标的可视化监控面板:

提示,此处不能任意填写,只能填已有的指标点,具体的可以在 Prometheus 的首页看到,即 http://localhost:9090/graph

多配置几个指标之后,即可有如下效果:

参考文档

文末福利

Java 资料大全 链接:https://pan.baidu.com/s/1pUCCPstPnlGDCljtBVUsXQ 密码:b2xc

更多资料: 2020 年 精选阿里 Java、架构、微服务精选资料等,加 v ❤ :qwerdd111

转载,请保留原文地址,谢谢 ~

最新文章

  1. 前端进阶试题(css部分)
  2. Manage Metadata Service Error: There are no addresses available for this application
  3. (转) Java读取文本文件中文乱码问题
  4. Kubernetes Architecture
  5. 【译】 AWK教程指南 附录E-正则表达式
  6. 消息队列(Message Queue)基本概念(转)
  7. 连连看的原生JS实现V2
  8. 使用Linux环境变量
  9. 数据库(Mongodb)
  10. js浮点数的加减乘除
  11. Centos7 利用crontab定时执行任务及配置方法
  12. 以编程方式使用 Microsoft Office Visio 2003 ActiveX 控件
  13. 修改Linux服务器的ttl值
  14. GNum试用体验
  15. Hive 数仓中常见的日期转换操作
  16. Sublime Text 3(中文)添加Lua编译环境
  17. 关于界面绘制过程多次回调ondraw()方法产生的问题
  18. 【2018暑假集训模拟一】Day2题解
  19. [转]使用RTT(Real-Time Terminal)
  20. Windows XP忘记密码的几种解决方法

热门文章

  1. 字符串常用方法总结与StringBuffer基础
  2. Nmap_使用介绍
  3. 1)BS和CS区别
  4. 【更新中】Hotspot tracer
  5. 吴裕雄--天生自然 HADOOP大数据分布式处理:安装配置JAVA
  6. 复习break、continue、while、do-while的运用
  7. Qt QThread必须要了解的几个函数
  8. VisionPro连接Dalsa线扫相机
  9. STL中map的使用
  10. python的collections模块和functools模块