riemann-aws 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53369cc4951c585ad4512b0f5cb8787fc62afc30
4
- data.tar.gz: 1b8d9e2dce92e426dd0f3776caef75b3b2ab25de
3
+ metadata.gz: 199a0f07d158b41eb67f84586294c9814d5b5681
4
+ data.tar.gz: 0d7f7526f9dac21f0b9197c610861bc4a2f82490
5
5
  SHA512:
6
- metadata.gz: 8833446b2ac85047da34dbdaa2d2a4e2f8e1fe798b0ec6ad682739dd8af15ef1d7948c551e2a0568a03ef01208b4134b8d263af6eb685ef91612952fd2bf9dce
7
- data.tar.gz: 2bd11a72ed228865e285db7bc0ea05e4eeb47633f4a5adac002f35856f99b96c2363217f66dbe91381dea8a92142a0ccb2c142f92765e5b4c4155b87b88f0026
6
+ metadata.gz: fb5e093683424c54ebb2c52183a9770e40346cfadfbcdf566b2535e5acd575a6fc1f7c53119248810697568b9461dfb8f0e7c0ad9c869d2e9e1dfebbc5feb6bc
7
+ data.tar.gz: 0bceced5e54574f926ffd8449196f2bafafb083d7803361e330f513167ea73289344da2dd43fb568cd33319efb794d1ab84d2371450d0cb67f827cfea9e3181b
data/README.md CHANGED
@@ -23,7 +23,7 @@ riemann-aws-billing --help
23
23
  riemann-aws-rds-status --help
24
24
  ```
25
25
 
26
- ### Riemann AWS SQS Satus
26
+ ### Riemann AWS SQS Status
27
27
 
28
28
  ```
29
29
  riemann-aws-sqs-status --help
@@ -40,3 +40,15 @@ riemann-aws-status --help
40
40
  ```
41
41
  riemann-elb-metrics --help
42
42
  ```
43
+
44
+ ### Riemann S3 Status by asking Cloudwatch
45
+
46
+ ```
47
+ riemann-s3-status --help
48
+ ```
49
+
50
+ ### Riemann S3 Count by listing objects
51
+
52
+ ```
53
+ riemann-s3-list --help
54
+ ```
@@ -25,7 +25,15 @@ class Riemann::Tools::AWSBilling
25
25
  Fog.credential = opts[:fog_credential].to_sym
26
26
  @cloudwatch = Fog::AWS::CloudWatch.new
27
27
  else
28
- @cloudwatch = Fog::AWS::CloudWatch.new(:aws_secret_access_key => opts[:secret_key], :aws_access_key_id => opts[:access_key])
28
+ if opts.has_key?('secret_key') and opts.has_key?('access_key')
29
+ creds = {
30
+ :aws_secret_access_key => opts[:secret_key],
31
+ :aws_access_key_id => opts[:access_key]
32
+ }
33
+ else
34
+ creds = { :use_iam_profile => true }
35
+ end
36
+ @cloudwatch = Fog::AWS::CloudWatch.new(creds)
29
37
  @start_time = (Time.now.utc - opts[:time_start]).iso8601
30
38
  @end_time = (Time.now.utc - opts[:time_end]).iso8601
31
39
  end
@@ -17,9 +17,16 @@ class Riemann::Tools::AWS
17
17
  opt :dbinstance_identifier, "DBInstanceIdentifier", :type => String
18
18
  def initialize
19
19
  abort "FATAL: specify a DB instance name, see --help for usage" unless opts[:dbinstance_identifier]
20
- @cloudwatch = Fog::AWS::CloudWatch.new(:aws_access_key_id => opts[:access_key],
21
- :aws_secret_access_key => opts[:secret_key],
22
- :region => opts[:region])
20
+ if opts[:access_key] and opts[:secret_key]
21
+ creds = {
22
+ :aws_access_key_id => opts[:access_key],
23
+ :aws_secret_access_key => opts[:secret_key]
24
+ }
25
+ else
26
+ creds = { :use_iam_profile => true }
27
+ end
28
+ creds['region'] = opts[:region]
29
+ @cloudwatch = Fog::AWS::CloudWatch.new(creds)
23
30
  end
24
31
 
25
32
  def tick
@@ -27,7 +34,6 @@ class Riemann::Tools::AWS
27
34
  ['DatabaseConnections', 'FreeableMemory', 'FreeStorageSpace', 'NetworkReceiveThroughput', 'NetworkTransmitThroughput', 'ReadThroughput', 'CPUUtilization'].each do |metric|
28
35
  result = @cloudwatch.get_metric_statistics({"Namespace" => 'AWS/RDS', "MetricName" => "#{metric}", "Statistics" => 'Average', "Dimensions" => [{"Name" => "DBInstanceIdentifier", "Value" => "#{opts[:dbinstance_identifier]}"}], "StartTime" => (time-120).to_time.iso8601, "EndTime" => time.to_time.iso8601, "Period" => 60})
29
36
  metricsResult = result.data[:body]['GetMetricStatisticsResult']
30
- puts JSON.dump(metricsResult)
31
37
  if (metricsResult['Datapoints'].length>0)
32
38
  datapoint = metricsResult['Datapoints'][0]
33
39
  ev = {:metric => datapoint['Average'],
@@ -44,4 +50,4 @@ class Riemann::Tools::AWS
44
50
  end
45
51
  end
46
52
 
47
- Riemann::Tools::AWS.run
53
+ Riemann::Tools::AWS.run
@@ -13,9 +13,16 @@ class Riemann::Tools::AWS
13
13
  opt :region, "AWS region", :type => String, :default => 'us-east-1'
14
14
  opt :queue, "SQS Queue name", :type => String
15
15
  def initialize
16
- @sqs = Fog::AWS::SQS.new(:aws_access_key_id => opts[:access_key],
17
- :aws_secret_access_key => opts[:secret_key],
18
- :region => opts[:region])
16
+ if opts.has_key?('access_key') and opts.has_key?('secret_key')
17
+ creds = {
18
+ :aws_access_key_id => opts[:access_key],
19
+ :aws_secret_access_key => opts[:secret_key]
20
+ }
21
+ else
22
+ creds = { :use_iam_profile => true }
23
+ end
24
+ creds['region'] = opts[:region]
25
+ @sqs = Fog::AWS::SQS.new(creds)
19
26
  response = @sqs.list_queues({'QueueNamePrefix' => opts[:queue]})
20
27
  @queue_url = response[:body]['QueueUrls'].first
21
28
  end
@@ -17,10 +17,17 @@ class Riemann::Tools::AWS
17
17
  opt :event_warning, "Number of days before event. Defaults to nil (i.e. when the event appears)", :default => nil
18
18
 
19
19
  def initialize
20
- @compute = Fog::Compute.new(:aws_access_key_id => opts[:access_key],
21
- :aws_secret_access_key => opts[:secret_key],
22
- :region => opts[:region],
23
- :provider => 'AWS')
20
+ if opts.has_key?('secret_key') and opts.has_key?('access_key')
21
+ creds = {
22
+ :aws_secret_access_key => opts[:secret_key],
23
+ :aws_access_key_id => opts[:access_key]
24
+ }
25
+ else
26
+ creds = { :use_iam_profile => true }
27
+ end
28
+ creds['region'] = opts[:region]
29
+ creds['provider'] = 'AWS'
30
+ @compute = Fog::Compute.new(creds)
24
31
  end
25
32
 
26
33
  def tick
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'riemann/tools'
4
+
5
+ $0 = __FILE__
6
+
7
+ class Riemann::Tools::S3Metrics
8
+ include Riemann::Tools
9
+ require 'fog'
10
+ require 'time'
11
+
12
+ opt :fog_credentials_file, "Fog credentials file", :type => String
13
+ opt :fog_credential, "Fog credentials to use", :type => String
14
+ opt :aws_access, "AWS Access Key", :type => String
15
+ opt :aws_secret, "AWS Secret Key", :type => String
16
+ opt :aws_region, "AWS Region", :type => String, :default => "eu-west-1"
17
+ opt :buckets, "Buckets to pull metrics from, multi=true", :type => String, :multi => true, :required => true
18
+ opt :max_objects, "Max number of objects to list before stopping to save bandwidth", :default => -1
19
+
20
+
21
+ def tick
22
+ if options[:fog_credentials_file]
23
+ Fog.credentials_path = options[:fog_credentials_file]
24
+ Fog.credential = options[:fog_credential].to_sym
25
+ connection = Fog::Storage.new
26
+ else
27
+ if options[:aws_access] && options[:aws_secret]
28
+ connection = Fog::Storage.new({
29
+ :provider => "AWS",
30
+ :aws_access_key_id => options[:aws_access],
31
+ :aws_secret_access_key => options[:aws_secret],
32
+ :region => options[:aws_region]
33
+ })
34
+ else
35
+ connection = Fog::Storage.new({
36
+ :provider => "AWS",
37
+ :use_iam_profile => true,
38
+ :region => options[:aws_region]
39
+ })
40
+ end
41
+ end
42
+
43
+ options[:buckets].each do |bucket|
44
+
45
+ directory = connection.directories.get(bucket)
46
+ count = 0
47
+ directory.files.each do |file|
48
+ count = count +1
49
+ if (options[:max_objects]>0 && count>options[:max_objects])
50
+ break
51
+ end
52
+ end
53
+ if (options[:max_objects]>0 && count>options[:max_objects])
54
+ event = event(bucket, "objectCount", count, "count was bigger than threshold #{options[:max_objects]}", "warning")
55
+ report(event)
56
+ else
57
+ event = event(bucket, "objectCount", count, "All objects counted, threshold=#{options[:max_objects]}", "ok")
58
+ report(event)
59
+ end
60
+ end
61
+ end
62
+
63
+ private
64
+ def event(bucket, label, metric, description, severity)
65
+ event = {
66
+ host: "bucket_#{bucket}",
67
+ service: "s3.#{label}",
68
+ ttl: 300,
69
+ description: "#{bucket} #{description}",
70
+ tags: ["s3_metrics"],
71
+ metric: metric,
72
+ state: severity
73
+ }
74
+ end
75
+ end
76
+
77
+ Riemann::Tools::S3Metrics.run
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'riemann/tools'
4
+
5
+ $0 = __FILE__
6
+
7
+ class Riemann::Tools::S3Metrics
8
+ include Riemann::Tools
9
+ require 'fog'
10
+ require 'time'
11
+
12
+ opt :fog_credentials_file, "Fog credentials file", :type => String
13
+ opt :fog_credential, "Fog credentials to use", :type => String
14
+ opt :aws_access, "AWS Access Key", :type => String
15
+ opt :aws_secret, "AWS Secret Key", :type => String
16
+ opt :aws_region, "AWS Region", :type => String, :default => "eu-west-1"
17
+ opt :buckets, "Buckets to pull metrics from, multi=true", :type => String, :multi => true, :required => true
18
+ opt :statistic, "Statistic to retrieve, multi=true, e.g. --statistic=Average --statistic=Maximum", :type => String, :multi => true, :required => true
19
+
20
+
21
+ def base_metrics
22
+ # get last 60 seconds
23
+ start_time = (Time.now.utc - 3600 * 24 * 1).iso8601
24
+ end_time = Time.now.utc.iso8601
25
+
26
+ # The base query that all metrics would get
27
+ metric_base = {
28
+ "Namespace" => "AWS/S3",
29
+ "StartTime" => start_time,
30
+ "EndTime" => end_time,
31
+ "Period" => 3600,
32
+ "MetricName" => "NumberOfObjects",
33
+ }
34
+
35
+ metric_base
36
+ end
37
+
38
+
39
+ def tick
40
+ if options[:fog_credentials_file]
41
+ Fog.credentials_path = options[:fog_credentials_file]
42
+ Fog.credential = options[:fog_credential].to_sym
43
+ connection = Fog::AWS::CloudWatch.new
44
+ else
45
+ if options[:aws_access] && options[:aws_secret]
46
+ connection = Fog::AWS::CloudWatch.new({
47
+ :aws_access_key_id => options[:aws_access],
48
+ :aws_secret_access_key => options[:aws_secret],
49
+ :region => options[:aws_region]
50
+ })
51
+ else
52
+ connection = Fog::AWS::CloudWatch.new({
53
+ :use_iam_profile => true,
54
+ :region => options[:aws_region]
55
+ })
56
+ end
57
+ end
58
+
59
+ options[:statistic].each do |statistic|
60
+ options[:buckets].each do |bucket|
61
+
62
+ metric_base_options = base_metrics
63
+ metric_base_options["Statistics"] = statistic
64
+ metric_base_options["Dimensions"] = [
65
+ {"Name" => "BucketName", "Value" => bucket},
66
+ {"Name" => "StorageType", "Value" => "AllStorageTypes"}]
67
+
68
+ result = connection.get_metric_statistics(metric_base_options)
69
+ if result.body["GetMetricStatisticsResult"]["Datapoints"].empty?
70
+ next
71
+ end
72
+ result.body["GetMetricStatisticsResult"]["Datapoints"][0].keys.sort.each do |stat_type|
73
+ next if stat_type == "Unit"
74
+ next if stat_type == "Timestamp"
75
+
76
+ unit = result.body["GetMetricStatisticsResult"]["Datapoints"][0]["Unit"]
77
+ metric = result.body["GetMetricStatisticsResult"]["Datapoints"][0][stat_type]
78
+ event = event(bucket, result.body["GetMetricStatisticsResult"]["Label"], stat_type, unit, metric)
79
+ report(event)
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+ def event(bucket, label, metric_type, stat_type, metric, unit=nil)
87
+ event = {
88
+ host: "bucket_#{bucket}",
89
+ service: "s3.#{label}.#{metric_type}.#{stat_type}",
90
+ ttl: 300,
91
+ description: "#{bucket} #{metric_type} #{stat_type} (#{unit})",
92
+ tags: ["s3_metrics"],
93
+ metric: metric
94
+ }
95
+ end
96
+ end
97
+
98
+ Riemann::Tools::S3Metrics.run
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Kingsbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riemann-tools
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.8
19
+ version: 0.2.11
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.8
26
+ version: 0.2.11
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fog
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -60,6 +60,8 @@ executables:
60
60
  - riemann-aws-sqs-status
61
61
  - riemann-aws-status
62
62
  - riemann-elb-metrics
63
+ - riemann-s3-list
64
+ - riemann-s3-status
63
65
  extensions: []
64
66
  extra_rdoc_files: []
65
67
  files:
@@ -70,6 +72,8 @@ files:
70
72
  - bin/riemann-aws-sqs-status
71
73
  - bin/riemann-aws-status
72
74
  - bin/riemann-elb-metrics
75
+ - bin/riemann-s3-list
76
+ - bin/riemann-s3-status
73
77
  homepage: https://github.com/riemann/riemann-tools
74
78
  licenses:
75
79
  - MIT
@@ -90,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
94
  version: '0'
91
95
  requirements: []
92
96
  rubyforge_project: riemann-aws
93
- rubygems_version: 2.4.5
97
+ rubygems_version: 2.5.2
94
98
  signing_key:
95
99
  specification_version: 4
96
100
  summary: Submits AWS stats to riemann.