由于2.x和1.x的监控不一样,此处先讲1.x

一 SpringBoot1.x监控

pom.xml

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

显示信息

10-15 15:57:11.548  INFO 11388 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-10-15 15:57:11.548 INFO 11388 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29
2019-10-15 15:57:11.657 INFO 11388 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-10-15 15:57:11.657 INFO 11388 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1027 ms
2019-10-15 15:57:11.970 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-10-15 15:57:11.970 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'metricsFilter' to: [/*]
2019-10-15 15:57:11.970 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-10-15 15:57:11.970 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-10-15 15:57:11.970 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-10-15 15:57:11.985 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-10-15 15:57:11.985 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2019-10-15 15:57:11.985 INFO 11388 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'applicationContextIdFilter' to: [/*]
2019-10-15 15:57:12.251 INFO 11388 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6b1274d2: startup date [Tue Oct 15 15:57:10 CST 2019]; root of context hierarchy
2019-10-15 15:57:12.298 INFO 11388 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-10-15 15:57:12.298 INFO 11388 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-10-15 15:57:12.329 INFO 11388 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-10-15 15:57:12.329 INFO 11388 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-10-15 15:57:12.360 INFO 11388 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-10-15 15:57:12.563 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
2019-10-15 15:57:12.574 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
2019-10-15 15:57:12.574 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map<java.lang.String, java.lang.String>)
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2019-10-15 15:57:12.575 INFO 11388 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

在配置文件application.properties中加入

management.security.enabled=false
info.app.id=hello
info.app=world #可以随意配置info开头的信息

下面进行各个节点测试

http://localhost:8080/health
{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 322541973504,
"free": 218166931456,
"threshold": 10485760
}
}
http://localhost:8080/info

{"app":"world","app.id":"hello"}
http://localhost:8080/dump

{
"threadName": "DestroyJavaVM",
"threadId": 40,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 0,
"lockName": null,
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "RUNNABLE",
"stackTrace": [],
"lockedMonitors": [],
"lockedSynchronizers": [],
"lockInfo": null
},
{
"threadName": "http-nio-8080-AsyncTimeout",
"threadId": 38,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 653,
"lockName": null,
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "TIMED_WAITING",
"stackTrace": [
{
"methodName": "sleep",
"fileName": "Thread.java",
"lineNumber": -2,
"className": "java.lang.Thread",
"nativeMethod": true
},
{
"methodName": "run",
"fileName": "AbstractProtocol.java",
"lineNumber": 1133,
"className": "org.apache.coyote.AbstractProtocol$AsyncTimeout",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "Thread.java",
"lineNumber": 745,
"className": "java.lang.Thread",
"nativeMethod": false
}
],
http://localhost:8080/env

{
"profiles": [],
"server.ports": {
"local.server.port": 8080
},
"commandLineArgs": {
"spring.output.ansi.enabled": "always"
},
"servletContextInitParams": {},
"systemProperties": {
.....
}
http://localhost:8080/beans

{
"context": "application",
"parent": null,
"beans": [
{
"bean": "actuatorApplication",
"aliases": [],
"scope": "singleton",
"type": "com.example.demo.ActuatorApplication$$EnhancerBySpringCGLIB$$90808ed2",
"resource": "null",
"dependencies": []
},
{
"bean": "org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory",
"aliases": [],
"scope": "singleton",
"type": "org.springframework.core.type.classreading.CachingMetadataReaderFactory",
"resource": "null",
"dependencies": []
},
{
"bean": "org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration",
"aliases": [],
"scope": "singleton",
"type": "org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration$$EnhancerBySpringCGLIB$$15f9df49",
"resource": "null",
"dependencies": []
},
http://localhost:8080/health

{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 322541973504,
"free": 218146656256,
"threshold": 10485760
}
}
http://localhost:8080/metrics

{
"mem": 277267,
"mem.free": 168703,
"processors": 4,
"instance.uptime": 785901,
"uptime": 789830,
"systemload.average": -1,
"heap.committed": 235520,
"heap.init": 262144,
"heap.used": 66816,
"heap": 3702784,
"nonheap.committed": 42816,
"nonheap.init": 2496,
"nonheap.used": 41748,
"nonheap": 0,
"threads.peak": 36,
"threads.daemon": 26,
"threads.totalStarted": 42,
"threads": 28,
"classes": 6055,
"classes.loaded": 6055,
"classes.unloaded": 0,
"gc.ps_scavenge.count": 5,
"gc.ps_scavenge.time": 49,
"gc.ps_marksweep.count": 1,
"gc.ps_marksweep.time": 38,
"httpsessions.max": -1,
"httpsessions.active": 0,
"gauge.response.beans": 12,
"gauge.response.env": 8,
"gauge.response.dump": 58,
"gauge.response.health": 24,
"gauge.response.star-star.favicon.ico": 25,
"counter.status.200.beans": 2,
"counter.status.200.star-star.favicon.ico": 1,
"counter.status.200.health": 1,
"counter.status.200.dump": 1,
"counter.status.200.env": 2
}

当加入git.properties

git.branch=master
git.commit.id=xjkd33s
git.commit.time=2017-12-12 12:12:56
http://localhost:8080/info

{
"app": "world",
"app.id": "hello",
"git": {
"commit": {
"time": "2017-12-12 12:12:56",
"id": "xjkd33s"
},
"branch": "master"
}
}

检查健康监控的时候,测试如下

加入redis的依赖

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

配置(测试用,随便填的地址)

spring.redis.host=118.24.44.169
http://localhost:8080/health       ##会查出redis的信息
{
"status": "DOWN",
"diskSpace": {
"status": "UP",
"total": 322541973504,
"free": 218147446784,
"threshold": 10485760
},
"redis": {
"status": "DOWN",
"error": "org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool"
}
}

二 定制断点信息

  • 定制断点一般通过endpoints+端点名+属性名来设置。

    修改结果:http://localhost:8080/bean 只有这个能登陆

    • management.context-path=/manage

      修改结果:访问要加路径/manage

    • management.port=8181

      修改结果:访问的端口改成8181

三 自定义健康状态指示器

  • 编写一个指示器 实现 HealthIndicator 接口

  • 指示器的名字 xxxxHealthIndicator

  • 加入容器中

    package com.example.demo;

    import org.springframework.boot.actuate.health.Health;
    import org.springframework.boot.actuate.health.HealthIndicator;
    import org.springframework.stereotype.Component;

    @Component
    public class MyAppHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {

    //自定义的检查方法
    //Health.up().build()代表健康
    return Health.down().withDetail("msg","服务异常").build();
    }
    }

    测试结果:

    http://localhost:8080/manage/health

    {
    "status": "DOWN",
    "myApp": {
    "status": "DOWN",
    "msg": "服务异常"
    },
    "diskSpace": {
    "status": "UP",
    "total": 322541973504,
    "free": 218143944704,
    "threshold": 10485760
    },
    "redis": {
    "status": "DOWN",
    "error": "org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool"
    }
    }

SpringBoot1.x与监控(六)的更多相关文章

  1. 朱晔的互联网架构实践心得S1E4:简单好用的监控六兄弟

    朱晔的互联网架构实践心得S1E4:简单好用的监控六兄弟 [下载本文PDF进行阅读] 这里所说的六兄弟只指ELK套件(ElasticSearch+Logstash+Kibana)以及TIG套件(Tele ...

  2. 朱晔和你聊Spring系列S1E6:容易犯错的Spring AOP

    阅读PDF版本 标题有点标题党了,这里说的容易犯错不是Spring AOP的错,是指使用的时候容易犯错.本文会以一些例子来展开讨论AOP的使用以及使用过程中容易出错的点. 几句话说清楚AOP 有关必要 ...

  3. 朱晔的互联网架构实践心得S1E1:Pilot

    朱晔的互联网架构实践心得S1E1:Pilot 最近几年写博客确实写得少了,初出茅庐的时候什么都愿意去写,现在写一点东西之前会反复斟酌是否有价值.工作十几年了,做了N多个互联网系统,业务涉及教育.游戏. ...

  4. Kafka实战解惑

    目录 一. kafka简介二. Kafka架构方案三. Kafka安装四. Kafka Client API 4.1 Producers API 4.2 Consumers API 4.3 消息高可靠 ...

  5. 朱晔的互联网架构实践心得S2E6:浅谈高并发架构设计的16招

    朱晔的互联网架构实践心得S2E6:浅谈高并发架构设计的16招 概览 标题中的高并发架构设计是指设计一套比较合适的架构来应对请求.并发量很大的系统,使系统的稳定性.响应时间符合预期并且能在极端的情况下自 ...

  6. 深入剖析 RabbitMQ —— Spring 框架下实现 AMQP 高级消息队列协议

    前言 消息队列在现今数据量超大,并发量超高的系统中是十分常用的.本文将会对现时最常用到的几款消息队列框架 ActiveMQ.RabbitMQ.Kafka 进行分析对比.详细介绍 RabbitMQ 在 ...

  7. 一文带你了解nginx基础

    学习nginx,就要先了解什么是nginx,为什么使用nginx,最后才是了解怎么使用nginx nginx简介 nginx安装 一.Linux中安装nginx 二.Docker中安装nginx 三. ...

  8. SpringBoot入门及深入

    一:SpringBoot简介 当前互联网后端开发中,JavaEE占据了主导地位.对JavaEE开发,首选框架是Spring框架.在传统的Spring开发中,需要使用大量的与业务无关的XML配置才能使S ...

  9. OC-引用计数器,内存管理,野指针

    总结 全局断点 →-->+-->Add Exception Breakpoint 开启僵尸监听 打开Edit scheme -->Diagnostics-->Enable Zo ...

随机推荐

  1. 打印方案之web打印

    前言: 前一段时间在工作中,遇到需要通过打印实现对报表或者工作流清单等事情时,都需要运用到打印功能,那么 ,这个时候你会怎么处理? 在这里,我们可以通过最简单的方式实现web打印功能,简单易懂,方便快 ...

  2. Player的跟踪狂 -- Camera

    P.S.很多游戏里的Player都会设置的被跟踪,是人性的扭曲,还是XXX,正在解密. 第三人称视角 camera紧跟player背后(角度随player改变) using System.Collec ...

  3. 非对称加密openssl协议在php7实践

    据网上资料,RSA加密算法是一种非对称加密算法.在公开密钥加密和电子商务中RSA被广泛使用.RSA是1977年由罗纳德·李维斯特(RON RIVEST).阿迪·萨莫尔(ADI SHAMIR)和伦纳德· ...

  4. JAVA 8 新特性Stream初体验

    什么是 Stream? Stream(流)是一个来自数据源的元素队列并支持聚合操作 <strong元素队列< strong="">元素是特定类型的对象,形成一个队 ...

  5. Python实现几种简单的排序算法

    一.冒泡排序 概念:为一个无序的列表排成有序的 实现过程描述:(升序) 1.比较相邻的元素,如果第一个比第二个大,就交换他们的位置 2.对每一对相邻元素重复1的工作,从开始第一队到最后一对,最后结束的 ...

  6. wordpress新注册用户或重置密码链接失效

    在网上找了好多个博客,一个比一个不要脸,要更改的是两个文件,最后都抄成一个文件了. 原文链接https://www.cnblogs.com/liudecai/p/6474611.html 我是按照这个 ...

  7. MongoDB 学习笔记之 WriteConcern

    WriteConcern: 转载:MongoDB WriteConcern(写关注)机制 http://www.ywnds.com/?p=3688&viewuser=40 MongoDB部署模 ...

  8. 5G 时代,云计算迎来新风口

    云计算是对传统IT模式从底层硬件到业务模式的颠覆,传统IT市场具备万亿级市场空间,目前云计算收入占IT支出占比尚小,渗透率较低,未来空间较大. 短期受到宏观经济等因素影响,云巨头资本开支增速有所波动, ...

  9. B-概率论-贝叶斯决策

    目录 贝叶斯决策 一.贝叶斯决策理论 二.贝叶斯公式 2.1 从条件概率公式推导贝叶斯公式 2.2 从全概率公式推导贝叶斯公式 三.贝叶斯公式应用 更新.更全的<机器学习>的更新网站,更有 ...

  10. vue-cli脚手架项目本地阅览和在线阅览

    一.需求 开发环境:当然啦,前提是你要完整检测整个项目无错误的运行:npm run dev 后项目在本地预览问题没有问题 二.服务器本地阅览 生产环境:项目制作完成后需执行npm run build操 ...