fluent-plugin-cloudwatch_ya 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013 suz-lab
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = fluent-plugin-cloudwatch_ya
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to fluent-plugin-cloudwatch_ya
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 suz-lab. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,96 @@
1
+ module Fluent
2
+ require 'net/http'
3
+ require 'jsonpath'
4
+ require 'aws-sdk'
5
+ class CloudWatchYaOutput < TimeSlicedOutput
6
+
7
+ METRIC_DATA_MAX_NUM = 20
8
+ Fluent::Plugin.register_output('cloudwatch_ya', self)
9
+ config_param :aws_key_id, :string, :default => nil
10
+ config_param :aws_sec_key, :string, :default => nil
11
+ config_param :cloud_watch_endpoint, :string, :default => 'monitoring.ap-northeast-1.amazonaws.com'
12
+ config_param :namespace, :string
13
+
14
+ def configure(conf)
15
+ super
16
+ instance_id = Net::HTTP.get('169.254.169.254', '/1.0/meta-data/instance-id')
17
+ @metric_list = []
18
+ conf.elements.select {|element|
19
+ element.name == 'metric'
20
+ }.each do |metric|
21
+ dimensions_list = []
22
+ if not metric['outcast_no_dimension_metric'] == 'yes' then
23
+ dimensions_list << []
24
+ end
25
+ metric.elements.select {|element|
26
+ element.name == 'dimensions'
27
+ }.each do |dimensions|
28
+ dimension_list = []
29
+ dimensions.each do |dimension, value|
30
+ if dimension.start_with?("dimension") then
31
+ name_and_value = value.split("=")
32
+ dimension_list << { 'name' => name_and_value[0], 'value' => name_and_value[1] }
33
+ elsif dimension == 'instance_id' and value == 'yes' then
34
+ dimension_list << { 'name' => 'InstanceId', 'value' => instance_id }
35
+ elsif dimension == 'fluent_tag' and value == 'yes' then
36
+ dimension_list << { 'name' => 'FluentTag', 'value' => nil }
37
+ end
38
+ end
39
+ dimensions_list << dimension_list
40
+ end
41
+ @metric_list << {
42
+ 'metric_name' => metric['metric_name'],
43
+ 'value_key' => metric['value_key'],
44
+ 'unit' => metric['unit'],
45
+ 'dimensions_list' => dimensions_list
46
+ }
47
+ end
48
+ $log.debug(@metric_list.inspect)
49
+ end
50
+
51
+ def format(tag, time, record)
52
+ record["tag"] = tag
53
+ record["timestamp"] = Time.at(time).iso8601
54
+ record.to_msgpack
55
+ end
56
+
57
+ def write(chunk)
58
+ metric_data = []
59
+ chunk.msgpack_each do |record|
60
+ @metric_list.each do |metric|
61
+ value = JsonPath.new(metric['value_key']).first(record)
62
+ if not value.nil? then
63
+ metric['dimensions_list'].each do |dimensions|
64
+ dimensions.each do |dimension_list|
65
+ if dimension_list['name'] == 'FluentTag' then
66
+ dimension_list['value'] = record['tag'];
67
+ end
68
+ end
69
+ metric_data << {
70
+ :metric_name => metric['metric_name'],
71
+ :timestamp => record['timestamp'],
72
+ :value => value,
73
+ :unit => metric['unit'],
74
+ :dimensions => dimensions
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ AWS.config(
81
+ :access_key_id => @aws_key_id,
82
+ :secret_access_key => @aws_sec_key,
83
+ :cloud_watch_endpoint => @cloud_watch_endpoint
84
+ )
85
+ cloud_watch = AWS::CloudWatch.new
86
+ until metric_data.length <= 0 do
87
+ $log.debug(metric_data.slice(0, METRIC_DATA_MAX_NUM).inspect)
88
+ cloud_watch.put_metric_data(
89
+ :namespace => @namespace,
90
+ :metric_data => metric_data.slice!(0, METRIC_DATA_MAX_NUM)
91
+ )
92
+ end
93
+ end
94
+
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-cloudwatch_ya
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - suz-lab
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Yet Another Plugin for Amazon CloudWatch
15
+ email: suzuki@suz-lab.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.rdoc
22
+ - lib/fluent/plugin/out_cloudwatch_ya.rb
23
+ homepage: http://github.com/suz-lab/fluent-plugin-cloudwatch_ya
24
+ licenses:
25
+ - Apache License, Version 2.0
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.23
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: Yet Another Plugin for Amazon CloudWatch
48
+ test_files: []