0

In my stack I'm using EC2 and NodeJS with PM2.

Time to time PM2 fails and the server goes down.

I'd like to create an email notification for these cases.

What I got so far:

  1. crontab job to ping the server every 10 minutes and write to a log file if it's down.
  2. CloudWatch monitoring that log file.
  3. Missing step.
  4. SNS Event and Subscription to send me an email.

My plan is to install the CloudWatch agent and configure the crontab in some others customer's servers. Group all them in the same CloudWatch/SNS flow.

I'm working on step 3: the connection between CloudWatch and SNS.

Using CloudWatch's wizard, it seems like I can only send statistics, like "the number of logs", and not the log itself.

The log created in step 1 has data about the server that is down, and I'd like to add it to the email message.

EDIT It's not a personal setup. And for some reason, my boss says the CloudWatch is a must to.

Falci
  • 1,823
  • 4
  • 29
  • 54

3 Answers3

0

Try using elastic beats. It will provide you the real-time server logs which you can view using kibana and there using the sentinl plugin you can configure and send any type of email on any system stats.

Please refer to the below-mentioned links :

Elastic Beats

Sentinl

Abhimanyu
  • 2,710
  • 2
  • 25
  • 42
0

I would use Route 53's Health Check feature which integrates with CloudWatch. You can then setup alerts in CloudWatch to send you an email. I don't think you have to be using Route 53 for DNS in order to use this, although if you are using Route 53 the you could also use this to perform a fail-over to a different server.

Alternatively, if the server is behind a Load Balancer then you could trigger the CloudWatch alarm off the Healthy Hosts metric that the Load Balancer's health check publishes to CloudWatch.

Mark B
  • 183,023
  • 24
  • 297
  • 295
0

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

  • 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.

And so on, take a look at this to keep the necessary steps: Use cloudwatch to determine if linux service is running

Those steps were listed by @BestPractices

Ele
  • 33,468
  • 7
  • 37
  • 75