zoukankan      html  css  js  c++  java
  • 老司机的应用级监控——spring actuator(转)

    转自:https://www.jianshu.com/p/c043d3c71f47

    什么是spring actuator?

    这是一个研发老司机与运维同学都会非常喜欢的东西,随着点融集团的扩张,点融网的业务越来越复杂、服务越来越多,不论是微服务还是SOA都会大大加重运维的负担。这时在应用层提供统一、强大的监控接口对于自动化运维来讲就显得非常重要!

     
     

    对于研发来讲,可以在应用启动后拿到应用的各种数据,非常便于调试应用、分析应用的运行状况,并且不需要研发去实现这些监控功能。

    对于运维来讲,可以监控应用的健康信息、统计应用的瞬时信息。发现应用挂掉了、发现瞬时信息不正常都可以发送报警信息, 也可以将信息拉到监控系统的数据系统中,再展示到漂亮的UI上实时监控应用的运行状态。这些actions 无疑将会大大保证系统的整体质量。

    而集成了actuator的springboot应用会在约定的endpoints上暴露自己应用的内部信息,又强大又统一标准,满足复杂分布式系统的监控需求,一些endpoints简介如下:

     
     

    研发会重点关注绿色的五项、而运维更关注深绿色的两项,其他项笔者暂时没有发现有特别的用处...

    如何在springboot应用中enable actuator?

    compile

    'org.springframework.boot:spring-boot-starter-actuator:1.3.6.RELEASE'

    自定义已有的endpoints

    1) 每个endpoint都可以在application.properties里面用 endpoints.[endpoint].[id|sensitive|enabled]来重定义其默认值。

    例如:

     
     

    这样就将autoconfig这个endpoint的path修改为了auto_cfg,本着约定优于配置原则,没有特殊需求,笔者不建议做此类修改。

    2) 自定义 /health endpoint

    当springboot应用跑起来之后,你可以通过访问该接口获得应用的健康状态。

     
     

    例如,图片中的 “ status:"UP" ” 即表明应用的健康状态,diskSpace 当中的单位为bytes. 表明了该应用目前硬盘的健康状态:

    红色箭头为我在health endpoint中自定义的 rabbitMQ healthCheckIndicator. 用于检查我的应用所依赖的rabbitMQ的健康状态。具体实现方式如下:

    您需要实现HealthIndicator 接口或者继承AbstractHealthIndicator

     
     

    3) 自定义 /metrics endpoint

    正如一的表格当中所讲的, metrics是最重要的endpoint之一。

     
     

    红色箭头所指向两个gauge指标是我fake的一个queue所对应有几个consumer, 有几条还在queue中未被消费的消息数量,具体自定义方式如下:

     
     

    如果想要自定义一些metrics, 如api的访问次数、消息数量成功处理次数、消息处理失败次数则可以自定义如下,也会展示在metrics接口中:

     
     

    4) 自定义 /info endpoint

    在application.properties中, 添加自定义字段,如下:

     
     

    访问效果:

     
     

    创建一个新的endpoint

    您需要实现Endpoint 接口或者继承AbstractEndpoint。

     
     

    访问效果:

     
     

    还有其他的一些自定义,开发可以不用特别关心 。

    非Springboot的Spring应用, 集成spring actuator

    添加依赖:

    compile('org.springframework.boot:spring-boot-actuator'){ exclude group: 'org.springframework.boot',

    module:'spring-boot-starter-logging'}

    1) 使用 AnnotationConfigWebApplicationContext :

    并在 Spring初始化config bean的上面添加@EnableAutoConfiguration 即可。详情见附录3。

    2) 使用 XML 方式的nonboot - spring 应用

    在任一Spring生命周期的Component bean上 添加@EnableAutoConfiguration 即可。

    也可以@Autowire 这些Endpoint自定义访问路径。详情见附录4

     
     


    附录:

    集成springboot actuator到非springboot spring应用中 : https://stackoverflow.com/questions/26913087/use-spring-boot-actuator-without-a-spring-boot-application

    本文所用的springboot源码: https://github.com/Agileaq/springboot-actuator

    非springboot的annotationConfig spring web应用源码: https://github.com/Agileaq/nonboot-actuator-example

    非springboot的xml base web应用源码: https://github.com/Agileaq/nonboot-xml-spring-actuator

    English version of Spring Actuator introduction: http://www.baeldung.com/spring-boot-actuators

    黑帮文章——神荼之眼监控系统(点融黑帮后台回复【神荼之眼】即可查看)

    黑帮文章——高颜值绘图工具Grafana(点融黑帮后台回复【Grafana】即可查看)




  • 相关阅读:
    zookeeper使用场景
    zookeeper安装配置
    hadoop 远程调试
    deep learning笔记
    Sentiment Analysis(1)-Dependency Tree-based Sentiment Classification using CRFs with Hidden Variables
    PRML阅读笔记 introduction
    Python 学习笔记(2)
    python nltk 学习笔记(5) Learning to Classify Text
    python nltk 学习笔记(4) Writing Structured Programs
    python nltk 学习笔记(3) processing raw text
  • 原文地址:https://www.cnblogs.com/shuiyelifang/p/8360060.html
Copyright © 2011-2022 走看看