Ceilometer Distributed Alarm

Ceilometer Alarm是H版新添加的功能,监控报警是云平台不可缺少的部分,Ceilometer已经实现了比较完善的监控体系,报警怎么能缺少呢?用过AWS CloudWatch Alarm的人应该不会对Ceilometer的Alarm感到陌生,Ceilometer实现的Alarm和CloudWatch的Alarm很像,概念基本上都一样,Alarm的逻辑也基本上一样,可以说是一个开源版的CloudWatch Alarm,但是它进行了一些“微创新”,实现了一些比较有意思的小功能,而且代码写的也非常不错,是一个不错的学习素材。

下面我们从功能,实现,以及它目前存在的问题三个方面介绍一下Ceilometer的Alarm。

功能篇

简单来说,Alarm的功能其实很简单,监控某一个或多个指标的值,若高于或者是低于阈值,那么就执行相应的动作,比如发送邮件短信报警,或者是直接调用某个接口进行autoscaling操作,像Heat就是依赖Ceilometer的Alarm实现Auto Scaling的操作。

Ceilometer中,实现了2种alarm:一种是threshold,一种是combination。顾名思义,threshold就是我们熟悉的根据监控指标的阈值去判断alarm的状态,它只是针对某一个监控指标建立alarm,而combination则可以理解为alarm的alarm,它是根据多个alarm的状态来判断自己的状态的,多个alarm之间是or/and的关系,这相当于是对多个监控指标建立了一个alarm。一般情况下,我们只需要threshold类型的alarm就足够了,但是一些特殊情况,比如Heat要执行auto scaling操作,可能就要对多个监控指标进行衡量,然后再采取操作。

下面,我们来分析一下Alarm的API,看它到底提供了哪些不一样的功能:

1. POST /v2/alarms

创建一个alarm,详细的参数见下表:

参数类型解释

namestrname是project唯一的

descriptionstr描述

enabledboolalarm的一个开关,可以停止/启动该alarm,默认是True

ok_actionslist当alarm状态变为ok状态时,采取的动作,默认是[]

alarm_actionslist当alarm状态变为alarm状态时,采取的动作,默认是[]

insufficient_data_actionslist当alarm状态变为insufficient data状态时,采取的动作,默认是[]

repeat_actionsbool当alarm被触发时,是否重复执行对应的动作,默认是False

typestralarm类型,目前有threshold和combination两种,必填

threshold_ruleAlarmThresholdRule当alarm类型为threshold时,制定的threshold规则

combination_ruleAlarmCombinationRule当alarm类型为combination时,制定的combination规则

time_constraintslist(AlarmTimeConstraint)约束该alarm在哪些时间段执行,默认是[]

statestralarm的状态,默认是insufficient data

user_idstruser id,默认是context user id

project_idstrproject id, 默认是context project id

timestampdatetimealarm的定义最后一次被更新的时间

state_timestampdatetimealarm的状态最后一次更改的时间

这里主要说下面几个参数:

AlarmThresholdRule:

AlarmCombinationRule:

operator: 定义alarms之间的逻辑关系,有两个选项:or 和 and,默认是and,注意这里的逻辑关系ALARM要比OK状态优先级高,比如有2个alarm,一个状态是ALARM,一个状态是OK,他们之间的逻辑关系是or,那么这个combination alarm是啥状态呢?答案是ALARM.alarms_id: alarm列表

AlarmTimeConstraint:

举两个例子:

threshold

{"name": "ThresholdAlarm1","type": "threshold","threshold_rule": {"comparison_operator": "gt","evaluation_periods": 2,"exclude_outliers": false,"meter_name": "cpu_util","period": 600,"query": [{"field": "resource_id","op": "eq","type": "string","value": "2a4d689b-f0b8-49c1-9eef-87cae58d80db"}],"statistic": "avg","threshold": 70.0},"alarm_actions": [":8000/alarm"],"insufficient_data_actions": [":8000/nodata"],"ok_actions": [":8000/ok"],"repeat_actions": false,"time_constraints": [{"description": "nightly build every night at 23h for 3 hours","duration": 10800,"name": "SampleConstraint","start": "0 23 * * *","timezone": "Europe/Ljubljana"}]}

combination

{"name": "CombinationAlarm1","type": "combination","combination_rule": {"alarm_ids": ["739e99cb-c2ec-4718-b900-332502355f38","153462d0-a9b8-4b5b-8175-9e4b05e9b856"],"operator": "or"},"alarm_actions": [":8000/alarm"],"insufficient_data_actions": [":8000/nodata"],"ok_actions": [":8000/ok"]}2. GET /v2/alarms/{alarm_id}/history

这个接口用来查询某个alarm发生的历史事件,记录的事件有:alarm被创建,alarm被更新,,alarm被删除,alarm的状态被更新。

举个例子,比如我创建了一个alarm,然后又删除了,调用这个接口返回的结果是:

[{"on_behalf_of": "2c35166baba84f46b1c5b093f02747fa","user_id": "778a4ae5d8904a41b00c4e0f5734bcfd","event_id": "dc5583ac-7ac8-4f4e-b8f7-edaa04522945","timestamp": "2014-07-26T16:50:59.387923","detail": "xxx","alarm_id": "697a05df-d704-46a4-a0bd-1591c6588a17","project_id": "2c35166baba84f46b1c5b093f02747fa","type": "deletion"},{"on_behalf_of": "2c35166baba84f46b1c5b093f02747fa","user_id": "778a4ae5d8904a41b00c4e0f5734bcfd","event_id": "d09fe2c3-37a8-4b19-9729-ccb2664a1116","timestamp": "2014-07-26T16:50:27.315824","detail": "xxx","alarm_id": "697a05df-d704-46a4-a0bd-1591c6588a17","project_id": "2c35166baba84f46b1c5b093f02747fa","type": "creation"}]

Alarm还有其它一些接口,这里就不说了,更多见文档。

实现篇所有的失败,与失去自己的失败比起来,更是微不足道

Ceilometer Distributed Alarm

相关文章:

你感兴趣的文章:

标签云: