SpringBoot项目监控JVM教程

1 篇文章 0 订阅

前期准备

采用Springboot2.x版本以及grafana和prometheus实现动态监控

操作步骤

1,springboot工程新增依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>

2,新增配置文件

info:
  alen: alen
management:
  endpoints:
    web:
      exposure:
        include: "*"
      base-path: /actuator
  server:
    port: 8000

注: management.server.port为actuator服务端监控端口,可根据具体情况修改

3,启动应用

启动后访问:localhost:8000/actuator/prometheus
如出现以下界面则表示配置成功:
在这里插入图片描述

4,安装prometheus

1,下载:prometheus下载地址

在这里插入图片描述

2,上传到服务器上 /application/prometheus-2.43.0.linux-amd64.tar.gz

3, 解压缩:

1,[www@VM-4-8-centos ~]# cd /application
2,[www@VM-4-8-centos application]# tar -xvf prometheus-2.43.0.linux-amd64.tar.gz
3,[www@VM-4-8-centos application]# mv prometheus-2.43.0.linux-amd64 prometheus

4,修改配置文件 prometheus/prometheus.yml

原prometheus.yml内容如下:
在这里插入图片描述
注:默认已经有一个prometheus本身的任务,切默认端口为9090
新增一个job_name即刚才启动的actuator,如下
在这里插入图片描述

  - job_name: "test_actuator"

    metrics_path:  '/actuator/prometheus'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:8000"]

4, 启动

新增完成后启动prometheus:

[www@VM-4-8-centos application]# prometheus/prometheus --config.file="/application/prometheus/prometheus.yml" &

启动后访问:localhost:9090 如出现以下界面说明配置成功:
在这里插入图片描述

5,安装grafana

1,下载:grafana下载

根据自己系统选择对应包;我选的是以下:
在这里插入图片描述

2,启动grafana

[www@VM-4-8-centos application]# systemctl start grafana-server
[www@VM-4-8-centos application]# systemctl enable grafana-server #设置开机启动
[www@VM-4-8-centos application]# netstat -lntp|grep grafana    # 可看出grafana的端口默认是3000

浏览器输入:localhost:3000进入grafana登录页面 默认用户名/密码: admin/admin
注:首次登陆必须修改密码

修改密码后进入主页面:
在这里插入图片描述

3,添加prometheus数据源

1,在configuration->data Sources中选择添加数据源

在这里插入图片描述

2,配置promethus路径

在这里插入图片描述

3,点击save+test出现以下提示说明配置成功

在这里插入图片描述

4,导入配置好的仪表盘

1,点击Dashboards–>Import

在这里插入图片描述

2,grafanaId配置4701

在这里插入图片描述

3,找到刚才配置好的Prometheus监控仪

在这里插入图片描述

5,以下为JVM监控页面,特别详细

在这里插入图片描述

6,远程监控

在被监控的机器上安装node_exporter组件

1,下载node_exporter
# 解压安装包
tar -xf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt

# 创建链接目录
cd /opt
ln -s node_exporter-1.0.1.linux-amd64 node_exporter

# 使用nohup后台运行
nohup /opt/node_exporter/node_exporter &

# 确认是否正常启动(默认端口9100[root@mysql01 ~]# netstat -lnptu | grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN      20716/node_exporter 

扩展: nohup命令: 如果把启动node_exporter的终端给关闭,那么进程也会
随之关闭。nohup命令会帮你解决这个问题

同样操作,将所有需要被监控主机安装node_exporter组件

2,通过浏览器访问http://被监控端IP:9100/metrics就可以查看到node_exporter在被监控端收集的监控信息

在这里插入图片描述

3,回到prometheus服务器的配置文件里添加被监控机器的配置段
  - job_name: "test_actuator"

    metrics_path:  '/actuator/prometheus'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:8000"]
    #新增远程主机
 - job_name: "remote-host"

    metrics_path:  '/actuator/prometheus'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["remoteIP:9100"]
4,添加完成重启prometheus
[www@VM-4-8-centos application]# prometheus/prometheus --config.file="/application/prometheus/prometheus.yml" &

回到prometheus界面,出现刚才到配置说明设置成功
在这里插入图片描述
大功告成,这样就可以监控多台机器的jvm了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值