使用cloudwatch确定linux服务是否正在运行 [英] Use cloudwatch to determine if linux service is running

查看:69
本文介绍了使用cloudwatch确定linux服务是否正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个ec2实例,其服务 /etc/init/my_service.conf 内容

Suppose I have an ec2 instance with service /etc/init/my_service.conf with contents

script
    exec my_exec
end script

我该如何监视该ec2实例,以便在 my_service 停止运行时可以采取行动?

How can I monitor that ec2 instance such that if my_service stopped running I can act on it?

推荐答案

您可以以心跳的形式向CloudWatch发布自定义指标。

You can publish a custom metric to CloudWatch in the form of a "heart beat".


  • 通过服务器上的cron运行的脚本,检查
    进程列表以查看my_service是否正在运行,如果正在运行,请进行
    a put-metric-data 调用到CloudWatch。

  • 指标很简单,只要将数字 1推送到CloudWatch中的自定义指标即可。

  • 设置CloudWatch警报,该警报将在指标的平均值低于1时触发

  • 使警报的时间段> = cron运行cron每5分钟运行一次,如果在两个5分钟内看到平均值低于1,则发出警报。

  • 请确保您还处理未发布指标的情况(例如cron无法运行或整个机器死机)。您可能想设置一个警报,以防指标丢失。 (请参阅此处: AWS Cloudwatch心跳警报

  • 请注意,自定义指标将向您的AWS账单增加50c的额外成本(对于一个指标而言,这并不是什么大不了的事情-但是,如果您要推升上百/千个指标,则等式会发生巨大变化-即,很高兴知道

  • Have a small script running via cron on your server checking the process list to see whether my_service is running and if it is, make a put-metric-data call to CloudWatch.
  • The metric could be as simple as pushing the number "1" to your custom metric in CloudWatch.
  • Set up a CloudWatch alarm that triggers if the average for the metric falls below 1
  • Make the period of the alarm be >= the period that the cron runs e.g. cron runs every 5 minutes, make the alarm alarm if it sees the average is below 1 for two 5 minute periods.
  • Make sure you also handle the situation in which the metric is not published (e. g. cron fails to run or whole machine dies). you would want to setup an alert in case the metric is missing. (see here: AWS Cloudwatch Heartbeat Alarm)
  • Be aware that the custom metric will add an additional cost of 50c to your AWS bill (not a big deal for one metric - but the equation changes drastically if you want to push hundred/thousands of metrics - i.e. good to know it's not free as one would expect)

有关如何发布自定义指标的信息,请参见此处: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/publishingMetrics.html

See here for how to publish a custom metric: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/publishingMetrics.html

这篇关于使用cloudwatch确定linux服务是否正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆