增加项目健康监控uptime-kuma

增加项目健康监控

这个增加监控首先分两步,第一步项目增加health健康检查,第二步增加监控配置。

1.项目配置health

我的java项目springboot框架使用spring-boot-starter-actuator包,步骤首先gradle增加配置

// health
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '3.2.2'

bootstrap配置:

management:
  endpoints:
    web:
      exposure:
        include: health
      base-path:                        // 去掉路径中的actuator

然后本地直接访问{{URL}}/health(URL为项目请求地址),会返回

{
    "status": "UP"
}

有以上结果代表项目正常运行中。

2.服务器安装uptime-kuma服务

uptime-kuma是在github上有4.6w个star的项目,这款工具拨测监控配置比较简单直观,以下是安装及配置过程。

docker run -d --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:1

然后阿里云开启3001端口号,然后本地请求ip地址:3001,进入登录注册页面,可以输入你自定义的用户名和密码,做好记录。

着重要注意的是通知,有很多种通知,我这边配的是飞书的

这边WebHook URL是飞书群里面添加机器人才能获取到的,这个添加机器人是只能在电脑端才能添加,手机不能加也是有点不适应。

把以上信息填写好后,点击保存这个任务就开始跑了,他会每分钟请求我设置的url,只有返回200才是正常,否则会发送通知到我设置的飞书群里面,比如下图

同样,这个工具也可以设置监控redis、mysql等数据库,只需要设置下拉监控类型即可

留一个之前配置好的json

[{"SourceGroupId":"","Policy":"Accept","Description":"chimeat-platform后端-test","SourcePortRange":"","Priority":1,"CreateTime":"2024-04-12T08:11:27Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"12002/12002","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf6fonk54qo8mfhwttgw","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"xxl-test","SourcePortRange":"","Priority":1,"CreateTime":"2024-04-12T07:57:48Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"9997/9997","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf602umfrxdlm6ft60oo","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"ssh登录","SourcePortRange":"","Priority":1,"CreateTime":"2024-03-19T09:21:48Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"34/34","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf65r8p87g51jnw6szp9","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"xxl","SourcePortRange":"","Priority":1,"CreateTime":"2024-02-29T08:31:04Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"9998/9998","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf61wwobw7jprsa2482o","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"jenkins","SourcePortRange":"","Priority":1,"CreateTime":"2023-12-27T07:56:02Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"8080/8080","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf65yjdttmbtf7ld5mcd","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"","SourcePortRange":"","Priority":1,"CreateTime":"2023-11-07T07:18:31Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"443/443","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf60axm8ppdhfrwhjuty","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"chimeat-platform后端","SourcePortRange":"","Priority":1,"CreateTime":"2023-09-18T09:59:02Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"12001/12001","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf606ufbr1tsie5ibv1l","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"chimeat-platform前端","SourcePortRange":"","Priority":1,"CreateTime":"2023-09-18T07:40:45Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"80/80","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf6is4ydvgp3gvlo8z8i","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Drop","Description":"System created rule.","SourcePortRange":"","Priority":100,"CreateTime":"2024-03-19T09:27:16Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"22/22","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf6cii54b6k61met5if9","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"System created rule.","SourcePortRange":"","Priority":100,"CreateTime":"2023-09-18T02:41:14Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"3389/3389","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"TCP","SecurityGroupRuleId":"sgr-uf64qus9k3cc3by4amd6","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""},{"SourceGroupId":"","Policy":"Accept","Description":"System created rule.","SourcePortRange":"-1/-1","Priority":100,"CreateTime":"2023-09-18T02:41:14Z","DestPrefixListName":"","Ipv6SourceCidrIp":"","NicType":"intranet","Direction":"ingress","DestGroupId":"","SourceGroupName":"","PortRange":"-1/-1","DestGroupOwnerAccount":"","DestPrefixListId":"","SourceCidrIp":"0.0.0.0/0","SourcePrefixListName":"","IpProtocol":"ICMP","SecurityGroupRuleId":"sgr-uf64qus9k3cc3by4amd7","DestCidrIp":"","DestGroupName":"","Ipv6DestCidrIp":"","SourceGroupOwnerAccount":"","SourcePrefixListId":""}]

 

posted @ 2024-04-02 17:40  蜗牛使劲冲  阅读(163)  评论(0编辑  收藏  举报