spring boot security ajax_Spring-Boot-应用可视化监控

图文简介

v2-1c4b586268e61816acbd9738f76d56da_b.jpg

v2-1f11856734f68840c0a54417b9722bca_b.jpg

快速开始

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

v2-5befd74156152162c40125d5cc226a7e_b.jpg

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

v2-682b42654a068d040b12fb8469dd85a9_b.jpg

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

v2-5c408a2b6dc9b790cd6a4eca2678be44_b.jpg

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

v2-7f27488b7ad956a730137533931957a2_b.jpg

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

v2-a2836a50292a48ddec8c140d29aca000_b.jpg

v2-0248639491938e1af02cbade57e3eb21_b.jpg

v2-cfa4a0b8cd6f163b754220b45d2087d3_b.jpg

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

v2-4905a4cab65b88845380e1c896c4f6d8_b.jpg

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

v2-8a7703a4bb8910efd3ad03ce6b58bcea_b.jpg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值