fluent-plugin-collectd-influxdb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ Release 0.1.0 - 2014/10/10
2
+
3
+ * First release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,52 @@
1
+ # Output filter plugin Output filter plugin to rewrite Collectd JSON output to be inserted into InfluxDB
2
+
3
+ Rewrites the message coming from Collectd to make it compatible with the way InfluxDB stores data in series.
4
+
5
+ ## Installation
6
+
7
+ Use RubyGems:
8
+
9
+ gem install fluent-plugin-collectd-influxdb
10
+
11
+ ## Configuration
12
+
13
+ <match pattern>
14
+ type collectd_influxdb
15
+ </match>
16
+
17
+ If following record is passed:
18
+
19
+ ```js
20
+ [{"time" => 1000, "host" => 'host_v', "interval" => 5, "plugin" => 'plugin_v', "plugin_instance" => 'plugin_instance_v', "type" => 'type_v', "type_instance" => 'type_instance_v', "values" => ['v1', 'v2'], "dsnames" => ['n1', 'n2'], "dstypes" => ['t1', 't2']}]
21
+ ```
22
+
23
+ then you got new record like below:
24
+
25
+ ```js
26
+ [{"n1"=>"v1", "n2"=>"v2"}]
27
+ ```
28
+
29
+ and the record tag will be changed to
30
+
31
+ ```js
32
+ host_v.plugin_v.plugin_instance_v.type_v.type_instance_v
33
+ ```
34
+
35
+ Empty values in "plugin", "plugin_instance", "type" or "type_instance" will not be copied into the new tag name
36
+
37
+
38
+ ## WARNING
39
+
40
+ * This plugin was written to deal with a specific use-case, might not be the best fit for everyone. If you need more configurability/features, create a PR
41
+
42
+
43
+ ## Copyright
44
+
45
+ <table>
46
+ <tr>
47
+ <td>Author</td><td>Giuseppe Iannello <giuseppe.iannello@brokenloop.net></td>
48
+ </tr>
49
+ <tr>
50
+ <td>License</td><td>MIT License</td>
51
+ </tr>
52
+ </table>
@@ -0,0 +1,12 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-collectd-influxdb"
6
+ gem.description = "Output filter plugin to rewrite Collectd JSON output to be inserted into InfluxDB"
7
+ gem.homepage = "https://github.com/giannello/fluent-plugin-collectd-influxdb"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Giuseppe Iannello"]
11
+ gem.email = "giuseppe.iannello@brokenloop.net"
12
+ gem.has_rdoc = false
13
+ #gem.platform = Gem::Platform::RUBY
14
+ gem.license = 'MIT'
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency "fluentd", "~> 0.10.17"
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ end
@@ -0,0 +1,38 @@
1
+ module Fluent
2
+ class CollectdInfluxdbOutput < Output
3
+ Fluent::Plugin.register_output('collectd_influxdb', self)
4
+
5
+ def configure(conf)
6
+ super
7
+ end
8
+
9
+ def emit(tag, es, chain)
10
+ es.each { |time, record|
11
+ record.each { |event|
12
+ Engine.emit(rewrite_tag(tag, event), event['time'], normalize_record(event))
13
+ }
14
+ }
15
+
16
+ chain.next
17
+ end
18
+
19
+ private
20
+
21
+ def rewrite_tag(tag, event)
22
+ @tags = [tag, event['host'].gsub(".","/"), event['plugin'], event['plugin_instance'], event['type'], event['type_instance']]
23
+ tag = @tags.join(".").squeeze(".").gsub(/\.$/, '')
24
+ tag
25
+ end
26
+
27
+ def normalize_record(record)
28
+ record['values'].each_with_index { |value, index|
29
+ record[record['dsnames'][index]] = value
30
+ }
31
+ keys = ['time', 'host', 'interval', 'plugin', 'plugin_instance', 'type', 'type_instance', 'values', 'dsnames', 'dstypes']
32
+ keys.each { |key|
33
+ record.delete(key)
34
+ }
35
+ record
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,75 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/out_collectd_influxdb'
3
+
4
+
5
+ class CollectdInfluxdbOutputTest < Test::Unit::TestCase
6
+ def setup
7
+ Fluent::Test.setup
8
+ end
9
+
10
+ CONFIG = %[
11
+ type collectd_influxdb
12
+ tag foo.filtered
13
+ ]
14
+
15
+ def create_driver(conf = CONFIG)
16
+ Fluent::Test::OutputTestDriver.new(Fluent::CollectdInfluxdbOutput, tag='test_tag').configure(conf)
17
+ end
18
+
19
+ def test_rewrite_tag
20
+ d = create_driver %[
21
+ type collectd_influxdb
22
+ ]
23
+
24
+ d.run do
25
+ d.emit([{
26
+ "time" => 1000, "host" => 'host', "interval" => 5,
27
+ "plugin" => 'plugin', "plugin_instance" => 'plugin_instance',
28
+ "type" => 'type', "type_instance" => 'type_instance',
29
+ "values" => ['v1', 'v2'], "dsnames" => ['n1', 'n2'], "dstypes" => ['t1', 't2']
30
+ }])
31
+ d.emit([{
32
+ "time" => 1000, "host" => 'host', "interval" => 5,
33
+ "plugin" => 'plugin', "plugin_instance" => '',
34
+ "type" => 'type', "type_instance" => 'type_instance',
35
+ "values" => ['v1', 'v2'], "dsnames" => ['n1', 'n2'], "dstypes" => ['t1', 't2']
36
+ }])
37
+ d.emit([{
38
+ "time" => 1000, "host" => 'host', "interval" => 5,
39
+ "plugin" => 'plugin', "plugin_instance" => 'plugin_instance',
40
+ "type" => '', "type_instance" => 'type_instance',
41
+ "values" => ['v1', 'v2'], "dsnames" => ['n1', 'n2'], "dstypes" => ['t1', 't2']
42
+ }])
43
+ d.emit([{
44
+ "time" => 1000, "host" => 'host', "interval" => 5,
45
+ "plugin" => 'plugin', "plugin_instance" => 'plugin_instance',
46
+ "type" => 'type', "type_instance" => '',
47
+ "values" => ['v1', 'v2'], "dsnames" => ['n1', 'n2'], "dstypes" => ['t1', 't2']
48
+ }])
49
+ end
50
+
51
+ assert_equal 4, d.emits.length
52
+ assert_equal "test_tag.host.plugin.plugin_instance.type.type_instance", d.emits[0][0]
53
+ assert_equal "test_tag.host.plugin.type.type_instance", d.emits[1][0]
54
+ assert_equal "test_tag.host.plugin.plugin_instance.type_instance", d.emits[2][0]
55
+ assert_equal "test_tag.host.plugin.plugin_instance.type", d.emits[3][0]
56
+ end
57
+
58
+ def test_normalize_record
59
+ d = create_driver %[
60
+ type collectd_influxdb
61
+ ]
62
+
63
+ d.run do
64
+ d.emit([{
65
+ "time" => 1000, "host" => 'v', "interval" => 5,
66
+ "plugin" => 'v', "plugin_instance" => 'v',
67
+ "type" => 'v', "type_instance" => 'v',
68
+ "values" => ['v1', 'v2'], "dsnames" => ['n1', 'n2'], "dstypes" => ['t1', 't2']
69
+ }])
70
+ end
71
+
72
+ assert_equal [{"n1"=>"v1", "n2"=>"v2"}], d.records
73
+ end
74
+
75
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-collectd-influxdb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Giuseppe Iannello
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.17
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.17
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2
46
+ description: Output filter plugin to rewrite Collectd JSON output to be inserted into
47
+ InfluxDB
48
+ email: giuseppe.iannello@brokenloop.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - ChangeLog
54
+ - Gemfile
55
+ - README.md
56
+ - Rakefile
57
+ - VERSION
58
+ - fluent-plugin-collectd-influxdb.gemspec
59
+ - lib/fluent/plugin/out_collectd_influxdb.rb
60
+ - test/out_collectd_influxdb.rb
61
+ homepage: https://github.com/giannello/fluent-plugin-collectd-influxdb
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Output filter plugin to rewrite Collectd JSON output to be inserted into
86
+ InfluxDB
87
+ test_files: []