图文简介

逻辑关系

效果演示

快速开始

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

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

配置 DataSource

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

选择 Graph

编辑

配置需要监控的指标

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

指标

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

Grafana 监控界面

参考文档

© 著作权归作者所有,转载或内容合作请联系作者

原文链接:

https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=2247486173&idx=1&sn=571a068a4d49cf7c054ebde623c67d17&chksm=fb3f1326cc489a30cef820c1be230a351b0ef0501f86f2a9c8dbf19bc694f9e5a32a40173194&token=423629656&lang=zh_CN#rd

本文由博客一文多发平台 OpenWrite 发布!

拒绝黑盒应用-Spring Boot 应用可视化监控的更多相关文章

  1. 微服务监控之三:Prometheus + Grafana Spring Boot 应用可视化监控

    一.Springboot增加Prometheus 1.Spring Boot 应用暴露监控指标,添加如下依赖 <dependency> <groupId>org.springf ...

  2. (转)Spring Boot(二十):使用 spring-boot-admin 对 Spring Boot 服务进行监控

    http://www.ityouknow.com/springboot/2018/02/11/spring-boot-admin.html 上一篇文章<Spring Boot(十九):使用 Sp ...

  3. Spring Boot Admin2.X监控的服务context-path问题

    在使用Spring Boot Admin进行监控时,如果被监控的服务没有加context-path的话是不会有任何问题的,一旦服务加了context-path的配置,监控就会失败. 下图是正常情况的显 ...

  4. Spring Boot 2.x监控数据可视化(Actuator + Prometheus + Grafana手把手)

    TIPS 本文基于Spring Boot 2.1.4,理论支持Spring Boot 2.x所有版本 众所周知,Spring Boot有个子项目Spring Boot Actuator,它为应用提供了 ...

  5. Spring Cloud第十三篇 | Spring Boot Admin服务监控

    本文是Spring Cloud专栏的第十三篇文章,了解前十二篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...

  6. spring boot/cloud 应用监控

    应用的监控功能,对于分布式系统非常重要.如果把分布式系统比作整个社会系统.那么各个服务对应社会中具体服务机构,比如银行.学校.超市等,那么监控就类似于警察局和医院,所以其重要性显而易见.这里说的,监控 ...

  7. spring Boot 学习(八、Spring Boot与与监控管理)

    一.监控管理通过引入spring-boot-starter-actuator,可以使用Spring Boot为我们提供的准 生产环境下的应用监控和管理功能.我们可以通过HTTP,JMX,SSH协议来进 ...

  8. Spring Boot配置druid监控页功能

    1.导入坐标 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http ...

  9. 基于spring boot admin 做监控的一些问题记录

    问题一 各个健康节点权限问题 解决方式 加入权限模块 <dependency> <groupId>org.springframework.boot</groupId> ...

随机推荐

  1. Java面试-interrupt

    我们都知道,Java中停止一个线程不能用stop,因为stop会瞬间强行停止一个线程,且该线程持有的锁并不能释放.大家多习惯于用interrupt,那么使用它又有什么需要注意的呢? interrupt ...

  2. sql server 使用 partition by 分区函数 解决不连续数字查询问题

    sql server表中的某一列数据为不一定连续的数字,但是需求上要求按照连续数字来分段显示,如:1,2,3,4,5,6,10,11,12,13, 会要求这样显示:1~6,10~13.下面介绍如何实现 ...

  3. django查询表记录的十三种方法

    django查询表记录的十三种方法 all() 结果为queryset类型 >>> models.Book.objects.all() <QuerySet [<Book: ...

  4. 由"跨域"引出的一个终极思想(jsonp)

    1.什么是跨域? 当协议.子域名.主域名.端口号中任意一个不相同时,都算作不同域. 跨域并不是请求发不出去,请求能发出去,服务端能收到请求并正常返回结果,但是因为浏览器存在一个"同源策略&q ...

  5. Redis连接池-Java代码

    1.JedisUtil类 2.测试类 3.测试日志(模拟出现竞争情况) import org.apache.log4j.Logger; import redis.clients.jedis.Jedis ...

  6. Angular 页面初始化动画

    用于进入组件前的加载动画 第一步:index.html 定义动画模板和样式 // 样式 <style type="text/css">.preloader { posi ...

  7. WebGL简易教程(五):图形变换(模型、视图、投影变换)

    [toc] 1. 概述 通过之前的教程,对WebGL中可编程渲染管线的流程有了一定的认识.但是只有前面的知识还不足以绘制真正的三维场景,可以发现之前我们绘制的点.三角形的坐标都是[-1,1]之间,Z值 ...

  8. MongoDB入门系列之科普篇

    ​ 目录 背景 对比 MongoDB的数据存储格式 背景 最近公司扩展了很多国外客户,那么一个很严重的问题就是翻译,对于国外客户来说,肯定看不懂中文,那就要项目中提供切换各自国家语言的功能. 由于每个 ...

  9. 正睿OI国庆DAY2:图论专题

    正睿OI国庆DAY2:图论专题 dfs/例题 判断无向图之间是否存在至少三条点不相交的简单路径 一个想法是最大流(后来说可以做,但是是多项式时间做法 旁边GavinZheng神仙在谈最小生成树 陈主力 ...

  10. wordpress安装主题、插件需要FTP用户名密码

    修改主目录wordpress下的wp-config.php文件,在最结尾加上 define("FS_METHOD", "direct"); define(&qu ...