fluent-plugin-td-monitoring 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,109 @@
1
+ module Fluent
2
+ class TDCounterOutput < Output
3
+ Plugin.register_output('td_counter', self)
4
+
5
+ #config_param :aggregate, :string, :default => 'tag'
6
+ #config_param :exact_count, :bool, :default => true
7
+
8
+ attr_accessor :counts
9
+ attr_reader :output
10
+
11
+ def initialize
12
+ super
13
+ @output = nil
14
+ end
15
+
16
+ def configure(conf)
17
+ super
18
+
19
+ conf.elements.select { |e|
20
+ e.name == 'store'
21
+ }.each { |e|
22
+ type = e['type']
23
+ unless type
24
+ raise ConfigError, "Missing 'type' parameter on <store> directive"
25
+ end
26
+ $log.debug "adding store type = #{type.dump}"
27
+
28
+ @output = Plugin.new_output(type)
29
+ @output.configure(e)
30
+ }
31
+
32
+ @counts = {}
33
+ @mutex = Mutex.new
34
+ end
35
+
36
+ def start
37
+ super
38
+
39
+ unless check_td_monitor_agent
40
+ $log.warn "in_td_monitor_agent not found. If you want to use out_td_counter, then you should configure in_td_monitor_agent in same configuration"
41
+ end
42
+
43
+ unless @output.nil?
44
+ @output.start
45
+ end
46
+ end
47
+
48
+ def shutdown
49
+ unless @output.nil?
50
+ @output.shutdown
51
+ end
52
+
53
+ super
54
+ end
55
+
56
+ COUNT_FIELD = 'count'
57
+ BYTES_FIELD = 'bytes'
58
+
59
+ def count_initialized
60
+ {COUNT_FIELD => 0, BYTES_FIELD => 0}
61
+ end
62
+
63
+ def countup(tag, counts, bytes)
64
+ @mutex.synchronize {
65
+ @counts[tag] ||= count_initialized
66
+ count = @counts[tag]
67
+ count[COUNT_FIELD] += counts
68
+ count[BYTES_FIELD] += bytes
69
+ }
70
+ end
71
+
72
+ def flush_counts
73
+ counts = nil
74
+ @mutex.synchronize {
75
+ counts = @counts
76
+ @counts = {}
77
+ }
78
+ counts
79
+ end
80
+
81
+ def emit(tag, es, chain)
82
+ count = 0
83
+ bytes = 0
84
+
85
+ # TODO: if bytes is not needed, use Event#num_records to reduce processing time
86
+ es.each { |time, record|
87
+ count += 1
88
+ bytes += record.to_msgpack.bytesize
89
+ }
90
+
91
+ countup(tag, count, bytes)
92
+ unless @output.nil?
93
+ @output.emit(tag, es, chain)
94
+ end
95
+
96
+ chain.next
97
+ end
98
+
99
+ private
100
+
101
+ def check_td_monitor_agent
102
+ found = false
103
+ ObjectSpace.each_object(Fluent::TDMonitorAgentInput) { |obj|
104
+ found = true
105
+ }
106
+ found
107
+ end
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-td-monitoring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro Nakagawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.33
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.33
27
+ - !ruby/object:Gem::Dependency
28
+ name: ohai
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 6.18.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 6.18.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpclient
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.5.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: rr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.0
97
+ description: ''
98
+ email:
99
+ - masa@treasure-data.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ChangeLog
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - VERSION
109
+ - data/ca-bundle.crt
110
+ - fluent-plugin-td-monitoring.gemspec
111
+ - lib/fluent/plugin/fms_fluentd_ext.rb
112
+ - lib/fluent/plugin/in_td_monitor_agent.rb
113
+ - lib/fluent/plugin/out_td_counter.rb
114
+ homepage: http://www.treasuredata.com/
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: 1.9.2
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.0.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: ''
138
+ test_files: []