Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Check_AWS_CloudWatch_metrics

Current Version
6.4.44
Last Release Date
2016-10-29
Compatible With
  • Nagios 3.x
  • Nagios XI
Owner
License
Apache
Hits
156568
Files:
FileDescription
check_cloudwatch_status-6.4.44.rbThe ruby script that retrieve the metric from AWS EC2, ELB or RDS.
check_cloudwatch_status.cfgThe definition of the nagios command.
sample_service.cfgSample of use for retrieving CPU usage of an instance on Amazon EC2.
encrypt_credentials.rbRuby script that encrypts Amazon Web Services Credentials.
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
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
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)
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
byIwahashi, December 19, 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
byerwinxiao, November 16, 2018
0 of 1 people found this review helpful
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')".
Are we able to access CloudWatch Metrics in Nagios via a proxy ?
If, not what changes do we need to make ?
byrubenc, March 23, 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.
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
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
bysachin, July 4, 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.
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
byakaydinb, November 6, 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?
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?
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,

byrsrajesh, December 15, 2014
1 of 1 people found this review helpful
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!
byjohnc10uk, June 5, 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
bymaglub, May 20, 2014
1 of 1 people found this review helpful
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.
byLijiman, April 11, 2014
1 of 1 people found this review helpful
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.
by, March 6, 2014
1 of 1 people found this review helpful
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.
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
bydrodriguez, December 3, 2013
1 of 1 people found this review helpful
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

byIsrael.Ochoa, November 21, 2013
0 of 1 people found this review helpful
gem install CloudyScripts
mkdir /etc/cloutomate/
ssh-keygen -f /etc/cloutomate/cloutomate.pem
Enter blank passphrase
chown nagios:nagios cloutomate.pem
Page 1 of 2