对java工程实时监控方式很多,本文主要讲在springboot框架中的监控。

springboot框架,自带了actuator监控,在pom中引入jar包即可,如下

1.引入jar

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

在2.0版本之后改动很大,我这里是用的2.0.2

2.启动项目后即可访问

http://localhost:8081/webproject/actuator/health

http://localhost:8081/webproject/actuator/info

如果想让url个性化一点,在 application.propertie

配置文件中 加入

management.endpoints.web.base-path=/jiankong

那么就可以访问

http://localhost:8081/webproject/jiankong/health

3.actuator 提供了很多api(称为:节点)

默认只开放了 health、info两个节点

如果需要公开所有 则在配置文件中继续加入

management.endpoints.web.exposure.include=*

其中 health方法 是不显示具体的内容的,如需要

则继续加入配置

management.endpoint.health.show-details=always

具体方法和返回内容 可以参考API

GET /autoconfig 查看自动配置的使用情况 true 

GET /configprops 查看配置属性,包括默认配置 true 

GET /beans 查看bean及其关系列表 true 

GET /dump 打印线程栈 true 

GET /env 查看所有环境变量 true 

GET /env/{name} 查看具体变量值 true 

GET /health 查看应用健康指标 false 

GET /info 查看应用信息 false 

GET /mappings 查看所有url映射 true 

GET /metrics 查看应用基本指标 true 

GET /metrics/{name} 查看具体指标 true 

POST /shutdown 关闭应用 true 

GET /trace 查看基本追踪信息 true

4. 常用的查看具体指标的方法  /metrics/{name}

http://localhost:8081/webproject/actuator/metrics/http.server.requests

http://localhost:8081/webproject/actuator/metrics/jvm.memory.used

http://localhost:8081/webproject/actuator/metrics/jvm.threads.peak

等等,具体name 可以通过/metrics 获得,

其中 http.server.requests 是对所有请求的url的监控,次数,时间 等。

那么如果我们需要针对个别重点controller分别监控呢~~

5.分别监控,需要在controller上做些手脚

在RequestMapping 上面 加上注解 @Timed(value = "list.base", longTask = true)

value可以就用mapping 这样。

这个@Timed 注解 是 micrometer-core-1.0.3-sources.jar的 springboot监控本身用到的。

当访问过这个controller之后 就可以调用~ 注意还没有收到过请求的话是请求不到这个list.base的

http://localhost:8081/webproject/actuator/metrics/list.base

{

    "availableTags":[

        {

            "tag":"exception",

            "values":["None"]

        },

        {

            "tag":"method",

            "values":["POST"]

        },

        {

            "tag":"uri",

            "values":["/ListDataBase","root"]

        },

        {

            "tag":"status",

            "values":["200"]

        }

    ],

    "measurements":[

        {

            "statistic":"ACTIVE_TASKS",

            "value":0

        },

        {

            "statistic":"DURATION",

            "value":0

        },

        {

            "statistic":"COUNT",

            "value":1

        },

        {

            "statistic":"TOTAL_TIME",

            "value":0.306317164

        },

        {

            "statistic":"MAX",

            "value":0.306317164

        }

    ],

    "name":"list.base"

}

如果有兴趣研究更多。。。官网api

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-endpoints

springboot 实时监控 spring-boot-starter-actuator 包的更多相关文章

  1. SpringBoot 之Spring Boot Starter依赖包及作用

    Spring Boot 之Spring Boot Starter依赖包及作用 spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. spri ...

  2. SpringBoot 之Spring Boot Starter依赖包及作用(自己还没有看)

    spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. spring-boot-starter-amqp 通过spring-rabbit来支持 ...

  3. Spring Boot (九): 微服务应用监控 Spring Boot Actuator 详解

    1. 引言 在当前的微服务架构方式下,我们会有很多的服务部署在不同的机器上,相互是通过服务调用的方式进行交互,一个完整的业务流程中间会经过很多个微服务的处理和传递,那么,如何能知道每个服务的健康状况就 ...

  4. Spring Boot整合actuator实现监控管理

    Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...

  5. Spring boot 打成jar包问题总结

    Spring boot 打成jar包问题总结 1.Unable to find a single main class from the following candidates 1.1.问题描述 m ...

  6. Spring Boot (28) actuator与spring-boot-admin

    在上一篇中,通过restful api的方式查看信息过于繁琐,也不直观,效率低下.当服务过多的时候看起来就过于麻烦,每个服务都需要调用不同的接口来查看监控信息. SBA SBA全称spring boo ...

  7. Spring Boot (十): Spring Boot Admin 监控 Spring Boot 应用

    Spring Boot (十): Spring Boot Admin 监控 Spring Boot 应用 1. 引言 在上一篇文章<Spring Boot (九): 微服务应用监控 Spring ...

  8. 年轻人的第一个自定义 Spring Boot Starter!

    陆陆续续,零零散散,栈长已经写了几十篇 Spring Boot 系列文章了,其中有介绍到 Spring Boot Starters 启动器,使用的.介绍的都是第三方的 Starters ,那如何开发一 ...

  9. 从零开始开发一个Spring Boot Starter

    一.Spring Boot Starter简介 Starter是Spring Boot中的一个非常重要的概念,Starter相当于模块,它能将模块所需的依赖整合起来并对模块内的Bean根据环境( 条件 ...

  10. 一个简单易上手的短信服务Spring Boot Starter

    前言 短信服务在用户注册.登录.找回密码等相关操作中,可以让用户使用更加便捷,越来越多的公司都采用短信验证的方式让用户进行操作,从而提高用户的实用性. Spring Boot Starter 由于 S ...

随机推荐

  1. mysql union 组合查询

    mysql> select * from test -> ; +----+------------+-------+-----------+ | id | name | score | s ...

  2. mysql 通配符%以及_

    %匹配任意长度 _ 匹配单个字符 mysql> select * from table1; +----------+------------+-----+-------------------- ...

  3. 程序日志-应用程序-特定 权限设置并未向在应用程序容器 不可用 SID (不可用)中运行的地址 LocalHost (使用 LRPC) 中的用户 NT AUTHORITY\SYSTEM SID (S-1-5-18)授予针对 CLSID 为 {D63B10C5-BB46-4990-A94F-E40B9D520

    应用程序-特定 权限设置并未向在应用程序容器 不可用 SID (不可用)中运行的地址 LocalHost (使用 LRPC) 中的用户 NT AUTHORITY\SYSTEM SID (S-1-5-1 ...

  4. OpenFOAM——具有压差的平行平板间流动(泊肃叶流动)

    本算例翻译整理自:http://the-foam-house5.webnode.es/products/chapter-1-plane-parallel-plates-case/ 这个算例中两平板间没 ...

  5. (二)Cisco dhcp snooping配置解释

    #配置dhcp snooping相关命令 Switch(config)#ip dhcp snooping  //打开DHCP Snooping功能Switch(config)#ip dhcp snoo ...

  6. 【CS224n】Lecture8 Notes

    注:这是2017年课程的lecture8.一直都在用RNN,但是对它内部的构造不甚了解,所以这次花了一个下午加一个晚上看了CS224n中关于RNN的推导,不敢说融会贯通,算是比以前清楚多了.做个笔记, ...

  7. __gcd-最大公约数

    __gcd-最大公约数 最大公约数(greatest common divisor,简写为gcd:或highest common factor,简写为hcf) __gcd(x,y)是algorithm ...

  8. (二)OpenCV-Python学习—对比度增强

    ·对于部分图像,会出现整体较暗或较亮的情况,这是由于图片的灰度值范围较小,即对比度低.实际应用中,通过绘制图片的灰度直方图,可以很明显的判断图片的灰度值分布,区分其对比度高低.对于对比度较低的图片,可 ...

  9. C# default(T)关键字

    C#关键词default函数,default(T)可以得到该类型的默认值. C#在类初始化时,会给未显示赋值的字段.属性赋上默认值,但是值变量却不会. 值变量可以使用默认构造函数赋值,或者使用defa ...

  10. git切换分支冲突解决-删除分支

    在项目开发中,有多个版本分支需要不时的来回切换,在切换的过程中,产生了很多冲突,提交的时候 也提交不了.总结下在解决这个过程中使用的两种方法: 1.删除项目在磁盘的目录,包括 git 文件,重新 cl ...