fluent-plugin-influxdb 0.2.2 → 0.2.3

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: 669c3b535b02de2911b23d4031733d428ae0c2c9
4
- data.tar.gz: 281bc8576f08186c507fc0101190df7dcc5e90d1
3
+ metadata.gz: c18eeb3df6edb6a13fd2c1bfb2297627b8523fd5
4
+ data.tar.gz: 684d18b8d759cb69474274f1346fff726591667b
5
5
  SHA512:
6
- metadata.gz: 65dd2cecf483c1ca25a0d57aff6322344785048830970d79cee2572eead29d544a4f98f7b2bb33c2b9a03b94cb96f04cbc1c6fb213aac70526eb1cf62c9f2a38
7
- data.tar.gz: e62c1259376e4cf34a21475a1d0187b868a18aa8a69beb13f6bedc314f95ef789b3f14723aff461d5842dec3a33de9301b94dc9d08b7e4c8e18a898c14625ec2
6
+ metadata.gz: 9479f05a97776e1d6e210212c05bb4e4c741a4362d157cf14007b913ad0bd7857152bca5297ea2f3974c77b118fdb25f1b164a542a308bb1a31b5ebd0df02398
7
+ data.tar.gz: d801c178625d67e10514679190e43aa4700f83858f34b122c6e8cd871fe4669d1101ed47489bc3dca56e9d799c6b7311717395b2ba41e9a63a35b6dce571990f
data/History.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.2.3 (Feb, 27, 2016)
5
+ =====
6
+
7
+ - Add sequence_tag option
8
+ - Add parameter descriptions
9
+
4
10
  0.2.2 (Nov, 02, 2015)
5
11
  =====
6
12
 
data/README.md CHANGED
@@ -39,6 +39,8 @@ Just like other regular output plugins, Use type `influxdb` in your fluentd conf
39
39
 
40
40
  `tag_keys`: The names of the keys to use as influxDB tags.
41
41
 
42
+ `sequence_tag`: The name of the tag whose value is incremented for the consecutive simultaneous events and reset to zero for a new event with the different timestamp
43
+
42
44
  ### Fluentd Tag and InfluxDB Series
43
45
 
44
46
  influxdb plugin uses Fluentd event tag for InfluxDB series.
@@ -57,6 +59,7 @@ So if you have events with `app.event`, influxdb plugin inserts events into `app
57
59
  use_ssl false
58
60
  time_precision s
59
61
  tag_keys ["key1", "key2"]
62
+ sequence_tag _seq
60
63
  </match>
61
64
  ```
62
65
 
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-influxdb"
6
- s.version = '0.2.2'
6
+ s.version = '0.2.3'
7
7
  s.authors = ["Masahiro Nakagawa", "FangLi"]
8
8
  s.email = ["repeatedly@gmail.com", "surivlee@gmail.com"]
9
9
  s.description = %q{InfluxDB output plugin for Fluentd}
@@ -7,18 +7,40 @@ class Fluent::InfluxdbOutput < Fluent::BufferedOutput
7
7
 
8
8
  include Fluent::HandleTagNameMixin
9
9
 
10
- config_param :host, :string, :default => 'localhost'
11
- config_param :port, :integer, :default => 8086
12
- config_param :dbname, :string, :default => 'fluentd'
13
- config_param :user, :string, :default => 'root'
14
- config_param :password, :string, :default => 'root', :secret => true
15
- config_param :time_precision, :string, :default => 's'
16
- config_param :use_ssl, :bool, :default => false
17
- config_param :tag_keys, :array, :default => []
10
+ config_param :host, :string, :default => 'localhost',
11
+ :desc => "The IP or domain of influxDB."
12
+ config_param :port, :integer, :default => 8086,
13
+ :desc => "The HTTP port of influxDB."
14
+ config_param :dbname, :string, :default => 'fluentd',
15
+ :desc => <<-DESC
16
+ The database name of influxDB.
17
+ You should create the database and grant permissions at first.
18
+ DESC
19
+ config_param :user, :string, :default => 'root',
20
+ :desc => "The DB user of influxDB, should be created manually."
21
+ config_param :password, :string, :default => 'root', :secret => true,
22
+ :desc => "The password of the user."
23
+ config_param :time_precision, :string, :default => 's',
24
+ :desc => <<-DESC
25
+ The time precision of timestamp.
26
+ You should specify either hour (h), minutes (m), second (s),
27
+ millisecond (ms), microsecond (u), or nanosecond (n).
28
+ DESC
29
+ config_param :use_ssl, :bool, :default => false,
30
+ :desc => "Use SSL when connecting to influxDB."
31
+ config_param :tag_keys, :array, :default => [],
32
+ :desc => "The names of the keys to use as influxDB tags."
33
+ config_param :sequence_tag, :string, :default => nil,
34
+ :desc => <<-DESC
35
+ The name of the tag whose value is incremented for the consecutive simultaneous
36
+ events and reset to zero for a new event with the different timestamp.
37
+ DESC
18
38
 
19
39
 
20
40
  def initialize
21
41
  super
42
+ @seq = 0
43
+ @prev_timestamp = nil
22
44
  end
23
45
 
24
46
  def configure(conf)
@@ -54,15 +76,36 @@ class Fluent::InfluxdbOutput < Fluent::BufferedOutput
54
76
  def write(chunk)
55
77
  points = []
56
78
  chunk.msgpack_each do |tag, time, record|
57
- point = {}
58
- point[:timestamp] = record.delete('time') || time
59
- point[:series] = tag
79
+ timestamp = record.delete('time') || time
60
80
  if tag_keys.empty?
61
- point[:values] = record
81
+ values = record
82
+ tags = {}
62
83
  else
63
- point[:tags] = record.select{|k,v| @tag_keys.include?(k)}
64
- point[:values] = record.select{|k,v| !@tag_keys.include?(k)}
84
+ values = {}
85
+ tags = {}
86
+ record.each_pair do |k, v|
87
+ if @tag_keys.include?(k)
88
+ tags[k] = v
89
+ else
90
+ values[k] = v
91
+ end
92
+ end
65
93
  end
94
+ if @sequence_tag
95
+ if @prev_timestamp == timestamp
96
+ @seq += 1
97
+ else
98
+ @seq = 0
99
+ end
100
+ tags[@sequence_tag] = @seq
101
+ @prev_timestamp = timestamp
102
+ end
103
+ point = {
104
+ :timestamp => timestamp,
105
+ :series => tag,
106
+ :values => values,
107
+ :tags => tags,
108
+ }
66
109
  points << point
67
110
  end
68
111
 
@@ -1,5 +1,18 @@
1
1
  require 'helper'
2
+
2
3
  class InfluxdbOutputTest < Test::Unit::TestCase
4
+ class DummyInfluxDBClient
5
+ attr_reader :points
6
+
7
+ def initialize
8
+ @points = []
9
+ end
10
+
11
+ def write_points(points)
12
+ @points += points
13
+ end
14
+ end
15
+
3
16
  def setup
4
17
  Fluent::Test.setup
5
18
  end
@@ -21,8 +34,10 @@ class InfluxdbOutputTest < Test::Unit::TestCase
21
34
 
22
35
  def create_driver(conf=CONFIG, tag='test')
23
36
  Fluent::Test::BufferedOutputTestDriver.new(Fluent::InfluxdbOutput, tag) do
24
- def write(chunk)
25
- chunk.read
37
+ attr_reader :influxdb
38
+ def configure(conf)
39
+ super
40
+ @influxdb = DummyInfluxDBClient.new()
26
41
  end
27
42
  end.configure(conf)
28
43
  end
@@ -60,7 +75,71 @@ class InfluxdbOutputTest < Test::Unit::TestCase
60
75
 
61
76
  data = driver.run
62
77
 
63
- assert_equal(['input.influxdb', time, {'a' => 1}].to_msgpack +
64
- ['input.influxdb', time, {'a' => 2}].to_msgpack, data)
78
+ assert_equal([
79
+ {
80
+ :timestamp => time,
81
+ :series => 'input.influxdb',
82
+ :values => {'a' => 1},
83
+ :tags => {},
84
+ },
85
+ {
86
+ :timestamp => time,
87
+ :series => 'input.influxdb',
88
+ :values => {'a' => 2},
89
+ :tags => {},
90
+ }
91
+ ], driver.instance.influxdb.points)
92
+
93
+ end
94
+
95
+ def test_seq
96
+ config = %[
97
+ type influxdb
98
+ host localhost
99
+ port 8086
100
+ dbname test
101
+ user testuser
102
+ password mypwd
103
+ use_ssl false
104
+ time_precision s
105
+ sequence_tag _seq
106
+ ]
107
+ driver = create_driver(config, 'input.influxdb')
108
+
109
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
110
+ driver.emit({'a' => 1}, time)
111
+ driver.emit({'a' => 2}, time)
112
+
113
+ driver.emit({'a' => 1}, time + 1)
114
+ driver.emit({'a' => 2}, time + 1)
115
+
116
+ data = driver.run
117
+
118
+ assert_equal([
119
+ {
120
+ :timestamp => time,
121
+ :series => 'input.influxdb',
122
+ :values => {'a' => 1},
123
+ :tags => {'_seq' => 0},
124
+ },
125
+ {
126
+ :timestamp => time,
127
+ :series => 'input.influxdb',
128
+ :values => {'a' => 2},
129
+ :tags => {'_seq' => 1},
130
+ },
131
+ {
132
+ :timestamp => time + 1,
133
+ :series => 'input.influxdb',
134
+ :values => {'a' => 1},
135
+ :tags => {'_seq' => 0},
136
+ },
137
+ {
138
+ :timestamp => time + 1,
139
+ :series => 'input.influxdb',
140
+ :values => {'a' => 2},
141
+ :tags => {'_seq' => 1},
142
+ }
143
+ ], driver.instance.influxdb.points)
65
144
  end
66
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Nakagawa
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-02 00:00:00.000000000 Z
12
+ date: 2016-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.4.5.1
128
+ rubygems_version: 2.2.2
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: A buffered output plugin for fluentd and influxDB