Others

Check_AWS_CloudWatch_metrics

Description:

This is a ruby script that retrieve metrics from Amazon Web Service EC2, ELB or RDS using Amazon CloudWatch API (supports all AWS region).
The Amazon credentials (Access Key ID and Secret Access Key) are read from an encrypted file.

NB: Amazon CloudWatch Namespaces, Dimensions, and Metrics Reference: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html

Current Version

6.4.44

Last Release Date

2016-10-29

Compatible With

  • Nagios 3.x
  • Nagios XI

License

Apache


Project Files
Project Notes
Using Amazon CloudWatch API, it is possible to retrieve the metrics (CPU, NetWork, Disk) from an instance without installing any agent or configuring SNMP daemon. Moreover, this requires only read-only credentials that could be easily generated using Amazon IAM. For security reasons, we use encrypted credentials that are decrypted by this plugin. Here is a command line sample of use for EC2: debian-secludit # RUBYOPT=rubygems ruby lib/nagios/check_cloudwatch_status.rb -a ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com -i i-XXXXXXXX -f ec2_credentials_1.cfg -C CPUUtilization -c 90 -w 75 CloudWatch Metric: CPUUtilization, Average: 16.81, Maximum: 22.93, Minimum: 11.56|metric_average=16.81 metric_maximum=22.93 metric_minimum=11.56 The ec2_credentials_1.cfg files contains the encrypted credentials as follow: [blank_space]ec2_access_id[blank_space]B64_encoding(BF-CBC-Cipher_encoding(Access Key ID) [blank_space]ec2_access_key[blank_space]B64_encoding(BF-CBC-Cipher_encoding(Secret Access Key) You can use the encrypt_credentials.rb ruby script that does that as follow: debian-secludit # RUBYOPT=rubygems ruby encrypt_credentials.rb -A XXXXXXXXXXXXXXXXXXXX -S XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -f ec2_credentials.cfg Here is a sample configuration file for nagios. define service { name Amazon_EC2_Instance_Name use generic-service check_command check_cloudwatch_status!i-XXXXXXXX!/etc/nagios3/credentials/ec2_credentials_1.cfg!CPUUtilization!50!80 max_check_attempts 3 } Samples: - EC2 debian-secludit # RUBYOPT=rubygems ruby lib/nagios/check_cloudwatch_status.rb -a ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com -i i-XXXXXXXX -f ec2_credentials_1.cfg -C CPUUtilization -c 90 -w 75 - RDS debian-secludit # RUBYOPT=rubygems ruby lib/nagios/check_cloudwatch_status.rb -i RDS_IDENTIFIER -a RDS_IDENTIFIER.XXXXXX.rds.amzonaws.com -f ec2_credentials_1.cfg -D CPUUtilization -c 90 -w 75 - ELB debian-secludit # RUBYOPT=rubygems ruby lib/nagios/check_cloudwatch_status.rb -i ELB_IDENTIFIER -a ELB_IDENTIFIER.XXXXXX.elb.amzonaws.com -f ec2_credentials_1.cfg -L RequestCount Requirements: Ruby version >= 1.8.7 Fog gem version >= 1.25.0
Reviews (29) Add a Review
Error occured while retrieving and decrypting credentials
by loganmscs004, July 31, 2021
Dear Coder,
First of all, alot of thanks for putting this great plugin. It has removed the depedency for installing nrpe on each instance. I am able to install all depedencies. Now when i tried to run the script i am having this error. Can you please tell me what i am missing here.

Error occured while retrieving and decrypting credentials for instance i-XXXXXXXXX on Amazon Server: ec2-XXXXXXXXX-compute-1.amazonaws.com: key must be 16 bytes
Helpful? Yes  No 
Error key must be 16 bits
by Iwahashi, December 31, 2018
Change: cipher = OpenSSL::Cipher::Cipher.new('bf-cbc') TO: cipher = OpenSSL::Cipher::AES256.new(:CBC)
In check_cloudwatch_status-6.4.44.rb and encrypt_credentials.rb
Helpful? Yes  No 
Some bugs for Ruby 2.4x
by erwinxiao, November 30, 2018
If you are going to use those scripts and your Ruby version is 2.4x, make sure do some modifications on the script:

1. Change "cipher = OpenSSL::Cipher::Cipher.new('bf-cbc')" into ''cipher = OpenSSL::Cipher.new('bf-cbc')"

2. Change "cipher = OpenSSL::Cipher::Cipher.new('bf-cbc')" into "cipher = OpenSSL::Cipher::Cipher.new('aes-256-bc')".
0 of 1 found this review helpful.
Helpful? Yes  No 1
Access CloudWatch Metrics in Nagios via a proxy
by mayurkadam24, August 31, 2017
Are we able to access CloudWatch Metrics in Nagios via a proxy ?
If, not what changes do we need to make ?
Helpful? Yes  No 
Needs maintenance
by rubenc, March 31, 2017
With all up to date, every command comes with a

[fog][DEPRECATION] describe_load_balancers with String is deprecated, use all('LoadBalancerNames' => []) instead (./check_cloudwatch_status.rb:386:in `')

(which can be safely ignored with a simple 2>/dev/null).

Problem is, ELB's RequestCount does not work, it always returns 1:

# ./check_cloudwatch_status.rb -f ec2_credentials.cfg -i XXXX-elb -a XXXX-elb-XXXX.eu-west-1.elb.amazonaws.com -L RequestCount 2>/dev/null
CloudWatch Metric: RequestCount, Average: 1.00, Maximum: 1.00, Minimum: 1.00|metric_average=1.00 metric_maximum=1.00 metric_minimum=1.00

The real RequestCount is by the thousands.
Helpful? Yes  No 
Having some trouble on 3.5.1
by mark8adams, November 30, 2016
This seems like a really good addition to our plugins, but I can't seem to make it work within Nagios. Reports metrics as expected from the command line, from any directory and as the nagios user, but I can only get a "null" response within nagios. I can't figure out what I'm missing.
I even tried the "--help" option as an argument and still only get a "null" return status.
Anybody else had a similar experience?

thanks
Helpful? Yes  No 
warning and critical switches
by SWoody_UK, July 31, 2016
I've got this running, however this is without the -w and -c switches as the help and documentation are unclear whether they are percentages or absolute values. I'm wondering if this can be cleared up as I'm trying to set a threshold on RDS FreeStorageSpace
Helpful? Yes  No 
Error into String
by sachin, July 31, 2016
/tmp/test/check_cloudwatch_status-2.5.07.rb:382:in `+': no implicit conversion of Fog::AWS::RDS::Error into String (TypeError)
from /tmp/test/check_cloudwatch_status-2.5.07.rb:382:in `rescue in '
from /tmp/test/check_cloudwatch_status-2.5.07.rb:336:in `'

I am getting above error. Please help me to resolve it.
Helpful? Yes  No 
Doesn't working with non-public instances
by pauldsmyth, June 30, 2016
This would be so useful but using the public address rather than just specify region means that instances without public addresses cannot be monitored without hacking the code. This is an incredibly basic and obvious feature and has been mentioned some time ago so it's disappointing it still isn't implemented
Helpful? Yes  No 
Fog error
by akaydinb, November 30, 2015
Hello,
I am using Opsview4.5 built on Nagios Core 4.0.20130912. My ruby version is 2.2.

I have added some AWS hosts using default check_cloudwatch_status (first applied these: http://docs.opsview.com/doku.php?id=opsview4.5:opspacks:templates:amazoncloudwatch) script provided in Opsview and got following error:

/usr/local/nagios/libexec/check_cloudwatch_status:330:in `+': no implicit conversion of NameError into String (TypeError)
from /usr/local/nagios/libexec/check_cloudwatch_status:330:in `rescue in '
from /usr/local/nagios/libexec/check_cloudwatch_status:321:in `'


Then I decided to upgrade to the latest version. The error message changed but Opsview still cannot run the check. It quits with following error:

/usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- fog (LoadError)
from /usr/local/rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/nagios/libexec/check_cloudwatch_status:12:in `block in '
from /usr/local/nagios/libexec/check_cloudwatch_status:12:in `each'
from /usr/local/nagios/libexec/check_cloudwatch_status:12:in `'


I have previously installed fog using "gem install fog" command, however current ruby executable cannot "see" fog package (sorry, I am not familiar with ruby).

Here is a sample check command which returns errors above:
sudo -u nagios /usr/local/nagios/libexec/check_cloudwatch_status -a dpesmas01q.n11.local -i "i-XXXXaab1" -C CPUUtilization -f /usr/local/nagios/etc/aws_credentials.cfg


Can you please help?
Helpful? Yes  No 
Works for fetching RDS stats
by esteewhy, October 31, 2015
First of all, the following error:

`+': no implicit conversion of NoMethodError into String (TypeError)

can generally be fixed by replacing:

abcd" + e

with:

abcd #{e}"

The issue i have with this plugin is that it's not very clear how to set --critical and --warning threshold for metrics which are not percentages, but are absolute values.

Let's say, i want to trigger WARN if FreeStorageSpace reaches 10%. How do i do that?

Looking at the code, it seems that threshold can only be an absolute value. But what if I don't know what total available disk size for RDS really is? Even more, what if i want to use the same Nagios service for multiple RDS hosts where disk size might be different (and i still only want to trigger WARN using some percentage threshold)?

Is it possible to use percentage threshold metrics others than CPUUtilization?
Helpful? Yes  No 
Now working for me :(
by rupikakapoor, June 30, 2015
I am getting similar error:
/usr/local/nagios/libexec/check_cloudwatch_status.rb:454:in `+': no implicit conversion of AWS::Error into String (TypeError)
from /usr/local/nagios/libexec/check_cloudwatch_status.rb:454:in `rescue in '
from /usr/local/nagios/libexec/check_cloudwatch_status.rb:408:in `'
Please help!
Owner's Reply:

Hi,
First of all I apologize fr the delay answering you.

We have uploaded a new version of the plugin which is now using Fog gem instead of amazon-ec2.
If any issue, please do not hesitate to contact me directly (fred at secludit.com).

best regards,


Helpful? Yes  No 
Error Message
by rsrajesh, December 31, 2014
When I ran the script check_cloudwatch_status-2.1.77.rb, I get the following error:

check_cloudwatch_status-2.1.77.rb:524:in `+': no implicit conversion of NoMethodError into String (TypeError)
from check_cloudwatch_status-2.1.77.rb:524:in `rescue in '
from check_cloudwatch_status-2.1.77.rb:512:in `


Please help!
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
ELB/RDS update
by johnc10uk, June 30, 2014
For ELB and RDS you don't need to define the instance_id so updated code to take hostname and shorten it for the elb/rds name. You can then use $HOSTNAME$ in the Nagios service check

check_cloudwatch_status.rb! YOURPATH/nagios/plugins/check_cloudwatch_status.rb -a $HOSTNAME$ -f ec2_credentials.cfg -L RequestCount -S Sum

line 348 :-

if namespace.eql?(AWS_NAMESPACE_EC2)
dimensions = "InstanceId=#{instance_id}"
elsif namespace.eql?(AWS_NAMESPACE_RDS)
# Strip off the name from the address
instance_id, *restofvalues = address.split('.')
instance_id = instance_id.split('-')[0...-1].join('-')
dimensions = "DBInstanceIdentifier=#{instance_id}"
elsif namespace.eql?(AWS_NAMESPACE_ELB)
# Strip off the name Load-Balancer-Name from the address Load-Balancer-Name-123456789.elb.amazon.com
instance_id, *restofvalues = address.split('.')
instance_id = instance_id.split('-')[0...-1].join('-')
dimensions = "LoadBalancerName=#{instance_id}"
end
Helpful? Yes  No 
Works well!
by maglub, May 31, 2014
Hi all,

I tested this script quite a bit recently, and offer the following comments:

* Very good integration with AWS once you get the grip on how to configure it.

* Instead of using the "Amazon Instance Address" with the -a/--address parameter, just use the region (i.e us-west-1 ) instead, since the script only use the address to parse out the region.

* I have offered the author a patch to enable http proxy usage, and to optionally allow credentials to be saved into a config.yml instead of the encrypted credentials file.
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Inverse measures?
by Lijiman, April 30, 2014
I have it working however it's funky depending on Cloudwatch's metrics.

It only works for when the measured metric from Cloudwatch is numerically greater than the warning or critical threshold metrics. So it works great for CPU since if it measures 80 from RDS Cloudwatch that meants it's at 80% use. However when measuring RDS FreeStorageSpace it won't work the same. FreeStorageSpace measures the empty space in RDS. This script won't work when you want to alert warning at 20GB free and then critical at 10GB free it will never trigger.

What would be ideal is if CloudWatch could measure UsedStorageSpace as well as FreeStorageSpace. Is there any way this script can measure the inverse?

If I could alert warning when RDS is 80% USED and 90% USED I think this script would be even more powerful.
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Extrmely useful plugin and excellent support
by egalstad, March 31, 2014
I have incorporated this plugin with our existing nagios setup and it has been very useful.
It works exactly as expected and makes it easier to have all the metrics monitored.
Very easy to setup. Needed a little bit of testing etc.
Here are the example syntaxes for all the AWS components.

For ELB
RUBYOPT=rubygems ruby ~/check_cloudwatch_status.rb -a checkcheck-892345671.us-east-1.elb.amazonaws.com -i checkcheck -f ec2_credentials.cfg -L RequestCount -S Sum

As I was informed by Fred, you can also use -S Sum,Maximum

For RDS

RUBYOPT=rubygems ruby ~/check_cloudwatch_status.rb -a checkcheck-892345671.us-east-1.rds.amazonaws.com -i checkcheck -f ec2_credentials.cfg -D DiskQueueDepth

EC2 example is as given in the description.

Thank you Fred.
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Information Regarding Check_AWS_CloudWatch_metrics Nagios Pluggin
by arun.tp, January 31, 2014
Hi.

First things first, Thanks for Check_AWS_CloudWatch_metrics Nagios Pluggin. The impementation and configuration was really quick and simple. It eased a lot of my work

This is the output I get

CloudWatch Metric: CPUUtilization, Average: 64.81, Maximum: 75.50, Minimum: 40.51 | metric_average=64.81 metric_maximum=75.50 metric_minimum=40.51


The only problem i had was to understanding the correctness of the output. When the pluggin says
CPUUtilization, Average: 64.81, Maximum: 75.50, Minimum: 40.51
Is it the average CPUUtilization, considering the CPU utilization of the past hour or the past day. Same in the case of Minimum and Maximum CPUUtilization. So if you could help me understand the output. it would be of great help to me

THANK YOU
Arun
Helpful? Yes  No 
Great Plugin
by drodriguez, December 31, 2013
great plugin, but i have a trouble. it works perfectly in terminal but when i configure it in nagios always show null in status information. what is going wrong?. thx
Owner's Reply:

Hi,

First of all thanks for using our Nagios plugin and helping us improving it.

Could you run the plugin as nagios user to get more detailed information and help troublshot the problem?

Please, feel free to contact me: fred@secludit.com
/fred


1 of 1 found this review helpful.
Helpful? Yes 1 No 0
For the Cloutomate issue
by Israel.Ochoa, November 30, 2013
gem install CloudyScripts
mkdir /etc/cloutomate/
ssh-keygen -f /etc/cloutomate/cloutomate.pem
Enter blank passphrase
chown nagios:nagios cloutomate.pem
0 of 1 found this review helpful.
Helpful? Yes  No 1
Excellent plugin!
by bsilverwood, October 31, 2013
I was able to get this implemented VERY quickly.

My only question is this: How would you set this up if you are using two different regions? I tried just making a second copy of the file, but this appears to not work from within Nagios, though I can run the ruby script from the command line and get proper output.
Helpful? Yes  No 
really good job
by 5c077yP, October 31, 2013
Hey the plugin is great,
i'm using it for my vpc instances - for the address argument i'm using the aws region and it works perfectly.

Please fix the hard-coded .pem file to be configurable ...
One can create the rsa files via openssl genrsa ...

Thanks a lot
Helpful? Yes  No 
Very Useful
by psattler22, August 31, 2013
A very useful plug-in that allows us to add CloudWatch metrics to our existing monitoring dashboard.
Helpful? Yes  No 
best agentless script to monitor EC2 and RDS
by call_krushna, August 31, 2013
This is excellent script to monitor EC2 and RDS .The
best feature is we can check free storage space in RDS .
Helpful? Yes  No 
excellent plugin
by hyjalsoul, July 31, 2013
Need to install amazon-ec2 gem, but other than that, setup is easy and it works great! Very good plugin for nagios to monitor AWS metrics
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Does most of the job
by Maquis196, July 31, 2013
I needed this more for ELB checking then ec2 checking, does the ec2 checking quite well from what I've seen and relatively easy to set up.

However I will ask, is there a way of finegraining elb metrics? At the moment it just uses the entire region, can the -I flag be used for the elb dns entry?

Cheers.
Owner's Reply:

Hi,

You should be able to check your ELB using the '-L' option that allows to retrieve ELB metrics such as Latency, RequestCount, HealthyHostCount, and UnHealthyHostCount.

If you have problem or need more information, feel free to contact me using "Contact Owner".

Best regards,
Fred


1 of 1 found this review helpful.
Helpful? Yes 1 No 0
not working...
by xoroz, May 31, 2013
Could not use the encrypt part
There is a hard code to /etc/cloutomate/cloutomate.pem what is that?
I always get the error:
Exception `NameError' at encrypt_credentials.rb:91 - uninitialized constant Digest::SHA256

Can you help me out?
Owner's Reply:

Hi Xorox,

The hardcoded file in encrypt_credentials.rb is a file containing a RSA private key in our system.

Could you please send me more information on how you configure the plugin and the full output of the plugin?

Please, feel free to contact me.
Fred


1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Great Script
by ianmen, December 31, 2012
Great plugin. I now can check my amazon instance with nagios ! The ability to see what's going on on all my instances is just great.
1 of 1 found this review helpful.
Helpful? Yes 1 No 0
great idea
by techlunacy, September 30, 2012
just to let people know it needs the amazon-ec2 gem installed to get it working as advertised and a little bit of work done to the rds monitoring to account for api changes
4 of 4 found this review helpful.
Helpful? Yes 4 No 0
Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4.3 (37)
Favorites
6
Views
156,499