ambari之alert解析

本次分析是基于ambari2.1.1进行的。

   1,Ambari Server启动时,会整合Alert定义,并将其保存到数据库中

         AmbariServer.java中
    LOG.info("********* Reconciling Alert Definitions **********");
       ambariMetaInfo.reconcileAlertDefinitions(clusters);
   2,接着启动定时调度任务

         AmbariServer.java中
serviceManager.startAsync();
    LOG.info("********* Started Services **********");
    Ambari采用guice作为依赖注入的框架;

    在类org.apache.ambari.server.controller.ControllerModule中完成了所有的依赖注入,包括ServiceManager

这里写图片描述
如代码所示,程序通过标注的方式@AmbariService找到要注入的service,被标注的service有两个:
org.apache.ambari.server.state.services.AlertNoticeDispatchService
这个服务用来查询数据库,获取处于挂起状态(NotificationState#PENDING)的通知对象(AlertNoticeEntity),
然后使用分派系统处理这些通知。
org.apache.ambari.server.state.services.AmbariServerAlertService
这个服务从数据库中查询表alert_definition,获取service_name=’AMBARI’ and component_name=
‘AMBARI_SERVER’的记录,即AlertDefinitionEntity,如下图:
这里写图片描述
一共存在两个AlertDefinitionEntity,分别获取对应的执行体(Runnable),这个执行体进行Server端的检测,执行体有两个,对应的配置文件入下:
这里写图片描述
org.apache.ambari.server.alerts.AgentHeartbeatAlertRunnable
这个执行体用来探测agent的心跳是否正常,程序会根据host的状态生成对应的alert,然后向事件总线发送对应的事件AlertReceivedEvent;
org.apache.ambari.server.alerts.StaleAlertRunnable
这个执行体用于检测alert最后的时候是否超过了指定的时间,用于判断这个alert的状态是否是陈旧的。如果alert的状态是陈旧的,说明该alert生成程序不再运行了。
a)分发通知
AlertNoticeDispatchService
b)Agent心跳是否过期
AgentHeartbeatAlertRunnable
c)是否存在过期未报的Alert
StaleAlertRunnable
3,Agent执行Alert信息收集
a)Agent向Server注册时,将本节点的Alert定义通过心跳响应从Server拿到本节点并保存为/var/lib/ambari-agent/cache/alerts/definitions.json
这里写图片描述
b)Agent根据definitions.json中的内容启动定时调度任务,收集相应指标
这里写图片描述
c)Agent向Server发送心跳时,会将收集到的Alert信息一同发送给Server
这里写图片描述
4,Server接收到心跳,将心跳信息中的Alert信息保存到数据库中
这里写图片描述

猜你喜欢

转载自blog.csdn.net/zxl1033394132/article/details/52452919