-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add check for cpu-balance on RDS #218
Open
ghost
wants to merge
1
commit into
sensu-plugins:master
Choose a base branch
from
unknown repository
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,8 @@ | |
|
||
**check-kms-key.rb** | ||
|
||
**check-rds-cpu_balance.rb** | ||
|
||
**check-rds-events.rb** | ||
|
||
**check-rds-pending.rb** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#! /usr/bin/env ruby | ||
# | ||
# check-rds-cpu_balance | ||
# | ||
# DESCRIPTION: | ||
# This plugin retrieves the value of the cpu balance for RDS instance | ||
# | ||
# OUTPUT: | ||
# plain-text | ||
# | ||
# PLATFORMS: | ||
# Linux | ||
# | ||
# DEPENDENCIES: | ||
# gem: aws-sdk | ||
# gem: sensu-plugin | ||
# | ||
# USAGE: | ||
# ./check-rds-cpu_balance -c 20 | ||
# | ||
# NOTES: | ||
# Based on check-ec2-cpu_balance.rb script (Shane Starcher) | ||
# | ||
# LICENSE: | ||
# Released under the same terms as Sensu (the MIT license); see LICENSE | ||
# for details. | ||
# | ||
|
||
require 'sensu-plugins-aws' | ||
require 'sensu-plugin/check/cli' | ||
require 'aws-sdk' | ||
|
||
class RDSCpuBalance < Sensu::Plugin::Check::CLI | ||
include Common | ||
|
||
option :critical, | ||
description: 'Trigger a critical when value is below VALUE', | ||
short: '-c VALUE', | ||
long: '--critical VALUE', | ||
proc: proc(&:to_f), | ||
required: true | ||
|
||
option :warning, | ||
description: 'Trigger a warning when value is below VALUE', | ||
short: '-w VALUE', | ||
long: '--warning VALUE', | ||
proc: proc(&:to_f) | ||
|
||
option :aws_region, | ||
short: '-r R', | ||
long: '--region REGION', | ||
description: 'AWS region', | ||
default: 'us-east-1' | ||
|
||
def data(instance) | ||
client = Aws::CloudWatch::Client.new | ||
stats = 'Average' | ||
period = 60 | ||
resp = client.get_metric_statistics( | ||
namespace: 'AWS/RDS', | ||
metric_name: 'CPUCreditBalance', | ||
dimensions: [{ | ||
name: 'DBInstanceIdentifier', | ||
value: instance | ||
}], | ||
start_time: Time.now - period * 10, | ||
end_time: Time.now, | ||
period: period, | ||
statistics: [stats] | ||
) | ||
|
||
return resp.datapoints.first.send(stats.downcase) unless resp.datapoints.first.nil? | ||
end | ||
|
||
def run | ||
rds = Aws::RDS::Client.new | ||
instances = rds.describe_db_instances | ||
|
||
messages = "\n" | ||
level = 0 | ||
instances.db_instances.each do |db_instance| | ||
next unless db_instance.db_instance_class.start_with? 'db.t2.' | ||
id = db_instance.db_instance_identifier | ||
result = data id | ||
unless result.nil? | ||
if result < config[:critical] | ||
level = 2 | ||
messages << "#{id} is below critical threshold [#{result} < #{config[:critical]}]\n" | ||
elsif config[:warning] && result < config[:warning] | ||
level = 1 if level == 0 | ||
messages << "#{id} is below warning threshold [#{result} < #{config[:warning]}]\n" | ||
end | ||
end | ||
end | ||
ok messages if level == 0 | ||
warning messages if level == 1 | ||
critical messages if level == 2 | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like this broken out as a param that we can check against a regex. My motivation is to not have to rewrite the plugin when t3's come out. It should ideally take a comma separated list and generate an array of regexes to do. Minimally a single regex exposed seems like the min requirement to not make this throw away when amazon bumps families. This unblocks user when it does break without waiting for a hotfix and release.