fluent-plugin-mqtt-io 0.2.1 → 0.2.2

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: c7acf8fbbfbb33e609608751a49d4cf4b97ec0b5
4
- data.tar.gz: a03ffed38eb93fa059f9b415bf58208fb7616b3a
3
+ metadata.gz: 5d00a8d71f16ee4a7f7c25d5c6432e1786159728
4
+ data.tar.gz: 54654b5f2cf2dca79f443a3e376a1bd323b4514f
5
5
  SHA512:
6
- metadata.gz: 93ae1aec473651c34c0c9398b144b7d832e1691d73844f6dc4a840df5740b786ca209c3f4484b5e1327b94d541ae74fde1cd40f30bb545ba385a7c33bef355e5
7
- data.tar.gz: 194bd3a8c5665788276f95ddb9dc1a99d89511b3e725f496af414e376385df2d44b07fcc1c169300f5fbac1c0364f1aca5938c52e75193beeaf77376296d57cb
6
+ metadata.gz: d061d3b17e90904f305b1310992e78aa4ebd26659fa9c10218e741b43b4d464157757d4c52c41a423b784dfb3409c23315e3bd0cc90f3cbb16f3d45af63b268b
7
+ data.tar.gz: 52628b2004bd6e0c492c12ce3fe4e24d073d4d02c9e21a7499ea0579c67313ee27108d71f6cd388156800f40d356d3bf57a386b71b3201afa6a020fef669083d
data/README.md CHANGED
@@ -58,6 +58,8 @@ The default MQTT topic is "#". Configurable options are the following:
58
58
  - ca_file: CA certificate file path
59
59
  - key_file: private key file path
60
60
  - cert_file: certificate file path
61
+ - recv_time: Add receive time to message in millisecond (ms) as integer for debug and performance/delay analysis
62
+ - recv_time_key: An attribute of recv_time
61
63
 
62
64
  Input Plugin supports @label directive.
63
65
 
@@ -82,6 +84,8 @@ The options are basically the same as Input Plugin except for "format" and "bulk
82
84
  - time_format: Output format of timestamp field. Default is ISO8601. You can specify your own format by using TimeParser.
83
85
  - topic_rewrite_pattern: Regexp pattern to extract replacement words from received topic or tag name
84
86
  - topic_rewrite_replacement: Topic name used for the publish using extracted pattern
87
+ - send_time: Add send time to message in millisecond (ms) as integer for debug and performance/delay analysis
88
+ - send_time_key: An attribute of recv_time
85
89
 
86
90
  If you use different source, e.g. the other MQTT broker, log file and so on, there is no need to specifie topic rewriting. Skip the following descriptions.
87
91
 
@@ -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-mqtt-io"
7
- spec.version = "0.2.1"
7
+ spec.version = "0.2.2"
8
8
  spec.authors = ["Toyokazu Akiyama"]
9
9
  spec.email = ["toyokazu@gmail.com"]
10
10
 
@@ -15,6 +15,8 @@ module Fluent
15
15
  config_param :ca_file, :string, :default => nil
16
16
  config_param :key_file, :string, :default => nil
17
17
  config_param :cert_file, :string, :default => nil
18
+ config_param :recv_time, :bool, :default => false
19
+ config_param :recv_time_key, :string, :default => "recv_time"
18
20
 
19
21
  require 'mqtt'
20
22
 
@@ -25,14 +27,6 @@ module Fluent
25
27
 
26
28
  def configure(conf)
27
29
  super
28
- @host ||= conf['host']
29
- @topic ||= conf['topic']
30
- @bulk_trans ||= conf['bulk_trans']
31
- @bulk_trans_sep ||= conf['bulk_trans_sep']
32
- @port ||= conf['port']
33
- @username ||= conf['username']
34
- @password ||= conf['password']
35
- @keep_alive ||= conf['keep_alive']
36
30
  configure_parser(conf)
37
31
  init_retry_interval
38
32
  end
@@ -51,9 +45,8 @@ module Fluent
51
45
  end
52
46
 
53
47
  def sleep_retry_interval(e, message)
54
- $log.debug "#{message}"
55
- $log.debug "#{e.class}: #{e.message}"
56
- $log.debug "Retry in #{@retry_interval} sec"
48
+ $log.error "#{message},#{e.class},#{e.message}"
49
+ $log.error "Retry in #{@retry_interval} sec"
57
50
  sleep @retry_interval
58
51
  increment_retry_interval
59
52
  end
@@ -107,14 +100,23 @@ module Fluent
107
100
  end
108
101
  end
109
102
 
103
+ def add_recv_time(record)
104
+ if @recv_time
105
+ # recv_time is recorded in ms
106
+ record.merge({@recv_time_key => Time.now.instance_eval { self.to_i * 1000 + (usec/1000) }})
107
+ else
108
+ record
109
+ end
110
+ end
111
+
110
112
  def parse(message)
111
113
  @parser.parse(message) do |time, record|
112
114
  if time.nil?
113
115
  $log.debug "Since time_key field is nil, Fluent::Engine.now is used."
114
116
  time = Fluent::Engine.now
115
117
  end
116
- $log.debug "#{topic}, #{time}, #{record}"
117
- return [time, record]
118
+ $log.debug "#{topic}, #{time}, #{add_recv_time(record)}"
119
+ return [time, add_recv_time(record)]
118
120
  end
119
121
  end
120
122
 
@@ -18,6 +18,8 @@ module Fluent
18
18
  base.config_param :topic_rewrite_pattern, :string, :default => nil
19
19
  base.config_param :topic_rewrite_replacement, :string, :default => nil
20
20
  base.config_param :bulk_trans_sep, :string, :default => "\t"
21
+ base.config_param :send_time, :bool, :default => false
22
+ base.config_param :send_time_key, :string, :default => "send_time"
21
23
  end
22
24
 
23
25
  require 'mqtt'
@@ -27,18 +29,6 @@ module Fluent
27
29
  # If the configuration is invalid, raise Fluent::ConfigError.
28
30
  def configure(conf)
29
31
  super
30
-
31
- # You can also refer raw parameter via conf[name].
32
- @host ||= conf['host']
33
- @port ||= conf['port']
34
- @username ||= conf['username']
35
- @password ||= conf['password']
36
- @keep_alive ||= conf['keep_alive']
37
- @time_key ||= conf['time_key']
38
- @time_format ||= conf['time_format']
39
- @topic_rewrite_pattern ||= conf['topic_rewrite_pattern']
40
- @topic_rewrite_replacement ||= conf['topic_rewrite_replacement']
41
- @bulk_trans_sep ||= conf['bulk_trans_sep']
42
32
  init_retry_interval
43
33
  end
44
34
 
@@ -51,9 +41,8 @@ module Fluent
51
41
  end
52
42
 
53
43
  def sleep_retry_interval(e, message)
54
- $log.debug "#{message}"
55
- $log.debug "#{e.class}: #{e.message}"
56
- $log.debug "Retry in #{@retry_interval} sec"
44
+ $log.error "#{message},#{e.class},#{e.message}"
45
+ $log.error "Retry in #{@retry_interval} sec"
57
46
  sleep @retry_interval
58
47
  increment_retry_interval
59
48
  end
@@ -133,6 +122,16 @@ module Fluent
133
122
  end
134
123
  end
135
124
 
125
+ def add_send_time(record)
126
+ if @send_time
127
+ # send_time is recorded in ms
128
+ record.merge({@send_time_key => Time.now.instance_eval { self.to_i * 1000 + (usec/1000) }})
129
+ else
130
+ record
131
+ end
132
+ end
133
+
134
+
136
135
  def rewrite_tag(tag)
137
136
  if @topic_rewrite_pattern.nil?
138
137
  tag.gsub("\.", "/")
@@ -9,8 +9,8 @@ module Fluent
9
9
 
10
10
  def emit(tag, es, chain)
11
11
  es.each {|time,record|
12
- $log.debug "#{tag}, #{format_time(time)}, #{record}"
13
- @client.publish(rewrite_tag(tag), record.merge(timestamp_hash(time)).to_json)
12
+ $log.debug "#{tag}, #{format_time(time)}, #{add_send_time(record)}"
13
+ @client.publish(rewrite_tag(tag), add_send_time(record).merge(timestamp_hash(time)).to_json)
14
14
  }
15
15
  $log.flush
16
16
 
@@ -11,7 +11,6 @@ module Fluent
11
11
  # Convert the event to a raw string.
12
12
  def format(tag, time, record)
13
13
  [tag, time, record].to_msgpack
14
- #[tag, time, record].to_json + "\n"
15
14
  end
16
15
 
17
16
  # This method is called every flush interval. Write the buffer chunk
@@ -24,19 +23,14 @@ module Fluent
24
23
  def write(chunk)
25
24
  messages = {}
26
25
  chunk.msgpack_each do |tag, time, record|
27
- #$log.debug "Thread ID: #{Thread.current.object_id}, tag: #{tag}, time: #{format_time(time)}, record: #{record}"
28
26
  messages[tag] = [] if messages[tag].nil?
29
- messages[tag] << record.merge(timestamp_hash(time))
27
+ messages[tag] << add_send_time(record).merge(timestamp_hash(time))
30
28
  end
31
29
  messages.keys.each do |tag|
32
30
  $log.debug "Thread ID: #{Thread.current.object_id}, topic: #{rewrite_tag(tag)}, message: #{messages[tag]}"
33
31
  @client.publish(rewrite_tag(tag), messages[tag].map {|m| m.to_json}.join(@bulk_trans_sep))
34
32
  end
35
33
  $log.flush
36
- #json = json_parse(chunk.open {|io| io.readline})
37
- #$log.debug "#{json[0]}, #{format_time(json[1])}, #{json[2]}"
38
- #@client.publish(rewrite_tag(json[0]), (json[2].merge(timestamp_hash(json[1]))).to_json)
39
- #$log.flush
40
34
  end
41
35
  end
42
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mqtt-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
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
@@ -75,7 +75,6 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
- - CODE_OF_CONDUCT.md
79
78
  - Gemfile
80
79
  - LICENSE
81
80
  - README.md
data/CODE_OF_CONDUCT.md DELETED
@@ -1,13 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
-
5
- We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
-
7
- Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
-
9
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
-
11
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
-
13
- This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)