fluent-plugin-influxdb_metrics 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/.gitignore +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +38 -0
- data/README.md +19 -0
- data/Rakefile +10 -0
- data/fluent-plugin-influxdb_metrics.gemspec +22 -0
- data/lib/fluent/plugin/out_influxdb_metrics.rb +83 -0
- data/test/helper.rb +1 -0
- data/test/plugin/test_out_influxdb_metrics.rb +44 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-influxdb_metrics (0.0.1)
|
5
|
+
fluentd
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.6)
|
11
|
+
cool.io (1.2.4)
|
12
|
+
crack (0.4.2)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
fluentd (0.10.48)
|
15
|
+
cool.io (>= 1.1.1, < 2.0.0, != 1.2.0)
|
16
|
+
http_parser.rb (>= 0.5.1, < 0.7.0)
|
17
|
+
json (>= 1.4.3)
|
18
|
+
msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
|
19
|
+
sigdump (~> 0.2.2)
|
20
|
+
yajl-ruby (~> 1.0)
|
21
|
+
http_parser.rb (0.6.0)
|
22
|
+
json (1.8.1)
|
23
|
+
msgpack (0.5.8)
|
24
|
+
rake (10.3.2)
|
25
|
+
safe_yaml (1.0.3)
|
26
|
+
sigdump (0.2.2)
|
27
|
+
webmock (1.18.0)
|
28
|
+
addressable (>= 2.3.6)
|
29
|
+
crack (>= 0.3.2)
|
30
|
+
yajl-ruby (1.2.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
fluent-plugin-influxdb_metrics!
|
37
|
+
rake
|
38
|
+
webmock
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# InfluxDB-Metrics, a plugin for [Fluentd](http://fluentd.org)
|
2
|
+
|
3
|
+
Feeding time series data to InfluxDB via FluentD.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install fluent-plugin-influxdb_metrics
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
type influxdb_metrics
|
12
|
+
host influx.local
|
13
|
+
port 8086
|
14
|
+
dbname test
|
15
|
+
table metrics
|
16
|
+
user testuser
|
17
|
+
password mypwd
|
18
|
+
fields event_type,event_name,event_data.sub.value,event_data.sub.other_value
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "fluent-plugin-influxdb_metrics"
|
5
|
+
s.version = '0.0.1'
|
6
|
+
s.authors = ["lxfontes"]
|
7
|
+
s.email = ["lxfontes+influx@gmail.com"]
|
8
|
+
s.description = %q{InfluxDB output plugin for Fluentd}
|
9
|
+
s.summary = %q{output plugin for fluentd}
|
10
|
+
s.homepage = "https://github.com/lxfontes/fluent-plugin-influxdb_metrics"
|
11
|
+
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($/)
|
14
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency "fluentd"
|
19
|
+
|
20
|
+
s.add_development_dependency "rake"
|
21
|
+
s.add_development_dependency "webmock"
|
22
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'date'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
class Fluent::InfluxdbMetricsOutput < Fluent::BufferedOutput
|
6
|
+
Fluent::Plugin.register_output('influxdb_metrics', self)
|
7
|
+
|
8
|
+
config_param :host, :string, :default => 'localhost'
|
9
|
+
config_param :port, :integer, :default => 8086
|
10
|
+
config_param :user, :string, :default => 'root'
|
11
|
+
config_param :password, :string, :default => 'root'
|
12
|
+
config_param :dbname, :string, :default => 'fluentd'
|
13
|
+
config_param :table, :string, :default => 'metrics'
|
14
|
+
config_param :fields, :string, :default => ''
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure(conf)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def filter_keys
|
29
|
+
@filter_keys ||= @fields.split(',').map(&:strip)
|
30
|
+
@filter_keys
|
31
|
+
end
|
32
|
+
|
33
|
+
def format(tag, time, record)
|
34
|
+
[tag, time, record].to_msgpack
|
35
|
+
end
|
36
|
+
|
37
|
+
def shutdown
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def write(chunk)
|
42
|
+
bulk = []
|
43
|
+
|
44
|
+
chunk.msgpack_each do |tag, time, record|
|
45
|
+
formatted_record = format_record(tag, time, record)
|
46
|
+
bulk << formatted_record if formatted_record
|
47
|
+
end
|
48
|
+
|
49
|
+
http = Net::HTTP.new(@host, @port)
|
50
|
+
resp, _ = http.post("/db/#{@dbname}/series?u=#{@user}&p=#{@password}&time_precision=s",
|
51
|
+
Yajl::Encoder.encode(bulk) + "\n",
|
52
|
+
'Content-Type' => 'text/json')
|
53
|
+
resp.value
|
54
|
+
end
|
55
|
+
|
56
|
+
def format_record(tag, time, record)
|
57
|
+
cols = ['time']
|
58
|
+
points = [time]
|
59
|
+
|
60
|
+
filter_keys.each do |field|
|
61
|
+
path = field.split('.')
|
62
|
+
rec_pos = record[path.shift]
|
63
|
+
path.each do |p|
|
64
|
+
rec_pos = rec_pos[p] if rec_pos
|
65
|
+
end
|
66
|
+
|
67
|
+
if rec_pos
|
68
|
+
cols << field
|
69
|
+
points << rec_pos
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if cols.length > 1
|
74
|
+
return {
|
75
|
+
name: @table,
|
76
|
+
columns: cols,
|
77
|
+
points: [points]
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'minitest/pride'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'fluent/test'
|
4
|
+
require 'fluent/plugin/out_influxdb_metrics'
|
5
|
+
|
6
|
+
require 'webmock/test_unit'
|
7
|
+
require 'date'
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
$:.push File.expand_path("../lib", __FILE__)
|
12
|
+
$:.push File.dirname(__FILE__)
|
13
|
+
|
14
|
+
WebMock.disable_net_connect!
|
15
|
+
|
16
|
+
class InfluxdbMetricsOutput < Test::Unit::TestCase
|
17
|
+
attr_accessor :index_cmds, :index_command_counts
|
18
|
+
|
19
|
+
def setup
|
20
|
+
Fluent::Test.setup
|
21
|
+
@driver = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def driver(tag='test', conf='')
|
25
|
+
@driver ||= Fluent::Test::BufferedOutputTestDriver.new(Fluent::InfluxdbMetricsOutput, tag).configure(conf)
|
26
|
+
end
|
27
|
+
|
28
|
+
def sample_record
|
29
|
+
{'age' => 26, 'request_id' => '42', 'parent_id' => 'parent', 'sub' => {'field'=>{'pos'=>15}}}
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_influx(url="http://localhost:8086/db/fluentd/series?p=root&u=root&time_precision=s")
|
33
|
+
stub_request(:post, url).with do |req|
|
34
|
+
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_writes_to_default_index
|
39
|
+
stub_influx
|
40
|
+
driver.configure('fields age,sub.field.pos')
|
41
|
+
driver.emit(sample_record)
|
42
|
+
driver.run
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-influxdb_metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- lxfontes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-25 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'
|
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'
|
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'
|
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'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: InfluxDB output plugin for Fluentd
|
63
|
+
email:
|
64
|
+
- lxfontes+influx@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- fluent-plugin-influxdb_metrics.gemspec
|
75
|
+
- lib/fluent/plugin/out_influxdb_metrics.rb
|
76
|
+
- test/helper.rb
|
77
|
+
- test/plugin/test_out_influxdb_metrics.rb
|
78
|
+
homepage: https://github.com/lxfontes/fluent-plugin-influxdb_metrics
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.23
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: output plugin for fluentd
|
103
|
+
test_files:
|
104
|
+
- test/helper.rb
|
105
|
+
- test/plugin/test_out_influxdb_metrics.rb
|