fluent-plugin-jubatus 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/fluent-plugin-jubatus.gemspec +22 -0
- data/lib/fluent/plugin/out_jubatus.rb +135 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 483f2c695c7f2a74eb89c1e6274b7d17234d5dfc
|
4
|
+
data.tar.gz: 33367a26b845d3c9373da9351819da2a81192c31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01a003c9b9a64c50bdb80909f04daf90832026395075e38af683ccfcda44e53dff4527f82e966a88b29ab8edd7a7baec62d15df62e1e03525b194744287de794
|
7
|
+
data.tar.gz: af137d2b712e41d8dda0610bb8c262a4a997b6c6128da152ef63dfe3552dd299f435d4ebf9b6c62b9bf2403479f4adc6c2ef46dd64d96254a81eae54b3c0835f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 MATSUMOTO Katsuyoshi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Fluent::Plugin::Jubatus
|
2
|
+
|
3
|
+
fluentd pluing for jubatus
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fluent-plugin-jubatus', git: 'git://github.com/katsyoshi/fluent-plugin-jubatus.git'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
Configuration file:
|
17
|
+
|
18
|
+
<match mikutter.timeline>
|
19
|
+
type jubatus
|
20
|
+
host 127.0.0.1 # not necessary (default: 127.0.0.1)
|
21
|
+
port 9199 # not necessary (default: 9199)
|
22
|
+
client_api 'classifier' # not necessary (default: claasifier)
|
23
|
+
str_keys string1, string2 # you need to evaluate string value in jubatus
|
24
|
+
num_keys number2, number2 # you need to evaluate number value in jubatus
|
25
|
+
tag jubatus.timeline # not necessary (default: jubatus)
|
26
|
+
</match>
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-jubatus"
|
6
|
+
gem.version = "0.0.1"
|
7
|
+
gem.authors = ["MATSUMOTO Katsuyoshi"]
|
8
|
+
gem.email = ["matsumoto.katsuyoshi+rubygems@gmail.com"]
|
9
|
+
gem.description = %q{Jubatus output plugin for fluentd}
|
10
|
+
gem.summary = %q{Jubatus output plugin for fluentd}
|
11
|
+
gem.homepage = "https://github.com/katsyoshi/fluent-plugin-jubatus"
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
|
18
|
+
gem.add_dependency 'fluentd'
|
19
|
+
gem.add_dependency 'jubatus'
|
20
|
+
gem.add_development_dependency "simplecov"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module Fluent
|
2
|
+
class JubatusOutput < Output
|
3
|
+
Plugin.register_output('jubatus', self)
|
4
|
+
config_param :client_api, :string, :default => 'classifier'
|
5
|
+
config_param :host, :string, :default => '127.0.0.1'
|
6
|
+
config_param :port, :string, :default => '9199'
|
7
|
+
config_param :name, :string, :default => ''
|
8
|
+
config_param :str_keys, :string, :default => ''
|
9
|
+
config_param :num_keys, :string, :default => ''
|
10
|
+
config_param :learn_analyze, :string, :default => 'analyze'
|
11
|
+
config_param :tag, :string, :default => 'jubatus'
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
require 'jubatus/classifier/client'
|
16
|
+
require 'jubatus/classifier/types'
|
17
|
+
require 'jubatus/anomaly/client'
|
18
|
+
require 'jubatus/anomaly/types'
|
19
|
+
require 'jubatus/recommender/client'
|
20
|
+
require 'jubatus/recommender/types'
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure(conf)
|
24
|
+
super
|
25
|
+
@str = @str_keys.split(/,/).map{|str| str.strip}
|
26
|
+
@num = @num_keys.split(/,/).map{|num| num.strip}
|
27
|
+
end
|
28
|
+
|
29
|
+
def start
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def shutdown
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def emit(tag, es, chain)
|
38
|
+
es.each do |time, record|
|
39
|
+
result = result_format(jubatus_run(record))
|
40
|
+
Engine.emit(@tag, time, result)
|
41
|
+
end
|
42
|
+
|
43
|
+
chain.next
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def jubatus_run(data)
|
48
|
+
datum = set_datum(data)
|
49
|
+
if @learn_analyze =~ /^analyze$/i
|
50
|
+
analyze(datum)
|
51
|
+
elsif @learn_analyze =~ /^train$/i
|
52
|
+
update(datum)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def analyze(datum)
|
57
|
+
case
|
58
|
+
when @client_api =~ /^classif(y|ier)$/i
|
59
|
+
classify(datum)
|
60
|
+
when @client_api =~ /^anomaly$/i
|
61
|
+
anomaly(datum)
|
62
|
+
when @client_api =~ /^recommender/i
|
63
|
+
recommend(datum)
|
64
|
+
end
|
65
|
+
rescue => e
|
66
|
+
e
|
67
|
+
end
|
68
|
+
|
69
|
+
def update(datum)
|
70
|
+
jubatus = Jubatus::Classifier::Client::Classifier.new(@host, @port.to_i)
|
71
|
+
jubatus.train(@name, [datum])
|
72
|
+
jubatus.get_client.close
|
73
|
+
rescue => e
|
74
|
+
e
|
75
|
+
end
|
76
|
+
|
77
|
+
def set_datum(data)
|
78
|
+
str = []
|
79
|
+
num = []
|
80
|
+
data.each do |key, value|
|
81
|
+
str << [key, value.to_s] if @str.include?(key)
|
82
|
+
num << [key, value.to_f] if @num.include?(key)
|
83
|
+
end
|
84
|
+
case
|
85
|
+
when @client_api =~ /^classif(y|ier)$/i
|
86
|
+
Jubatus::Classifier::Datum.new(str, num)
|
87
|
+
when @client_api =~ /^anomaly$/i
|
88
|
+
Jubatus::Anomaly::Datum.new(str, num)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def result_format(data)
|
93
|
+
case
|
94
|
+
when @client_api =~ /^classifier$/i
|
95
|
+
result_classify(data)
|
96
|
+
when @client_api =~ /^anomaly$/i
|
97
|
+
result_anomaly(data)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def classify(datum)
|
102
|
+
jubatus = Jubatus::Classifier::Client::Classifier.new(@host, @port.to_i)
|
103
|
+
result = jubatus.classify(@name, [datum])
|
104
|
+
jubatus.get_client.close()
|
105
|
+
result
|
106
|
+
rescue => e
|
107
|
+
e
|
108
|
+
end
|
109
|
+
|
110
|
+
def anomaly(datum)
|
111
|
+
jubatus = Jubatus::Anomaly::Client::Anomaly.new(@host, @port.to_i)
|
112
|
+
result = jubatus.add(@name, datum)
|
113
|
+
jubatus.get_client.close()
|
114
|
+
result
|
115
|
+
rescue => e
|
116
|
+
e
|
117
|
+
end
|
118
|
+
|
119
|
+
def result_classify(data)
|
120
|
+
result = {}
|
121
|
+
data.map do |datum|
|
122
|
+
datum.map do |est|
|
123
|
+
result[est[0]] = est[1]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
result
|
127
|
+
end
|
128
|
+
|
129
|
+
def result_anomaly(data)
|
130
|
+
value = data[1]
|
131
|
+
value = data[1].to_s if data[1].to_s == "Infinity"
|
132
|
+
{ id: data[0], value: value }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-jubatus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MATSUMOTO Katsuyoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jubatus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Jubatus output plugin for fluentd
|
70
|
+
email:
|
71
|
+
- matsumoto.katsuyoshi+rubygems@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-jubatus.gemspec
|
82
|
+
- lib/fluent/plugin/out_jubatus.rb
|
83
|
+
homepage: https://github.com/katsyoshi/fluent-plugin-jubatus
|
84
|
+
licenses: []
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.0.3
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Jubatus output plugin for fluentd
|
106
|
+
test_files: []
|