<commit_before>#!/usr/bin/env ruby
## grab metrics from AWS cloudwatch 
### <NAME>
### 2012-07-10
### gem install fog  --no-ri --no-rdoc
 
$:.unshift File.join(File.dirname(__FILE__), *%w[.. conf])
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])

require 'config'
require 'Sendit'
require 'rubygems'
require 'fog'
require 'json'

if ARGV.length != 1
        puts "I need one argument. The RDS instance name"
        exit 1
end

dimensionId = ARGV[0]

#AWS cloudwatch stats seem to be a minute or so behind

startTime = Time.now.utc-180
endTime  = Time.now.utc-120


metricNames = {	"CPUUtilization" 	=> "Percent", 
		"DatabaseConnections" 	=> "Count",
		"FreeStorageSpace" 	=> "Bytes",
		"ReadIOPS"		=> "Count/Second",
 		"ReadLatency"		=> "Seconds",
		"ReadThroughput"	=> "Bytes/Second",
		"WriteIOPS"		=> "Count/Second",
 		"WriteLatency"		=> "Seconds",
		"WriteThroughput"	=> "Bytes/Second",
	}

statisticTypes = 'Average'

cloudwatch = Fog::AWS::CloudWatch.new(:aws_secret_access_key => $awssecretkey, :aws_access_key_id => $awsaccesskey)


metricNames.each do |metricName, unit|

  response = cloudwatch.get_metric_statistics({
           'Statistics' => 'Average',
           'StartTime' =>  startTime.iso8601,
           'EndTime'    => endTime.iso8601, 
	   'Period'     => 60, 
           'Unit'       => unit,
	   'MetricName' => metricName, 
	   'Namespace'  => 'AWS/RDS',
	   'Dimensions' => [{
	                'Name'  => 'DBInstanceIdentifier', 
	                'Value' => dimensionId 
			}]
           }).body['GetMetricStatisticsResult']['Datapoints']

  metricpath = "AWScloudwatch.RDS." + dimensionId + "." + metricName 
  metricvalue = response.first["Average"]
  metrictimestamp = endTime.to_i.to_s

  Sendit metricpath, metricvalue, metrictimestamp
end
<commit_msg>If no database is specified, get metrics for all<commit_after>#!/usr/bin/env ruby
## grab metrics from AWS cloudwatch 
### <NAME>
### 2012-07-10
### gem install fog  --no-ri --no-rdoc
### if no argument is specified get metrics for all databases
### if a database name is specified as an argument then only show that database
 
$:.unshift File.join(File.dirname(__FILE__), *%w[.. conf])
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])

#require '/opt/vacuumetrix/conf/config.rb'
#require '/opt/vacuumetrix/lib/Sendit.rb'

require 'config'
require 'Sendit'
require 'rubygems'
require 'fog'
require 'json'

if ARGV.length == 1
  dimensionId = ARGV[0]
end


#AWS cloudwatch stats seem to be a minute or so behind

startTime = Time.now.utc-180
endTime  = Time.now.utc-120


metricNames = {	"CPUUtilization" 	=> "Percent", 
		"DatabaseConnections" 	=> "Count",
		"FreeStorageSpace" 	=> "Bytes",
		"ReadIOPS"		=> "Count/Second",
 		"ReadLatency"		=> "Seconds",
		"ReadThroughput"	=> "Bytes/Second",
		"WriteIOPS"		=> "Count/Second",
 		"WriteLatency"		=> "Seconds",
		"WriteThroughput"	=> "Bytes/Second",
	}

statisticTypes = 'Average'

rds = Fog::AWS::RDS.new(:aws_secret_access_key => $awssecretkey, :aws_access_key_id => $awsaccesskey)

if !dimensionId.nil?
  instance_list = rds.servers.get(dimensionId)
  cloudwatch = Fog::AWS::CloudWatch.new(:aws_secret_access_key => $awssecretkey, :aws_access_key_id => $awsaccesskey)

metricNames.each do |metricName, unit|

  response = cloudwatch.get_metric_statistics({
           'Statistics' => 'Average',
           'StartTime' =>  startTime.iso8601,
           'EndTime'    => endTime.iso8601, 
	   'Period'     => 60, 
           'Unit'       => unit,
	   'MetricName' => metricName, 
	   'Namespace'  => 'AWS/RDS',
	   'Dimensions' => [{
	                'Name'  => 'DBInstanceIdentifier', 
	                'Value' => dimensionId 
			}]
           }).body['GetMetricStatisticsResult']['Datapoints']

  metricpath = "AWScloudwatch.RDS." + dimensionId + "." + metricName 
  metricvalue = response.first["Average"]
  metrictimestamp = endTime.to_i.to_s

  Sendit metricpath, metricvalue, metrictimestamp
end
else
  instance_list = rds.servers.all

  instance_list.each do |i|
  cloudwatch = Fog::AWS::CloudWatch.new(:aws_secret_access_key => $awssecretkey, :aws_access_key_id => $awsaccesskey)

  dimensionId = i.id
  metricNames.each do |metricName, unit|

    response = cloudwatch.get_metric_statistics({
           'Statistics' => 'Average',
           'StartTime' =>  startTime.iso8601,
           'EndTime'    => endTime.iso8601, 
	   'Period'     => 60, 
           'Unit'       => unit,
	   'MetricName' => metricName, 
	   'Namespace'  => 'AWS/RDS',
	   'Dimensions' => [{
	                'Name'  => 'DBInstanceIdentifier', 
	                'Value' => dimensionId 
			}]
           }).body['GetMetricStatisticsResult']['Datapoints']

    metricpath = "AWScloudwatch.RDS." + dimensionId + "." + metricName 
    metricvalue = response.first["Average"]
    metrictimestamp = endTime.to_i.to_s

    Sendit metricpath, metricvalue, metrictimestamp
  end
end
end

{'fraction_non_alphanumeric': 0.14924766165107767, 'fraction_numerical': 0.012810085400569337, 'mean_word_length': 3.277391304347826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7450836', 'n_tokens_mistral': 1815, 'n_tokens_neox': 1663, 'n_words': 346}