fluent-plugin-watch-process 0.0.2 → 0.0.3
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/fluent-plugin-watch-process.gemspec +3 -1
- data/lib/fluent/plugin/in_watch_process.rb +20 -43
- metadata +34 -2
@@ -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-watch-process"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Kentaro Yoshida"]
|
8
8
|
s.email = ["y.ken.studio@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/y-ken/fluent-plugin-watch-process"
|
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
# specify any dependencies:
|
18
18
|
s.add_development_dependency "rake"
|
19
19
|
s.add_runtime_dependency "fluentd"
|
20
|
+
s.add_runtime_dependency "fluent-mixin-rewrite-tag-name"
|
21
|
+
s.add_runtime_dependency "fluent-mixin-type-converter"
|
20
22
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'fluent/mixin/rewrite_tag_name'
|
2
|
+
require 'fluent/mixin/type_converter'
|
3
|
+
|
1
4
|
module Fluent
|
2
5
|
class WatchProcessInput < Fluent::Input
|
3
6
|
Plugin.register_input('watch_process', self)
|
@@ -5,33 +8,21 @@ module Fluent
|
|
5
8
|
config_param :tag, :string
|
6
9
|
config_param :command, :string, :default => nil
|
7
10
|
config_param :keys, :string, :default => nil
|
8
|
-
config_param :types, :string, :default => nil
|
9
11
|
config_param :interval, :string, :default => '5s'
|
10
12
|
config_param :lookup_user, :string, :default => nil
|
11
13
|
config_param :hostname_command, :string, :default => 'hostname'
|
12
14
|
|
13
15
|
DEFAULT_KEYS = %w(start_time user pid parent_pid cpu_time cpu_percent memory_percent mem_rss mem_size state proc_name command)
|
14
|
-
DEFAULT_TYPES =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
else
|
25
|
-
false
|
26
|
-
end
|
27
|
-
},
|
28
|
-
'time' => lambda { |v, time_parser|
|
29
|
-
time_parser.parse(v)
|
30
|
-
},
|
31
|
-
'array' => lambda { |v, delimiter|
|
32
|
-
v.to_s.split(delimiter)
|
33
|
-
}
|
34
|
-
}
|
16
|
+
DEFAULT_TYPES = "pid:integer,parent_pid:integer,cpu_percent:float,memory_percent:float,mem_rss:integer,mem_size:integer"
|
17
|
+
|
18
|
+
include Fluent::HandleTagNameMixin
|
19
|
+
|
20
|
+
include Fluent::Mixin::RewriteTagName
|
21
|
+
config_set_default :enable_placeholder_upcase, true
|
22
|
+
config_set_default :enable_placeholder_hostname, true
|
23
|
+
|
24
|
+
include Fluent::Mixin::TypeConverter
|
25
|
+
config_param :types, :string, :default => DEFAULT_TYPES
|
35
26
|
|
36
27
|
def initialize
|
37
28
|
super
|
@@ -43,11 +34,8 @@ module Fluent
|
|
43
34
|
|
44
35
|
@command = @command || get_ps_command
|
45
36
|
@keys = @keys.nil? ? DEFAULT_KEYS : @keys.to_s.gsub(' ', '').split(',')
|
46
|
-
@types = @types || DEFAULT_TYPES
|
47
|
-
@types_map = Hash[types.map{|v| v.split(':')}]
|
48
37
|
@lookup_user = @lookup_user.gsub(' ', '').split(',') unless @lookup_user.nil?
|
49
38
|
@interval = Config.time_value(@interval)
|
50
|
-
@hostname = `#{@hostname_command}`.chomp
|
51
39
|
$log.info "watch_process: polling start. :tag=>#{@tag} :lookup_user=>#{@lookup_user} :interval=>#{@interval} :command=>#{@command}"
|
52
40
|
end
|
53
41
|
|
@@ -65,22 +53,18 @@ module Fluent
|
|
65
53
|
io.gets
|
66
54
|
while result = io.gets
|
67
55
|
keys_size = @keys.size
|
68
|
-
if result =~ /(?<lstart>(^\w
|
56
|
+
if result =~ /(?<lstart>(^\w+\s+\w+\s+\d+\s+\d\d:\d\d:\d\d \d+))/
|
69
57
|
lstart = Time.parse($~[:lstart])
|
70
|
-
|
58
|
+
result = result.sub($~[:lstart], '')
|
71
59
|
keys_size -= 1
|
72
60
|
end
|
73
|
-
values =
|
74
|
-
data = Hash[
|
75
|
-
@keys.zip([lstart.to_s, values].reject(&:empty?).flatten).map do |k,v|
|
76
|
-
v = Converters[@types_map[k]].call(v) if @types_map.include?(k)
|
77
|
-
[k,v]
|
78
|
-
end
|
79
|
-
]
|
61
|
+
values = [lstart.to_s, result.chomp.strip.split(/\s+/, keys_size)]
|
62
|
+
data = Hash[@keys.zip(values.reject(&:empty?).flatten)]
|
80
63
|
data['elapsed_time'] = (Time.now - Time.parse(data['start_time'])).to_i if data['start_time']
|
81
64
|
next unless @lookup_user.nil? || @lookup_user.include?(data['user'])
|
82
|
-
|
83
|
-
|
65
|
+
emit_tag = tag.dup
|
66
|
+
filter_record(emit_tag, Engine.now, data)
|
67
|
+
Engine.emit(emit_tag, Engine.now, data)
|
84
68
|
end
|
85
69
|
io.close
|
86
70
|
sleep @interval
|
@@ -115,12 +99,5 @@ module Fluent
|
|
115
99
|
OS.unix? and not OS.mac?
|
116
100
|
end
|
117
101
|
end
|
118
|
-
|
119
|
-
def get_placeholder
|
120
|
-
return {
|
121
|
-
'__HOSTNAME__' => @hostname,
|
122
|
-
'${hostname}' => @hostname,
|
123
|
-
}
|
124
|
-
end
|
125
102
|
end
|
126
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-watch-process
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -43,6 +43,38 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fluent-mixin-rewrite-tag-name
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fluent-mixin-type-converter
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description:
|
47
79
|
email:
|
48
80
|
- y.ken.studio@gmail.com
|