logstash-input-cloudwatch 0.1.0 → 0.2.0

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: bd905939912c0289d1f422f637b80f0bd4abc723
4
- data.tar.gz: 7da492dea138521b8b92e2756ffd3d4be2cfe615
3
+ metadata.gz: 7ca8079400562640f3ccc4d9cb2db97e79f0f1ee
4
+ data.tar.gz: ac7eaf6358e575ca75b70b8897f27bfa95db7436
5
5
  SHA512:
6
- metadata.gz: 09eadecfe87039ba40806927cd530e8a0c1f838e95b1d5ae3c69a784120173af75023c5f7436b5bceac6e91491dfe77018cd4c1d1f6706a609e473778c9ba350
7
- data.tar.gz: 91f39d44ffb49e98a3ccfd855a5e01606728b9a0b4baa714ee23d6f0ce3e738853c1eaf51c10b8016329d4d355afd8bab2275c43e40f7741b42a0e2b9bc4cf12
6
+ metadata.gz: d2e9ffb25fac13a85a12dc7771b3ab325ab0ad42d9431fc902d1e92b1739e22b3e24f453f616499a94add388f50a98e0d2732a2d6bf7ca7767fbd5810155c563
7
+ data.tar.gz: 5379f1f46bf773a53c996fe07acad735aa9ba2edf3e574c18bd27641bb561d51f888196b5d1cc7f487817f27e112fdcff27883ac7ee4c47e659735ee4367b3b9
@@ -25,7 +25,7 @@ class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base
25
25
  # The default, `900`, means check every 15 minutes
26
26
  config :interval, :validate => :number, :default => (60 * 15)
27
27
 
28
- # Set the granularity of the retruned datapoints.
28
+ # Set the granularity of the returned datapoints.
29
29
  #
30
30
  # Must be at least 60 seconds and in multiples of 60.
31
31
  config :period, :validate => :number, :default => 60
@@ -54,6 +54,13 @@ class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base
54
54
  # takes precedence.
55
55
  config :tag_values, :validate => :array
56
56
 
57
+ # Set how frequently the available instances should be refreshed. Making it less
58
+ # than `interval` doesn't really make sense. This cannot be used along with the
59
+ # `instances` setting.
60
+ #
61
+ # The default, -1, means never refresh
62
+ config :instance_refresh, :validate => :number, :default => -1
63
+
57
64
  # Specify the metrics to fetch for each instance
58
65
  config :metrics, :validate => :array, :default => [ 'CPUUtilization', 'DiskReadOps', 'DiskWriteOps', 'NetworkIn', 'NetworkOut' ]
59
66
 
@@ -70,14 +77,29 @@ class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base
70
77
  require "aws-sdk"
71
78
  AWS.config(:logger => @logger)
72
79
 
80
+ if @instances
81
+ raise LogStash::ConfigurationError, 'Should not specify both `instance_refresh` and `instances`' if @instance_refresh > 0
82
+ raise LogStash::ConfigurationError, 'Should not specify both `tag_name` and `instances`' unless @tag_name.nil?
83
+ raise LogStash::ConfigurationError, 'Should not specify both `tag_values` and `instances`' unless @tag_values.nil?
84
+ else
85
+ raise LogStash::ConfigurationError, 'Both `tag_name` and `tag_values` need to be specified if no `instances` are specified' if @tag_name.nil? || @tag_values.nil?
86
+ end
87
+
73
88
  @cloudwatch = AWS::CloudWatch::Client.new(aws_options_hash)
74
89
  @ec2 = AWS::EC2::Client.new(aws_options_hash)
75
-
90
+ @last_check = Time.now
76
91
  end # def register
77
92
 
78
93
  def run(queue)
79
94
  Stud.interval(@interval) do
80
95
  @logger.debug('Polling CloudWatch API')
96
+ # Set up the instance_refresh check
97
+ if @instance_refresh > 0
98
+ @instances = nil if (Time.now - @last_check) > @instance_refresh
99
+ @last_check = Time.now
100
+ end
101
+
102
+ # Poll the instances
81
103
  instance_ids.each do |instance|
82
104
  metrics(instance).each do |metric|
83
105
  opts = options(metric, instance)
@@ -132,7 +154,6 @@ class LogStash::Inputs::CloudWatch < LogStash::Inputs::Base
132
154
  def instance_ids
133
155
  return @instances unless @instances.nil?
134
156
 
135
- raise('Both the tag_name and tag_values needs to be set if no instances are specified') if @tag_name.nil? || @tag_values.nil?
136
157
  @instances = []
137
158
  @ec2.describe_instances(filters: [ { name: "tag:#{@tag_name}", values: @tag_values } ])[:reservation_set].each do |reservation|
138
159
  @logger.debug reservation
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-cloudwatch'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Retrieve stats from AWS CloudWatch."
6
6
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
metadata CHANGED
@@ -1,112 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-cloudwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgens du Toit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-14 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.4.0
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 2.0.0
23
- requirement: !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - '>='
27
+ - - ">="
26
28
  - !ruby/object:Gem::Version
27
29
  version: 1.4.0
28
- - - <
30
+ - - "<"
29
31
  - !ruby/object:Gem::Version
30
32
  version: 2.0.0
31
- prerelease: false
32
- type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: logstash-codec-plain
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - '>='
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
35
  requirement: !ruby/object:Gem::Requirement
41
36
  requirements:
42
- - - '>='
37
+ - - ">="
43
38
  - !ruby/object:Gem::Version
44
39
  version: '0'
45
- prerelease: false
46
40
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: stud
41
+ prerelease: false
49
42
  version_requirements: !ruby/object:Gem::Requirement
50
43
  requirements:
51
- - - '>='
44
+ - - ">="
52
45
  - !ruby/object:Gem::Version
53
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: stud
54
49
  requirement: !ruby/object:Gem::Requirement
55
50
  requirements:
56
- - - '>='
51
+ - - ">="
57
52
  - !ruby/object:Gem::Version
58
53
  version: '0'
59
- prerelease: false
60
54
  type: :runtime
61
- - !ruby/object:Gem::Dependency
62
- name: logstash-mixin-aws
55
+ prerelease: false
63
56
  version_requirements: !ruby/object:Gem::Requirement
64
57
  requirements:
65
- - - '>='
58
+ - - ">="
66
59
  - !ruby/object:Gem::Version
67
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-mixin-aws
68
63
  requirement: !ruby/object:Gem::Requirement
69
64
  requirements:
70
- - - '>='
65
+ - - ">="
71
66
  - !ruby/object:Gem::Version
72
67
  version: '0'
73
- prerelease: false
74
68
  type: :runtime
75
- - !ruby/object:Gem::Dependency
76
- name: aws-sdk
69
+ prerelease: false
77
70
  version_requirements: !ruby/object:Gem::Requirement
78
71
  requirements:
79
- - - '>='
72
+ - - ">="
80
73
  - !ruby/object:Gem::Version
81
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: aws-sdk
82
77
  requirement: !ruby/object:Gem::Requirement
83
78
  requirements:
84
- - - '>='
79
+ - - ">="
85
80
  - !ruby/object:Gem::Version
86
81
  version: '0'
87
- prerelease: false
88
82
  type: :runtime
89
- - !ruby/object:Gem::Dependency
90
- name: logstash-devutils
83
+ prerelease: false
91
84
  version_requirements: !ruby/object:Gem::Requirement
92
85
  requirements:
93
- - - '>='
86
+ - - ">="
94
87
  - !ruby/object:Gem::Version
95
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: logstash-devutils
96
91
  requirement: !ruby/object:Gem::Requirement
97
92
  requirements:
98
- - - '>='
93
+ - - ">="
99
94
  - !ruby/object:Gem::Version
100
95
  version: '0'
101
- prerelease: false
102
96
  type: :development
103
- description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: This gem is a logstash plugin required to be installed on top of the
104
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
105
+ a stand-alone program
104
106
  email: jrgns@jadeit.co.za
105
107
  executables: []
106
108
  extensions: []
107
109
  extra_rdoc_files: []
108
110
  files:
109
- - .gitignore
111
+ - ".gitignore"
110
112
  - CHANGELOG.md
111
113
  - DEVELOPER.md
112
114
  - Gemfile
@@ -114,7 +116,6 @@ files:
114
116
  - README.md
115
117
  - Rakefile
116
118
  - lib/logstash/inputs/cloudwatch.rb
117
- - lib/logstash/inputs/test.rb
118
119
  - logstash-input-cloudwatch.gemspec
119
120
  - spec/inputs/cloudwatch_spec.rb
120
121
  homepage: http://jadeit.co.za
@@ -123,24 +124,24 @@ licenses:
123
124
  metadata:
124
125
  logstash_plugin: 'true'
125
126
  logstash_group: input
126
- post_install_message:
127
+ post_install_message:
127
128
  rdoc_options: []
128
129
  require_paths:
129
130
  - lib
130
131
  required_ruby_version: !ruby/object:Gem::Requirement
131
132
  requirements:
132
- - - '>='
133
+ - - ">="
133
134
  - !ruby/object:Gem::Version
134
135
  version: '0'
135
136
  required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  requirements:
137
- - - '>='
138
+ - - ">="
138
139
  - !ruby/object:Gem::Version
139
140
  version: '0'
140
141
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.4.5
143
- signing_key:
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.6
144
+ signing_key:
144
145
  specification_version: 4
145
146
  summary: Retrieve stats from AWS CloudWatch.
146
147
  test_files:
@@ -1,95 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/inputs/base"
3
- require "logstash/namespace"
4
- require "logstash/plugin_mixins/aws_config"
5
- require 'pp'
6
- require 'logger'
7
-
8
- class LogStash::Inputs::Test < LogStash::Inputs::Base
9
- include LogStash::PluginMixins::AwsConfig
10
-
11
- config_name "cloudwatch"
12
-
13
- # If undefined, Logstash will complain, even if codec is unused.
14
- default :codec, "plain"
15
-
16
- public
17
- def aws_service_endpoint(region)
18
- {
19
- region: region
20
- }
21
- end
22
-
23
- public
24
- def register
25
- require "aws-sdk"
26
- AWS.config(:logger => Logger.new($stdout))
27
- AWS.config(:log_level => :debug)
28
-
29
- @interval = 60 * 15
30
- @region = 'eu-west-1'
31
- @namespace = 'AWS/EC2'
32
- @metrics = [ 'CPUUtilization' ]
33
- @period = 60
34
- @statistics = ["SampleCount", "Average", "Minimum", "Maximum", "Sum"]
35
- @tag_name = 'Managed'
36
- @tag_values = [ 'Yes' ]
37
-
38
- @cloudwatch = ::AWS::CloudWatch::Client.new(aws_options_hash)
39
- @ec2 = ::AWS::EC2::Client.new(aws_options_hash)
40
- end
41
-
42
- def tryit
43
- instance_ids.each do |instance|
44
- metrics(instance).each do |metric|
45
- opts = {
46
- namespace: @namespace,
47
- metric_name: metric,
48
- dimensions: [ { name: 'InstanceId', value: instance } ],
49
- start_time: (Time.now - @interval).iso8601,
50
- end_time: Time.now.iso8601,
51
- period: @period,
52
- statistics: @statistics
53
- }
54
- puts "#{instance} #{metric}"
55
- @cloudwatch.get_metric_statistics(opts)[:datapoints].each do |dp|
56
- puts dp.inspect
57
- # event = Logstash::Event.new(dp)
58
- # puts event.inspect
59
- # decorate(event)
60
- # queue << event
61
- end
62
- end
63
- end
64
- end
65
-
66
- def metrics(instance)
67
- metrics_available(instance) & @metrics
68
- end
69
-
70
- def instance_ids
71
- @instances = []
72
- @ec2.describe_instances(filters: [ { name: "tag:#{@tag_name}", values: @tag_values } ])[:reservation_set].each do |reservation|
73
- reservation[:instances_set].each do |instance|
74
- @instances.push instance[:instance_id]
75
- end
76
- end
77
- @instances
78
- end
79
-
80
- def metrics_available(instance)
81
- opts = { namespace: @namespace, dimensions: [ { name: 'InstanceId', value: instance } ] }
82
- results = []
83
- @cloudwatch.list_metrics(opts)[:metrics].each do |metrics|
84
- results.push metrics[:metric_name]
85
- end
86
- results
87
- end
88
- end
89
-
90
- puts "Starting up"
91
- test = LogStash::Inputs::Test.new
92
- puts "Registering"
93
- test.register
94
- puts "Get the instances"
95
- test.tryit