fluent-plugin-jvmwatcher 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +115 -0
- data/Rakefile +11 -0
- data/fluent-plugin-jvmwatcher.gemspec +23 -0
- data/lib/fluent/plugin/in_jvmwatcher.rb +66 -0
- data/lib/fluent/plugin/jvmwatcher/bin/JvmProcCheck.sh +20 -0
- data/lib/fluent/plugin/jvmwatcher/bin/JvmWatcher.sh +20 -0
- data/lib/fluent/plugin/jvmwatcher/bin/setEnv.sh +8 -0
- data/lib/fluent/plugin/jvmwatcher/bin/setEnv.sh.template +8 -0
- data/lib/fluent/plugin/jvmwatcher/config/commons-logging.properties +2 -0
- data/lib/fluent/plugin/jvmwatcher/config/config_sample.json +6 -0
- data/lib/fluent/plugin/jvmwatcher/config/log4j.xml.template +41 -0
- data/lib/fluent/plugin/jvmwatcher/lib/commons-logging-1.1.2.jar +0 -0
- data/lib/fluent/plugin/jvmwatcher/lib/jackson-core-2.2.0.jar +0 -0
- data/lib/fluent/plugin/jvmwatcher/lib/jvmwatcher.jar +0 -0
- data/lib/fluent/plugin/jvmwatcher/lib/log4j-1.2.17.jar +0 -0
- data/lib/fluent/plugin/jvmwatcher/log/empty +0 -0
- data/lib/fluent/plugin/jvmwatcher_util.rb +133 -0
- data/test/helper.rb +30 -0
- data/test/plugin/test_in_jvmwatcher.rb +23 -0
- data/test/plugin/test_jvmwatcher_util.rb +58 -0
- metadata +110 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013 MasayukiMiyake
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
Java VM status input plugin for Fluent
|
2
|
+
====
|
3
|
+
fluent-plugin-jvmwatcher is input plugin which collects the CPU usage rate and the memory usage of more than one JavaVM, information on GC to the constant period.
|
4
|
+
|
5
|
+
fluent-plugin-jvmwatcherは、複数のJavaVMの、CPU使用率やメモリ使用量、GCの情報を、一定周期に収集するinput pluginです。
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
|
10
|
+
What you have to do is only installing like this:
|
11
|
+
|
12
|
+
$ gem install fluent-plugin-jvmwatcher
|
13
|
+
|
14
|
+
Then fluent automatically loads the plugin installed.
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
<source>
|
19
|
+
type jvmwatcher
|
20
|
+
log_interval 1000
|
21
|
+
log_buff_num 3
|
22
|
+
jvm_refind_interval 30000
|
23
|
+
filter_config_path filter_config.json
|
24
|
+
tag jvmwatcher.log
|
25
|
+
</source>
|
26
|
+
|
27
|
+
## filtering Configuration
|
28
|
+
|
29
|
+
{"target" :
|
30
|
+
[
|
31
|
+
{ "shortname" : "TestJavaProcess" , "pattern" : "(jvmwatcher.test.TestJavaProcess)"},
|
32
|
+
{ "shortname" : "Tomcat" , "pattern" : "(org.apache.catalina)"}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
There is a sample of the command which outputs the list of the Java process under the directory of fluent-plugin-jvmwatcher which was installed in gem and the definition file of filtering.
|
37
|
+
|
38
|
+
gemでインストールした、fluent-plugin-jvmwatcherのディレクトリの下に、Javaプロセスの一覧を出力するコマンドと、フィルタリングの定義ファイルのサンプルがあります。
|
39
|
+
|
40
|
+
|
41
|
+
fluent-plugin-jvmwatcher-*.*.*
|
42
|
+
|-lib
|
43
|
+
|-fluent
|
44
|
+
|-plugin
|
45
|
+
|-jvmwatcher
|
46
|
+
|- bin
|
47
|
+
| |-JvmProcCheck.sh
|
48
|
+
|-config
|
49
|
+
| |-config_sample.json <-- sample file
|
50
|
+
| |-filter_config.json <-- It is the filter definition file which you created.
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
###Java process listup.
|
55
|
+
Before creating the definition file of filtering, it executes JvmProcCheck.sh command and it makes output the list of the Java process which is working on the host.
|
56
|
+
It finds the character string which suited the key word to use for the regular expression to set to "pattern" from the name of the Java process which is output by [ CommandLine ] of the list.
|
57
|
+
|
58
|
+
フィルタリングの定義ファイルを作成する前に、JvmProcCheck.shコマンドを実行して、ホスト上で動作しているJavaプロセスの一覧を出力させます。
|
59
|
+
一覧の[CommandLine]に出力されるJavaプロセスの名称から、"pattern"に設定する正規表現に使用するキーワードに適した文字列を、見つけ出します。
|
60
|
+
|
61
|
+
cd lib/fluent/plugin/jvmwatcher/bin
|
62
|
+
./JvmProcCheck.sh
|
63
|
+
|
64
|
+
Output
|
65
|
+
|
66
|
+
-- process list start --
|
67
|
+
Target prosecc [pid]=7552 [ShortName]=org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -os linux -ws gtk -arch x86_64 -showsplash -launcher /home/miyake/Develop/Java/Tools/eclipse_juno/eclipse -name Eclipse --launcher.library /home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20120913-144807/eclipse_1502.so -startup /home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar --launcher.overrideVmargs -exitdata 60009 -product org.eclipse.epp.package.jee.product -vm /usr/bin/java -vmargs -Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -XX:MaxPermSize=256m -Xms512m -Xmx1024m -javaagent:/home/miyake/Develop/Java/Tools/eclipse_juno/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar -jar /home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar [CommandLine]=/home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -os linux -ws gtk -arch x86_64 -showsplash -launcher /home/miyake/Develop/Java/Tools/eclipse_juno/eclipse -name Eclipse --launcher.library /home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20120913-144807/eclipse_1502.so -startup /home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar --launcher.overrideVmargs -exitdata 60009 -product org.eclipse.epp.package.jee.product -vm /usr/bin/java -vmargs -Dosgi.requiredJavaVersion=1.5 -Dhelp.lucene.tokenizer=standard -XX:MaxPermSize=256m -Xms512m -Xmx1024m -javaagent:/home/miyake/Develop/Java/Tools/eclipse_juno/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar -jar /home/miyake/Develop/Java/Tools/eclipse_juno//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
|
68
|
+
Target prosecc [pid]=7723 [ShortName]=sun.tools.jconsole.JConsole [CommandLine]=sun.tools.jconsole.JConsole
|
69
|
+
Target prosecc [pid]=2677 [ShortName]=org.apache.catalina.startup.Bootstrap start [CommandLine]=org.apache.catalina.startup.Bootstrap start
|
70
|
+
Target prosecc [pid]=7684 [ShortName]=jvmwatcher.test.TestJavaProcess 4096 512 20 5 [CommandLine]=jvmwatcher.test.TestJavaProcess 4096 512 20 5
|
71
|
+
Target prosecc [pid]=7640 [ShortName]=jvmwatcher.test.TestJavaProcess 1024 2048 10 5 [CommandLine]=jvmwatcher.test.TestJavaProcess 1024 2048 10 5
|
72
|
+
-- process list end --
|
73
|
+
|
74
|
+
###Java process filtering check.
|
75
|
+
Create the definition file of filtering from the found key word and preserve it under config.
|
76
|
+
It executes JvmProcCheck.sh command and it confirms that only a Java process for the purpose is done by filtering by the definition file of created filtering.
|
77
|
+
The way of confirming set the definition file of created filtering to the argument of the JvmProcCheck.sh command and execute it.
|
78
|
+
|
79
|
+
見つけ出したキーワードから、フィルタリングの定義ファイルを作成し、configの下に保存して下さい。
|
80
|
+
作成したフィルタリングの定義ファイルによって、目的のJavaプロセスだけがフィルタリングされることは、JvmProcCheck.shコマンドを実行して確認します。
|
81
|
+
確認方法は、作成したフィルタリングの定義ファイルを、JvmProcCheck.shコマンドの引数に設定して、実行してください。
|
82
|
+
|
83
|
+
./JvmProcCheck.sh ../config/filter_config.json
|
84
|
+
|
85
|
+
Output
|
86
|
+
|
87
|
+
-- process list start --
|
88
|
+
Target prosecc [pid]=2677 [ShortName]=Tomcat [CommandLine]=org.apache.catalina.startup.Bootstrap start
|
89
|
+
Target prosecc [pid]=7684 [ShortName]=TestJavaProcess [CommandLine]=jvmwatcher.test.TestJavaProcess 4096 512 20 5
|
90
|
+
Target prosecc [pid]=7640 [ShortName]=TestJavaProcess [CommandLine]=jvmwatcher.test.TestJavaProcess 1024 2048 10 5
|
91
|
+
-- process list end --
|
92
|
+
|
93
|
+
|
94
|
+
##JVM status log sample
|
95
|
+
It is the sample of the log which was output from jvmwatcher.
|
96
|
+
This sample is outputting only a necessary Java process using filter_config_path of the configuration.
|
97
|
+
The name to set to "shortname" of the definition file of filtering is output by "name" of the output log.
|
98
|
+
When not using filter_config_path of the configuration, the contents which are the same as "display_name" are output by "shortname".
|
99
|
+
Also, the log of all Java processes of the node is output.
|
100
|
+
|
101
|
+
jvmwatcherから出力されたログのサンプルです。
|
102
|
+
このサンプルは、コンフィグレーションのfilter_config_pathを使用して、必要なJavaプロセスだけを出力しています。
|
103
|
+
出力されているログの"name"には、フィルタリングの定義ファイルの"shortname"に設定している名称が出力されます。
|
104
|
+
コンフィグレーションのfilter_config_pathを使用しない場合は、"shortname"に"display_name"と同じ内容が出力されます。また、ノードのすべてのJavaプロセスのログが出力されます。
|
105
|
+
|
106
|
+
2013-05-11T13:53:50+09:00 jvmwatcher.log {"logtime":1368248030423,"host_name":"nanoha","proc_state":"START_PROCESS","pid":2677,"name":"Tomcat","display_name":"org.apache.catalina.startup.Bootstrap start","start_time":1368235715885,"up_time":12314590,"cpu_usage":0.13756041,"compile_time":2280,"c_load_cnt":2110,"c_unload_cnt":0,"c_total_load_cnt":2111,"th_cnt":15,"daemon_th_cnt":14,"peak_th_cnt":15,"heap_init":62766272,"heap_used":14218752,"heap_commit":60227584,"heap_max":892928000,"notheap_init":24313856,"notheap_used":18505232,"notheap_commit":31784960,"notheap_max":224395264,"pending_fin_cnt":0,"total_phy_mem_size":4017041408,"total_swap_mem_size":4160741376,"free_phy_mem_size":1830621184,"free_swap_mem_size":4160741376,"commit_vmem_size":2432827392,"gc_collect":[{"gc_mgr_name":"PS MarkSweep","gc_coll_cnt":4,"gc_coll_time":159},{"gc_mgr_name":"PS Scavenge","gc_coll_cnt":7,"gc_coll_time":44}]}
|
107
|
+
2013-05-11T13:53:51+09:00 jvmwatcher.log {"logtime":1368248031423,"host_name":"nanoha","proc_state":"LIVE_PROCESS","pid":2677,"name":"Tomcat","display_name":"org.apache.catalina.startup.Bootstrap start","start_time":1368235715885,"up_time":12315551,"cpu_usage":4.162331,"compile_time":2334,"c_load_cnt":2153,"c_unload_cnt":0,"c_total_load_cnt":2153,"th_cnt":15,"daemon_th_cnt":14,"peak_th_cnt":15,"heap_init":62766272,"heap_used":15915928,"heap_commit":60227584,"heap_max":892928000,"notheap_init":24313856,"notheap_used":18749552,"notheap_commit":31784960,"notheap_max":224395264,"pending_fin_cnt":0,"total_phy_mem_size":4017041408,"total_swap_mem_size":4160741376,"free_phy_mem_size":1805737984,"free_swap_mem_size":4160741376,"commit_vmem_size":2432827392,"gc_collect":[{"gc_mgr_name":"PS MarkSweep","gc_coll_cnt":4,"gc_coll_time":159},{"gc_mgr_name":"PS Scavenge","gc_coll_cnt":7,"gc_coll_time":44}]}
|
108
|
+
2013-05-11T13:53:52+09:00 jvmwatcher.log {"logtime":1368248032423,"host_name":"nanoha","proc_state":"LIVE_PROCESS","pid":2677,"name":"Tomcat","display_name":"org.apache.catalina.startup.Bootstrap start","start_time":1368235715885,"up_time":12316551,"cpu_usage":1.0,"compile_time":2334,"c_load_cnt":2154,"c_unload_cnt":0,"c_total_load_cnt":2154,"th_cnt":15,"daemon_th_cnt":14,"peak_th_cnt":15,"heap_init":62766272,"heap_used":16446200,"heap_commit":60227584,"heap_max":892928000,"notheap_init":24313856,"notheap_used":18755256,"notheap_commit":31784960,"notheap_max":224395264,"pending_fin_cnt":0,"total_phy_mem_size":4017041408,"total_swap_mem_size":4160741376,"free_phy_mem_size":1803935744,"free_swap_mem_size":4160741376,"commit_vmem_size":2432827392,"gc_collect":[{"gc_mgr_name":"PS MarkSweep","gc_coll_cnt":4,"gc_coll_time":159},{"gc_mgr_name":"PS Scavenge","gc_coll_cnt":7,"gc_coll_time":44}]}
|
109
|
+
2013-05-11T13:53:50+09:00 jvmwatcher.log {"logtime":1368248030850,"host_name":"nanoha","proc_state":"START_PROCESS","pid":7684,"name":"TestJavaProcess","display_name":"jvmwatcher.test.TestJavaProcess 4096 512 20 5","start_time":1368244328237,"up_time":3702631,"cpu_usage":2.3138952,"compile_time":82,"c_load_cnt":1126,"c_unload_cnt":0,"c_total_load_cnt":1127,"th_cnt":14,"daemon_th_cnt":8,"peak_th_cnt":14,"heap_init":62766272,"heap_used":5471312,"heap_commit":6881280,"heap_max":892928000,"notheap_init":24313856,"notheap_used":9034992,"notheap_commit":24313856,"notheap_max":224395264,"pending_fin_cnt":0,"total_phy_mem_size":4017041408,"total_swap_mem_size":4160741376,"free_phy_mem_size":1817698304,"free_swap_mem_size":4160741376,"commit_vmem_size":2421960704,"gc_collect":[{"gc_mgr_name":"PS MarkSweep","gc_coll_cnt":1243,"gc_coll_time":10825},{"gc_mgr_name":"PS Scavenge","gc_coll_cnt":12796,"gc_coll_time":11733}]}
|
110
|
+
2013-05-11T13:53:51+09:00 jvmwatcher.log {"logtime":1368248031851,"host_name":"nanoha","proc_state":"LIVE_PROCESS","pid":7684,"name":"TestJavaProcess","display_name":"jvmwatcher.test.TestJavaProcess 4096 512 20 5","start_time":1368244328237,"up_time":3703650,"cpu_usage":7.8508344,"compile_time":96,"c_load_cnt":1169,"c_unload_cnt":0,"c_total_load_cnt":1169,"th_cnt":14,"daemon_th_cnt":8,"peak_th_cnt":14,"heap_init":62766272,"heap_used":6286216,"heap_commit":9043968,"heap_max":892928000,"notheap_init":24313856,"notheap_used":9261848,"notheap_commit":24313856,"notheap_max":224395264,"pending_fin_cnt":0,"total_phy_mem_size":4017041408,"total_swap_mem_size":4160741376,"free_phy_mem_size":1804816384,"free_swap_mem_size":4160741376,"commit_vmem_size":2421960704,"gc_collect":[{"gc_mgr_name":"PS MarkSweep","gc_coll_cnt":1243,"gc_coll_time":10825},{"gc_mgr_name":"PS Scavenge","gc_coll_cnt":12797,"gc_coll_time":11735}]}
|
111
|
+
2013-05-11T13:53:52+09:00 jvmwatcher.log {"logtime":1368248032852,"host_name":"nanoha","proc_state":"LIVE_PROCESS","pid":7684,"name":"TestJavaProcess","display_name":"jvmwatcher.test.TestJavaProcess 4096 512 20 5","start_time":1368244328237,"up_time":3704647,"cpu_usage":4.5135407,"compile_time":102,"c_load_cnt":1171,"c_unload_cnt":0,"c_total_load_cnt":1171,"th_cnt":14,"daemon_th_cnt":8,"peak_th_cnt":14,"heap_init":62766272,"heap_used":7337016,"heap_commit":9437184,"heap_max":892928000,"notheap_init":24313856,"notheap_used":9278600,"notheap_commit":24313856,"notheap_max":224395264,"pending_fin_cnt":0,"total_phy_mem_size":4017041408,"total_swap_mem_size":4160741376,"free_phy_mem_size":1803935744,"free_swap_mem_size":4160741376,"commit_vmem_size":2421960704,"gc_collect":[{"gc_mgr_name":"PS MarkSweep","gc_coll_cnt":1243,"gc_coll_time":10825},{"gc_mgr_name":"PS Scavenge","gc_coll_cnt":12798,"gc_coll_time":11736}]}
|
112
|
+
|
113
|
+
In the date and time which is output at the head of the log, it is generating from "logtime" which is the time by which the information was acquired actually from JavaVM.
|
114
|
+
|
115
|
+
ログの先頭に出力されている日時は、実際にJavaVMから情報を取得した時間である"logtime"から生成しています。
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-jvmwatcher"
|
6
|
+
gem.version = "0.1.2"
|
7
|
+
gem.authors = ["MasayukiMiyake"]
|
8
|
+
gem.email = ["masayukimiyake97@gmail.com"]
|
9
|
+
gem.description = %q{It is the input plugin of fluentd which collects the condition of Java VM.}
|
10
|
+
gem.summary = %q{It is the input plugin of fluentd which collects the condition of Java VM.}
|
11
|
+
gem.homepage = "https://github.com/MasayukiMiyake97/fluent-plugin-jvmwatcher.git"
|
12
|
+
|
13
|
+
gem.rubyforge_project = "fluent-plugin-jvmwatcher"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_runtime_dependency "fluentd"
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Fluent
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'fluent/plugin/jvmwatcher_util'
|
5
|
+
|
6
|
+
class JvmwatcherInput < Input
|
7
|
+
Plugin.register_input('jvmwatcher', self)
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
@log4j_path = JvmwatcherUtil.make_log4j_file
|
12
|
+
@setenv_path = JvmwatcherUtil.make_setenv_file
|
13
|
+
@bin_path = JvmwatcherUtil.find_watcher_java_path(JvmwatcherUtil::BinDirName)
|
14
|
+
@jvmwatcher_connamd = File.join(@bin_path, "JvmWatcher.sh")
|
15
|
+
end
|
16
|
+
|
17
|
+
config_param :tag, :string
|
18
|
+
config_param :filter_config_path, :string, :default => nil
|
19
|
+
config_param :log_interval, :integer, :default => 1000
|
20
|
+
config_param :log_buff_num, :integer, :default => 1
|
21
|
+
config_param :jvm_refind_interval, :integer, :default => 20000
|
22
|
+
|
23
|
+
def start
|
24
|
+
@config_path = JvmwatcherUtil.find_filter_config_path(@filter_config_path)
|
25
|
+
command = "#{@jvmwatcher_connamd} '#{@config_path}' #{@jvm_refind_interval} #{@log_interval} #{@log_buff_num} #{@setenv_path}"
|
26
|
+
|
27
|
+
@io = IO.popen(command, "r")
|
28
|
+
@pid = @io.pid
|
29
|
+
@thread = Thread.new(&method(:run))
|
30
|
+
end
|
31
|
+
|
32
|
+
def shutdown
|
33
|
+
Process.kill(:TERM, @pid)
|
34
|
+
if @thread.join(60)
|
35
|
+
return
|
36
|
+
end
|
37
|
+
Process.kill(:KILL, @pid)
|
38
|
+
@yhread.join
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
@io.each_line(&method(:each_line))
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def each_line(line)
|
47
|
+
begin
|
48
|
+
line.chomp!
|
49
|
+
# JSON text convert to data
|
50
|
+
data = JSON.parse(line)
|
51
|
+
# get log time
|
52
|
+
logtime = data["logtime"] / 1000
|
53
|
+
|
54
|
+
Engine.emit(@tag, logtime.to_i , data)
|
55
|
+
rescue
|
56
|
+
$log.error "exec failed to emit", :error=>$!.to_s
|
57
|
+
$log.warn_backtrace $!.backtrace
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
source setEnv.sh
|
4
|
+
|
5
|
+
# get JDK path
|
6
|
+
#pathtojava=$(readlink -e $(which javac))
|
7
|
+
#JDK_LIB=${pathtojava%/*/*}/lib
|
8
|
+
|
9
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/jvmwatcher.jar
|
10
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/jackson-core-2.2.0.jar
|
11
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/commons-logging-1.1.2.jar
|
12
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/log4j-1.2.17.jar
|
13
|
+
export CLASSPATH=$CLASSPATH:$JDK_LIB/tools.jar
|
14
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_CONFIGPATH
|
15
|
+
|
16
|
+
echo $1
|
17
|
+
|
18
|
+
java org.fluentd.jvmwatcher.JvmWatcher targetlist $1
|
19
|
+
|
20
|
+
exit 0
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
localhostname=$(hostname)
|
4
|
+
|
5
|
+
source $5
|
6
|
+
|
7
|
+
# get JDK path
|
8
|
+
#pathtojava=$(readlink -e $(which javac))
|
9
|
+
#JDK_LIB=${pathtojava%/*/*}/lib
|
10
|
+
|
11
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/jvmwatcher.jar
|
12
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/jackson-core-2.2.0.jar
|
13
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/commons-logging-1.1.2.jar
|
14
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_LIBPATH/log4j-1.2.17.jar
|
15
|
+
export CLASSPATH=$CLASSPATH:$JDK_LIB/tools.jar
|
16
|
+
export CLASSPATH=$CLASSPATH:$WATCHER_CONFIGPATH
|
17
|
+
|
18
|
+
java org.fluentd.jvmwatcher.JvmWatcher watcher $1 $2 $3 $4 $localhostname
|
19
|
+
|
20
|
+
exit 0
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
3
|
+
|
4
|
+
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" >
|
5
|
+
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
6
|
+
<param name="Threshold" value="FATAL" />
|
7
|
+
<param name="Encoding" value="UTF-8" />
|
8
|
+
<param name="Target" value="System.out" />
|
9
|
+
<layout class="org.apache.log4j.PatternLayout">
|
10
|
+
<param name="ConversionPattern" value="[%5p][%d{yyyy-MM-dd HH:mm:ss}] %c{1} - %m%n" />
|
11
|
+
</layout>
|
12
|
+
</appender>
|
13
|
+
|
14
|
+
<appender name="logfile" class="org.apache.log4j.DailyRollingFileAppender">
|
15
|
+
<param name="Threshold" value="DEBUG" />
|
16
|
+
<param name="Encoding" value="UTF-8" />
|
17
|
+
<param name="File" value="[LOG_PATH]/log.log" />
|
18
|
+
<param name="Append" value="true" />
|
19
|
+
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
20
|
+
<layout class="org.apache.log4j.PatternLayout">
|
21
|
+
<param name="ConversionPattern" value="[%5p][%d{yyyy-MM-dd HH:mm:ss}] %c{1} - %m%n" />
|
22
|
+
</layout>
|
23
|
+
</appender>
|
24
|
+
|
25
|
+
<appender name="errfile" class="org.apache.log4j.DailyRollingFileAppender">
|
26
|
+
<param name="Threshold" value="ERROR" />
|
27
|
+
<param name="Encoding" value="UTF-8" />
|
28
|
+
<param name="File" value="[LOG_PATH]/err.log" />
|
29
|
+
<param name="Append" value="true" />
|
30
|
+
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
31
|
+
<layout class="org.apache.log4j.PatternLayout">
|
32
|
+
<param name="ConversionPattern" value="[%5p][%d{yyyy-MM-dd HH:mm:ss}] %c{1} - %m%n" />
|
33
|
+
</layout>
|
34
|
+
</appender>
|
35
|
+
|
36
|
+
<root>
|
37
|
+
<priority value="debug" />
|
38
|
+
<appender-ref ref="logfile"/>
|
39
|
+
</root>
|
40
|
+
</log4j:configuration>
|
41
|
+
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
module JvmwatcherUtil
|
3
|
+
|
4
|
+
SetEnvFileName = "setEnvWatcher.sh"
|
5
|
+
Log4JFileName = "log4j.xml"
|
6
|
+
SetEnvTemplateFileName = "setEnv.sh.template"
|
7
|
+
Log4JTemplateFileName = "log4j.xml.template"
|
8
|
+
|
9
|
+
BinDirName = "bin"
|
10
|
+
LibDirName = "lib"
|
11
|
+
ConfigDirName = "config"
|
12
|
+
LogDirName = "log"
|
13
|
+
|
14
|
+
def find_watcher_java_path (dir_name, file_name = nil)
|
15
|
+
|
16
|
+
java_path = nil
|
17
|
+
|
18
|
+
$LOAD_PATH.map do |load_path|
|
19
|
+
path = File.join(load_path, "fluent/plugin") # make fluentd plugin path
|
20
|
+
if File.directory?(path)
|
21
|
+
|
22
|
+
# find target directory
|
23
|
+
Dir.glob("**/jvmwatcher/#{dir_name}").each do |path_name|
|
24
|
+
|
25
|
+
next unless File.directory?(path_name) # chech directory
|
26
|
+
|
27
|
+
if file_name
|
28
|
+
# check file
|
29
|
+
java_path = File.join(path_name, file_name)
|
30
|
+
java_path = nil unless File.file?(java_path)
|
31
|
+
else
|
32
|
+
java_path = path_name
|
33
|
+
end
|
34
|
+
|
35
|
+
break if java_path
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
break if java_path
|
40
|
+
end
|
41
|
+
|
42
|
+
return java_path
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def make_setenv_file
|
47
|
+
|
48
|
+
template_path = find_watcher_java_path(BinDirName, SetEnvTemplateFileName)
|
49
|
+
output_path = find_watcher_java_path(BinDirName)
|
50
|
+
lib_path = find_watcher_java_path(LibDirName)
|
51
|
+
config_path = find_watcher_java_path(ConfigDirName)
|
52
|
+
|
53
|
+
# path nil check
|
54
|
+
return nil unless template_path
|
55
|
+
return nil unless output_path
|
56
|
+
return nil unless lib_path
|
57
|
+
return nil unless config_path
|
58
|
+
|
59
|
+
output_path = File.join(output_path, SetEnvFileName)
|
60
|
+
# make setEnvWatcher.sh
|
61
|
+
temp_io = File.open(template_path, "r")
|
62
|
+
env_io = File.open(output_path, "w")
|
63
|
+
|
64
|
+
temp_io.each do |line|
|
65
|
+
line.chomp!
|
66
|
+
line = line.gsub(/\[LIB_PATH\]/, lib_path)
|
67
|
+
line = line.gsub(/\[CONFIG_PATH\]/, config_path)
|
68
|
+
|
69
|
+
env_io.puts(line)
|
70
|
+
end
|
71
|
+
|
72
|
+
temp_io.close
|
73
|
+
env_io.close
|
74
|
+
|
75
|
+
return output_path
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def make_log4j_file
|
81
|
+
|
82
|
+
template_path = find_watcher_java_path(ConfigDirName, Log4JTemplateFileName)
|
83
|
+
output_path = find_watcher_java_path(ConfigDirName)
|
84
|
+
log_path = find_watcher_java_path(LogDirName)
|
85
|
+
|
86
|
+
# path nil check
|
87
|
+
return nil unless template_path
|
88
|
+
return nil unless output_path
|
89
|
+
return nil unless log_path
|
90
|
+
|
91
|
+
output_path = File.join(output_path, Log4JFileName)
|
92
|
+
# make setEnvWatcher.sh
|
93
|
+
temp_io = File.open(template_path, "r")
|
94
|
+
env_io = File.open(output_path, "w")
|
95
|
+
|
96
|
+
temp_io.each do |line|
|
97
|
+
line.chomp!
|
98
|
+
line = line.gsub(/\[LOG_PATH\]/, log_path)
|
99
|
+
|
100
|
+
env_io.puts(line)
|
101
|
+
end
|
102
|
+
|
103
|
+
temp_io.close
|
104
|
+
env_io.close
|
105
|
+
|
106
|
+
return output_path
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def find_filter_config_path (config_path)
|
112
|
+
|
113
|
+
# check nil
|
114
|
+
return "NO_CONFIG" unless config_path
|
115
|
+
|
116
|
+
unless File.file?(config_path)
|
117
|
+
|
118
|
+
path = find_watcher_java_path(ConfigDirName)
|
119
|
+
config_path = File.join(path, config_path)
|
120
|
+
config_path = "NO_CONFIG" unless File.file?(config_path)
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
return config_path
|
125
|
+
end
|
126
|
+
|
127
|
+
module_function :find_watcher_java_path
|
128
|
+
module_function :make_setenv_file
|
129
|
+
module_function :make_log4j_file
|
130
|
+
module_function :find_filter_config_path
|
131
|
+
|
132
|
+
end
|
133
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/in_jvmwatcher'
|
26
|
+
require 'fluent/plugin/jvmwatcher_util'
|
27
|
+
|
28
|
+
class Test::Unit::TestCase
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class JvmWatcherInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
tag jvmwatcher.log
|
10
|
+
]
|
11
|
+
|
12
|
+
def create_driver(conf = CONFIG)
|
13
|
+
Fluent::Test::InputTestDriver.new(Fluent::ScribeInput).configure(conf)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_configure
|
17
|
+
d = create_driver
|
18
|
+
#### check configurations
|
19
|
+
assert_equal 'jvmwatcher.log', d.instance.tag
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class JvmWatcherUtilTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_find_watcher_java_path
|
10
|
+
path = JvmwatcherUtil.find_watcher_java_path("bin")
|
11
|
+
puts path
|
12
|
+
path = JvmwatcherUtil.find_watcher_java_path("lib")
|
13
|
+
puts path
|
14
|
+
path = JvmwatcherUtil.find_watcher_java_path("config")
|
15
|
+
puts path
|
16
|
+
path = JvmwatcherUtil.find_watcher_java_path("log")
|
17
|
+
puts path
|
18
|
+
path = JvmwatcherUtil.find_watcher_java_path("logg")
|
19
|
+
puts path
|
20
|
+
path = JvmwatcherUtil.find_watcher_java_path("bin", JvmwatcherUtil::SetEnvFileName)
|
21
|
+
puts path
|
22
|
+
path = JvmwatcherUtil.find_watcher_java_path("config", JvmwatcherUtil::Log4JFileName)
|
23
|
+
puts path
|
24
|
+
path = JvmwatcherUtil.find_watcher_java_path("bin", JvmwatcherUtil::SetEnvTemplateFileName)
|
25
|
+
puts path
|
26
|
+
path = JvmwatcherUtil.find_watcher_java_path("config", JvmwatcherUtil::Log4JTemplateFileName)
|
27
|
+
puts path
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_make_setenv_file
|
31
|
+
|
32
|
+
path = JvmwatcherUtil.make_setenv_file
|
33
|
+
puts "setenv=" << path
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_make_log4j_file
|
38
|
+
|
39
|
+
path = JvmwatcherUtil.make_log4j_file
|
40
|
+
puts "setenv=" << path
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_find_filter_config_path
|
45
|
+
|
46
|
+
path = JvmwatcherUtil.find_filter_config_path(nil)
|
47
|
+
puts "nil config=" + path
|
48
|
+
path = JvmwatcherUtil.find_filter_config_path("config_sample.json")
|
49
|
+
puts "config_sample.json config=" + path
|
50
|
+
path = JvmwatcherUtil.find_filter_config_path("/home/miyake/Develop/Project/fluent/fluent-plugin-jvmwatcher/lib/fluent/plugin/jvmwatcher/config/config_sample.json")
|
51
|
+
puts "full path config=" + path
|
52
|
+
path = JvmwatcherUtil.find_filter_config_path("config.json")
|
53
|
+
puts "nil config=" + path
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-jvmwatcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- MasayukiMiyake
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: fluentd
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: It is the input plugin of fluentd which collects the condition of Java
|
47
|
+
VM.
|
48
|
+
email:
|
49
|
+
- masayukimiyake97@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- fluent-plugin-jvmwatcher.gemspec
|
60
|
+
- lib/fluent/plugin/in_jvmwatcher.rb
|
61
|
+
- lib/fluent/plugin/jvmwatcher/bin/JvmProcCheck.sh
|
62
|
+
- lib/fluent/plugin/jvmwatcher/bin/JvmWatcher.sh
|
63
|
+
- lib/fluent/plugin/jvmwatcher/bin/setEnv.sh
|
64
|
+
- lib/fluent/plugin/jvmwatcher/bin/setEnv.sh.template
|
65
|
+
- lib/fluent/plugin/jvmwatcher/config/commons-logging.properties
|
66
|
+
- lib/fluent/plugin/jvmwatcher/config/config_sample.json
|
67
|
+
- lib/fluent/plugin/jvmwatcher/config/log4j.xml.template
|
68
|
+
- lib/fluent/plugin/jvmwatcher/lib/commons-logging-1.1.2.jar
|
69
|
+
- lib/fluent/plugin/jvmwatcher/lib/jackson-core-2.2.0.jar
|
70
|
+
- lib/fluent/plugin/jvmwatcher/lib/jvmwatcher.jar
|
71
|
+
- lib/fluent/plugin/jvmwatcher/lib/log4j-1.2.17.jar
|
72
|
+
- lib/fluent/plugin/jvmwatcher/log/empty
|
73
|
+
- lib/fluent/plugin/jvmwatcher_util.rb
|
74
|
+
- test/helper.rb
|
75
|
+
- test/plugin/test_in_jvmwatcher.rb
|
76
|
+
- test/plugin/test_jvmwatcher_util.rb
|
77
|
+
homepage: https://github.com/MasayukiMiyake97/fluent-plugin-jvmwatcher.git
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
hash: -3280767746614921117
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: -3280767746614921117
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project: fluent-plugin-jvmwatcher
|
103
|
+
rubygems_version: 1.8.25
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: It is the input plugin of fluentd which collects the condition of Java VM.
|
107
|
+
test_files:
|
108
|
+
- test/helper.rb
|
109
|
+
- test/plugin/test_in_jvmwatcher.rb
|
110
|
+
- test/plugin/test_jvmwatcher_util.rb
|