ここでは、しきい値アラームをメッセージサービス (MNS) に書き込む方法について説明します。
手順
- CloudMonitor による MNS へのアラームの書き込みを許可するには、ここをクリックします。
- OpenAPI Explorer サービスを開始し、 PutResourceMetricRule操作を呼び出して、アラームルールを作成します。
- PutMetricRuleTargets操作を呼び出して、指定のアラームルールのアラームを作成し、対応する MNS パラメーターを設定します。
ARN:
“acs:mns:{$RegionId}:{$UserId}:/queues/{$queueName}/messages”
の形式で対象の MNS キューを指定します。または、“acs:mns:{$RegionId}:{$UserId}:/topics/{$queueName}/messages”
の形式で対象の MNS トピックを指定します。
次の例では、PutMetricRuleTargets のパラメーターを示します。
RuleId:”db17-4afc-b11a-568512d5a1f9”,Targets:[{ Id: 1, Arn:”acs:mns:{$RegionId}:{$UserId}:/queues/{$queueName}/messages”, Level: [“INFO”, “WARN”, “CRITICAL”],}]
MNS に書き込むメッセージ本文
CloudMonitor は、メッセージ本文を JSON 文字列形式で MNS に書き込みます。 MNS がメッセージ本文を読み込むと、クライアントは次のようにメッセージ構造をJSON 文字列として解析します。
{ “ruleId”: “putNewAlarm_group_778af9ba-a291-46ab-ac53-3983bcee“, “ruleName”: “test”, //Current level. “curLevel”: “WARN”, //Previous level. “preLevel”: “OK”, //The instance that triggers the alarm. “resources”: “{\”instanceId\”: \”i-uf61rfofjd2iku7e\”}”, //The condition that triggers the alarm. “escalation”: { “comparisonOperator”: “GreaterThanYesterday”, “level”: 3, “statistics”: “Average”, “tag”: “WARN”, “threshold”: “0”, “times”: 1 }, “metricData”: { “timestamp”: 1534736160000, “userId”: “127067667954“, “instanceId”: “i-uf61rfofjd2iku7e“, “Average”: 470687744, “Maximum”: 470794240, “Minimum”: 470556672, //Compare some metrics with those in the previous month and those in the same period of the previous year.—Start. “AliyunCmsPrevValues”: { //Compared values. “timestamp”: 1534649760000, “userId”: “127067667954“, “instanceId”: “i-uf61rfofjd2iku7e“, “Average”: 468463616, “Maximum”: 468549632, “Minimum”: 468258816 }, //Comparison formula. “AliyunCmsComplexExpression”: “100.0 ($Average-$$prevAverage)/$$prevAverage”, //Conversion formula. “AliyunCmsComplexMath”: “100.0 (470687744-468463616)/468463616”, //Calculation result. “AliyunCmsComplexValue”: 0.47477070236336133 //Compare some metrics with those in the previous month and those in the same period last year.—End. }, //Metric parameters. “metricName”: “memory_actualusedspace#60”, “namespace”: “acs_ecs_dashboard”, “period”: “60”, //Application group parameters. “groupBy”: “group”, “productGroupName”: “RDS instance group”, “groupId”:”44958”, //Alarm time “lastTime”: 327362743, //The duration of the alarm. “time”: 1534736160000, //The time when the data occurred. “userId”: “173651113438“, “eventName”: “AlertOk”, “eventType”: “Alert”, //Use the following parameters to trace the alarm. “batchId”: “4272653-152082-0”, “version”: “1.0”}
</article>
</main>