Use cloudwatch to determine if Linux service is running

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

 script exec my_exec end script 

How can I control this ec2 instance so that if my_service stops, can I act on it?

+5
source share
2 answers

You can publish your own heartwave metric to CloudWatch.

  • You have a small script running through cron on your server that checks the process list to see if my_service is working, and if so, make a put-metric-data call to CloudWatch.
  • A metric can be as simple as tapping the number ā€œ1ā€ on your custom metric in CloudWatch.
  • Set a CloudWatch alarm that starts if the average for the metric drops below 1
  • Specify the alarm period> = the period during which the cron runs. cron starts every 5 minutes, gives an alarm if it sees that the average value is less than 1 for two 5-minute periods.
  • Make sure that you also deal with a situation in which the metric is not published (for example, cron does not start or the whole computer dies). you need to set up an alert if there is no metric. (see here Heartbeat AWS Cloudwatch Alarm )
  • Keep in mind that a custom metric will add an extra cost of 50c to your AWS account (not a big deal for one indicator), but the equation will change a lot if you want to click one hundred / thousand indicators - that is, it's nice to know it's not free, as you would expect )

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

+11
source

I’m not sure if CloudWatch is the right route to test the service — it would be easier with a Nagios solution.

However, you can try the CloudWatch Custom metrics approach. You add extra lines of code that publishes, say, the integer 1 in CloudWatch Custom Metrics every 5 minutes. You can then configure CloudWatch notifications to notify SNS Notification / Mail Notification for conditions such as Sample Count or sum that reject the expected value.

 script exec my_exec publish cloudwatch custom metrics value end script 

Additional Information

Post custom metrics - http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/publishingMetrics.html

+1
source

All Articles