温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何进行Spring Boot 应用可视化监控

发布时间:2021-10-09 15:22:40 来源:亿速云 阅读:115 作者:柒染 栏目:大数据

这期内容当中小编将会给大家带来有关如何进行Spring Boot 应用可视化监控,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

图文简介

如何进行Spring Boot 应用可视化监控

逻辑关系

如何进行Spring Boot 应用可视化监控

效果演示

快速开始

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

如何进行Spring Boot 应用可视化监控

Mappings

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

如何进行Spring Boot 应用可视化监控

指标数据

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 采集状态是否正常。

如何进行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

如何进行Spring Boot 应用可视化监控

配置 DataSource

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

如何进行Spring Boot 应用可视化监控

选择 Graph

如何进行Spring Boot 应用可视化监控

编辑

如何进行Spring Boot 应用可视化监控

配置需要监控的指标

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

如何进行Spring Boot 应用可视化监控

指标

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

如何进行Spring Boot 应用可视化监控

Grafana 监控界面

上述就是小编为大家分享的如何进行Spring Boot 应用可视化监控了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI