fluent-plugin-tagged_udp 0.0.5 → 0.0.6

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: 6ea677c145728705289717a08674db7432f9abcd
4
- data.tar.gz: 95cf849b3046a58d0ca038f391ada1654592a3d7
3
+ metadata.gz: b7d42d12afc1781ecc3f16ab20d4b13db8b59d79
4
+ data.tar.gz: 5836b906c9bc72da12df1c2acc9975090c6b21da
5
5
  SHA512:
6
- metadata.gz: 39f5ef00240c71c440a03978fbd7577473c935c5476ea37ea0f8b3595a4ca34ceae9c8783779a3330af14b7a1b1d73599bd96c8473b533c6bdc4076c7131cc5e
7
- data.tar.gz: 64946230b236198efc1c6acb77ba221442faedcdf23f6f092b2d194e827ea7aabe3bc807e54c6110d3936a9b939ff2fda96f0b2dbf4c0649bf1bc16da7ef6590
6
+ metadata.gz: 6d6d2cd5ab1d64b8097e3e4385e131c99138b74bb8b8c555c6cb5c4fb5b4b864ea63c6a5fed48cd00d43e082489eaeb62bd5ed8744e1d750bfc0a338f5d646a0
7
+ data.tar.gz: cf401b581f53b9b15314fc6c043ba43315d18f2019ed35d9d891cfb16e98d733e543c92ca5979260a23b8117ddeb98a96ba297d726f0c09fca44f3c21bd669f8
data/README.md CHANGED
@@ -37,6 +37,9 @@ Input plugin can be used via source directive.
37
37
  Optional parameters are as follows:
38
38
 
39
39
  - tag_sep: separator of tag name. default is "\t"
40
+ - recv_time: Add receive time to message in millisecond (ms) as integer for debug and performance/delay analysis
41
+ - recv_time_key: An attribute of recv_time
42
+
40
43
 
41
44
  Output Plugin can be used via match directive.
42
45
 
@@ -50,6 +53,12 @@ Output Plugin can be used via match directive.
50
53
 
51
54
  ```
52
55
 
56
+ Optional parameters are as follows:
57
+
58
+ - tag_sep: separator of tag name. default is "\t"
59
+ - send_time: Add send time to message in millisecond (ms) as integer for debug and performance/delay analysis
60
+ - send_time_key: An attribute of recv_time
61
+
53
62
  ## Contributing
54
63
 
55
64
  1. Fork it ( http://github.com/toyokazu/fluent-plugin-tagged_udp/fork )
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-tagged_udp"
7
- spec.version = "0.0.5"
7
+ spec.version = "0.0.6"
8
8
  spec.authors = ["Toyokazu Akiyama"]
9
9
  spec.email = ["toyokazu@gmail.com"]
10
10
 
@@ -9,6 +9,8 @@ module Fluent
9
9
  config_param :port, :integer, :default => 1883
10
10
  config_param :tag_sep, :string, :default => "\t"
11
11
  config_param :format, :string, :default => 'json'
12
+ config_param :recv_time, :bool, :default => false
13
+ config_param :recv_time_key, :string, :default => "recv_time"
12
14
 
13
15
  require 'socket'
14
16
 
@@ -22,16 +24,11 @@ module Fluent
22
24
  # If the configuration is invalid, raise Fluent::ConfigError.
23
25
  def configure(conf)
24
26
  super
25
-
26
- # You can also refer raw parameter via conf[name].
27
- @bind ||= conf['bind']
28
- @port ||= conf['port']
29
- @tag_sep ||= conf['tag_sep']
30
27
  configure_parser(conf)
31
28
  end
32
29
 
33
30
  def configure_parser(conf)
34
- @parser = Plugin.new_parser(conf['format'])
31
+ @parser = Plugin.new_parser(@format)
35
32
  @parser.configure(conf)
36
33
  end
37
34
 
@@ -45,20 +42,31 @@ module Fluent
45
42
  end
46
43
  end
47
44
 
45
+ def add_recv_time(record)
46
+ if @recv_time
47
+ # recv_time is recorded in ms
48
+ record.merge({@recv_time_key => Time.now.instance_eval { self.to_i * 1000 + (usec/1000) }})
49
+ else
50
+ record
51
+ end
52
+ end
53
+
48
54
  def start
49
55
  $log.debug "start udp server #{@bind}"
50
56
 
51
57
  @thread = Thread.new(Thread.current) do |parent|
52
- begin
53
- Socket.udp_server_loop(@bind, @port) do |msg, msg_src|
54
- $log.debug("Received #{msg}")
55
- tag, message = msg.split(@tag_sep)
56
- time, record = parse(message)
57
- $log.debug "#{tag}, #{time}, #{record}"
58
- router.emit(tag, time, record)
58
+ while (true)
59
+ begin
60
+ Socket.udp_server_loop(@bind, @port) do |msg, msg_src|
61
+ $log.debug("Received #{msg}")
62
+ tag, message = msg.split(@tag_sep)
63
+ time, record = parse(message)
64
+ $log.debug "#{tag}, #{time}, #{add_recv_time(record)}"
65
+ router.emit(tag, time, add_recv_time(record))
66
+ end
67
+ rescue StandardError => e
68
+ $log.debug("In udp_server_loop, #{e.class}: #{e.message}")
59
69
  end
60
- rescue StandardError => e
61
- parent.raise(e)
62
70
  end
63
71
  end
64
72
  end
@@ -10,6 +10,8 @@ module Fluent
10
10
  config_param :tag_sep, :string, :default => "\t"
11
11
  config_param :time_key, :string, :default => 'time'
12
12
  config_param :time_format, :string, :default => nil
13
+ config_param :send_time, :bool, :default => false
14
+ config_param :send_time_key, :string, :default => "send_time"
13
15
 
14
16
  require 'socket'
15
17
 
@@ -18,11 +20,6 @@ module Fluent
18
20
  # If the configuration is invalid, raise Fluent::ConfigError.
19
21
  def configure(conf)
20
22
  super
21
-
22
- # You can also refer raw parameter via conf[name].
23
- @host ||= conf['host']
24
- @port ||= conf['port']
25
- @tag_sep ||= conf['tag_sep']
26
23
  @socket = UDPSocket.new
27
24
  end
28
25
 
@@ -48,14 +45,23 @@ module Fluent
48
45
  end
49
46
  end
50
47
 
48
+ def add_send_time(record)
49
+ if @send_time
50
+ # send_time is recorded in ms
51
+ record.merge({@send_time_key => Time.now.instance_eval { self.to_i * 1000 + (usec/1000) }})
52
+ else
53
+ record
54
+ end
55
+ end
56
+
51
57
  def emit(tag, es, chain)
52
58
  begin
53
59
  es.each {|time,record|
54
- $log.debug "#{tag}, #{format_time(time)}, #{record}"
60
+ $log.debug "#{tag}, #{format_time(time)}, #{add_send_time(record)}"
55
61
  @socket.send(
56
62
  # tag is inserted into the head of the message
57
- "#{tag}#{@tag_sep}#{record.merge(timestamp_hash(time)).to_json}",
58
- Socket::MSG_EOR, @host, @port
63
+ "#{tag}#{@tag_sep}#{add_send_time(record).merge(timestamp_hash(time)).to_json}",
64
+ 0, @host, @port
59
65
  )
60
66
  }
61
67
  $log.flush
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-tagged_udp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toyokazu Akiyama
8
8
  autorequire:
9
9
  bindir: []
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd