当前位置: 移动技术网 > IT编程>开发语言>Java > 拒绝黑盒应用-Spring Boot 应用可视化监控

拒绝黑盒应用-Spring Boot 应用可视化监控

2019年10月31日  | 移动技术网IT编程  | 我要评论

img

图文简介

img

逻辑关系

img

效果演示

快速开始

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

img

mappings

利用账号密码访问 ,可以看到 prometheus 格式的指标数据

img

指标数据

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

最后,访问 , 检查 spring boot 采集状态是否正常。

img

采集状态

3、grafana 可视化监控数据

首先,获取 grafana 的 docker 镜像:

$ docker pull grafana/grafana

然后,启动 grafana:

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

接着,访问 配置 prometheus 数据源:

grafana 登录账号 admin 密码 admin

img

配置 datasource

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

img

选择 graph

img

编辑

img

配置需要监控的指标

提示,此处不能任意填写,只能填已有的指标点,具体的可以在 prometheus 的首页看到,即

img

指标

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

img

grafana 监控界面

参考文档

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

原文链接:
https://mp.weixin.qq.com/s?__biz=mzu0mdewmjgwna==&mid=2247486173&idx=1&sn=571a068a4d49cf7c054ebde623c67d17&chksm=fb3f1326cc489a30cef820c1be230a351b0ef0501f86f2a9c8dbf19bc694f9e5a32a40173194&token=423629656&lang=zh_cn#rd

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网