fluent-plugin-zmq 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 +4 -0
- data/Gemfile +8 -0
- data/README +3 -0
- data/Rakefile +1 -0
- data/fluent-plugin-zmq.gemspec +24 -0
- data/lib/fluent-plugin-zmq/version.rb +7 -0
- data/lib/fluent/plugin/in_zmq.rb +137 -0
- metadata +52 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fluent-plugin-zmq/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fluent-plugin-zmq"
|
7
|
+
s.version = Fluent::Plugin::Zmq::VERSION
|
8
|
+
s.authors = ["OZAWA Tsuyoshi"]
|
9
|
+
s.email = ["ozawa.tsuyoshi@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{zmq plugin for fluent, an event collector}
|
12
|
+
s.description = %q{zmq plugin for fluent, an event collector}
|
13
|
+
|
14
|
+
s.rubyforge_project = "fluent-plugin-zmq"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "fluent-plugin-zmq/version"
|
4
|
+
#
|
5
|
+
# Fluent
|
6
|
+
#
|
7
|
+
# Copyright (C) 2011 OZAWA Tsuyoshi
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
|
23
|
+
module Fluent
|
24
|
+
|
25
|
+
class ZMQInput < Input
|
26
|
+
Plugin.register_input('zmq', self)
|
27
|
+
|
28
|
+
config_param :port, :integer, :default => 4010
|
29
|
+
config_param :bind, :string, :default => '0.0.0.0'
|
30
|
+
config_param :body_size_limit, :size, :default => 32*1024*1024 # TODO default
|
31
|
+
#config_param :server_type, :string, :default => 'nonblocking'
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
require 'zmq'
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def configure(conf)
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def start
|
43
|
+
Signal.trap(:INT){
|
44
|
+
puts ":INT"
|
45
|
+
@server.close
|
46
|
+
exit(0)
|
47
|
+
}
|
48
|
+
|
49
|
+
$log.debug "listening http on #{@bind}:#{@port}"
|
50
|
+
@zmq = ZMQ::Context.new
|
51
|
+
@server = @zmq.socket(ZMQ::UPSTREAM)
|
52
|
+
@server.bind("tcp://" + @bind + ":" + @port.to_s)
|
53
|
+
@thread = Thread.new(&method(:run))
|
54
|
+
end
|
55
|
+
|
56
|
+
def run
|
57
|
+
begin
|
58
|
+
while true
|
59
|
+
ret = ZMQ::select([@server])
|
60
|
+
ret[0].each do |sock|
|
61
|
+
msg = sock.recv
|
62
|
+
on_message(MessagePack.unpack(msg))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
rescue
|
66
|
+
$log.error "unexpected error", :error=>$!.to_s
|
67
|
+
$log.error_backtrace
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# message Entry {
|
73
|
+
# 1: long time
|
74
|
+
# 2: object record
|
75
|
+
# }
|
76
|
+
#
|
77
|
+
# message Forward {
|
78
|
+
# 1: string tag
|
79
|
+
# 2: list<Entry> entries
|
80
|
+
# }
|
81
|
+
#
|
82
|
+
# message PackedForward {
|
83
|
+
# 1: string tag
|
84
|
+
# 2: raw entries # msgpack stream of Entry
|
85
|
+
# }
|
86
|
+
#
|
87
|
+
# message Message {
|
88
|
+
# 1: string tag
|
89
|
+
# 2: long? time
|
90
|
+
# 3: object record
|
91
|
+
# }
|
92
|
+
def on_message(msg)
|
93
|
+
# TODO format error
|
94
|
+
tag = msg[0].to_s
|
95
|
+
time = msg[1]
|
96
|
+
time = Engine.now if time == 0
|
97
|
+
record = msg[2]
|
98
|
+
|
99
|
+
p tag
|
100
|
+
p time
|
101
|
+
p record
|
102
|
+
|
103
|
+
Engine.emit(tag, time, record)
|
104
|
+
|
105
|
+
# TODO : support other formats
|
106
|
+
#if entries.class == String
|
107
|
+
# # PackedForward
|
108
|
+
# es = MessagePackEventStream.new(entries, @cached_unpacker)
|
109
|
+
# Engine.emit_stream(tag, es)
|
110
|
+
|
111
|
+
#elsif entries.class == Array
|
112
|
+
# # Forward
|
113
|
+
# es = MultiEventStream.new
|
114
|
+
# entries.each {|e|
|
115
|
+
# time = e[0].to_i
|
116
|
+
# time = (now ||= Engine.now) if time == 0
|
117
|
+
# record = e[1]
|
118
|
+
# es.add(time, record)
|
119
|
+
# }
|
120
|
+
# Engine.emit_stream(tag, es)
|
121
|
+
|
122
|
+
#else
|
123
|
+
# # Message
|
124
|
+
# time = msg[1]
|
125
|
+
# time = Engine.now if time == 0
|
126
|
+
# record = msg[2]
|
127
|
+
# Engine.emit(tag, time, record)
|
128
|
+
#end
|
129
|
+
end
|
130
|
+
|
131
|
+
def shutdown
|
132
|
+
@server.close
|
133
|
+
#@thread.join # TODO
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-zmq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- OZAWA Tsuyoshi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: zmq plugin for fluent, an event collector
|
15
|
+
email:
|
16
|
+
- ozawa.tsuyoshi@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- README
|
24
|
+
- Rakefile
|
25
|
+
- fluent-plugin-zmq.gemspec
|
26
|
+
- lib/fluent-plugin-zmq/version.rb
|
27
|
+
- lib/fluent/plugin/in_zmq.rb
|
28
|
+
homepage: ''
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: fluent-plugin-zmq
|
48
|
+
rubygems_version: 1.8.10
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: zmq plugin for fluent, an event collector
|
52
|
+
test_files: []
|