embulk-input-jstat 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9a6b33a6170e95d4088a5022154f93a4f0a97b8
4
+ data.tar.gz: 750c33b7fe05b4120fbf9384416d7d9a1c2adb24
5
+ SHA512:
6
+ metadata.gz: 28d9bcf5afad16fb7b08a481bb656c6dea2f974ae1e030660021db3dfb2c90200337c34a006fd289fdbaf610034e1120ef389d775ca5ae03e55e800d76898a75
7
+ data.tar.gz: 8ce0f55384e76c83aabb5ff03ce225798ba30da9202570b2013c5dd5d04df0ee01f7ffec029f8c569cd4030187d59f25388546d104650e827df69e3cd95db446
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.swp
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 KUBOTA Yuji
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,42 @@
1
+ # Embulk::Input::Jstat
2
+
3
+ [Embulk](https://github.com/embulk/embulk) input plugin for [jstat](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html).
4
+ Now, this plugin supports only JDK8.
5
+
6
+ ## Installation
7
+
8
+ Run this command with your embulk binary.
9
+
10
+ ```ruby
11
+ $ embulk gem install embulk-input-jstat
12
+ ```
13
+
14
+ ## Configuration
15
+
16
+ Specify in your config.yml file
17
+
18
+ ```yaml
19
+ in:
20
+ type: jstat
21
+ paths: [/tmp, /path/to/jstat_files, /other/path/to/jstats_files]
22
+ option: -gcutil
23
+ timestamp: false
24
+ ```
25
+
26
+ - type: specify this plugin as `jstat`.
27
+ - paths: specify paths where jstat files(\*.log) are. (optional, default: /tmp)
28
+ - option: specify a stat option of jstat, e.g., -gcutil. (optional, default: -gcutil)
29
+ - timestamp: specify whether your jstat files include a timestamp column or not. (optional, default: false)
30
+
31
+ ## TODO
32
+
33
+ - support JDK7, JDK6.
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/ykubota/embulk-input-jstat/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
42
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "embulk-input-jstat"
7
+ spec.version = "0.0.3"
8
+ spec.authors = ["KUBOTA Yuji"]
9
+ spec.email = ["kubota.yuji@gmail.com"]
10
+ spec.summary = %q{Embulk plugin for jstat input.}
11
+ spec.description = %q{Embulk input plugin for Java Virtual Machine statistics by jstat command.}
12
+ spec.homepage = "https://github.com/ykubota/embulk-input-jstat"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
@@ -0,0 +1,233 @@
1
+ # -*- coding:utf-8 -*-
2
+
3
+ module Embulk
4
+ class InputJstat < InputPlugin
5
+ require 'json'
6
+
7
+ Plugin.register_input('jstat', self)
8
+
9
+ # output columns of jstat (JDK8)
10
+ JSTAT_COLUMNS = {
11
+ class: {
12
+ Loaded: 'int',
13
+ Bytes: 'double',
14
+ Unloader: 'int',
15
+ Bytes: 'double',
16
+ Time: 'double'
17
+ },
18
+ compiler: {
19
+ Compiled: 'int',
20
+ Failed: 'int',
21
+ Invalid: 'int',
22
+ Time: 'double',
23
+ FailedType: 'int',
24
+ FailedMethod: 'string'
25
+ },
26
+ gc: {
27
+ S0C: 'double',
28
+ S1C: 'double',
29
+ S0U: 'double',
30
+ S1U: 'double',
31
+ EC: 'double',
32
+ EU: 'double',
33
+ OC: 'double',
34
+ MC: 'double',
35
+ MU: 'double',
36
+ CCSC: 'double',
37
+ CCSU: 'double',
38
+ YGC: 'int',
39
+ YGCT: 'double',
40
+ FGC: 'int',
41
+ FGCT: 'double',
42
+ GCT: 'double'
43
+ },
44
+ gccause: {
45
+ S0: 'double',
46
+ S1: 'double',
47
+ E: 'double',
48
+ O: 'double',
49
+ M: 'double',
50
+ CCS: 'double',
51
+ YGC: 'int',
52
+ YGCT: 'double',
53
+ FGC: 'int',
54
+ FGCT: 'double',
55
+ GCT: 'double',
56
+ LGCC: 'string',
57
+ GCC: 'string'
58
+ },
59
+ gcnew: {
60
+ S0C: 'double',
61
+ S1C: 'double',
62
+ S0U: 'double',
63
+ S1U: 'double',
64
+ TT: 'int',
65
+ MTT: 'double',
66
+ DSS: 'double',
67
+ EC: 'double',
68
+ EU: 'double',
69
+ YGC: 'int',
70
+ YGCT: 'double'
71
+ },
72
+ gcnewcapacity: {
73
+ NGCMN: 'double',
74
+ NGCMX: 'double',
75
+ NGC: 'double',
76
+ S0CMX: 'double',
77
+ S0C: 'double',
78
+ S1CMX: 'double',
79
+ S1C: 'double',
80
+ ECMX: 'double',
81
+ EC: 'double',
82
+ YGC: 'int',
83
+ FGC: 'int'
84
+ },
85
+ gcold: {
86
+ MC: 'double',
87
+ MU: 'double',
88
+ CCSC: 'double',
89
+ CCSU: 'double',
90
+ OC: 'double',
91
+ OU: 'double',
92
+ YGC: 'int',
93
+ FGC: 'int',
94
+ FGCT: 'double',
95
+ GCT: 'double'
96
+ },
97
+ gcoldcapacity: {
98
+ OGCMN: 'double',
99
+ OGCMX: 'double',
100
+ OGC: 'double',
101
+ OC: 'double',
102
+ YGC: 'int',
103
+ FGC: 'int',
104
+ FGCT: 'double',
105
+ GCT: 'double'
106
+ },
107
+ gcmetacapacity: {
108
+ MCMN: 'double',
109
+ MCMX: 'double',
110
+ MC: 'double',
111
+ CCSMN: 'double',
112
+ CCSMX: 'double',
113
+ CCSC: 'double',
114
+ YGC: 'int',
115
+ FGC: 'int',
116
+ FGCT: 'double',
117
+ GCT: 'double'
118
+ },
119
+ gcutil: {
120
+ S0: 'double',
121
+ S1: 'double',
122
+ E: 'double',
123
+ O: 'double',
124
+ M: 'double',
125
+ CCS: 'double',
126
+ YGC: 'int',
127
+ YGCT: 'double',
128
+ FGC: 'int',
129
+ FGCT: 'double',
130
+ GCT: 'double'
131
+ },
132
+ printcompilation: {
133
+ Compiled: 'int',
134
+ Size: 'int',
135
+ Type: 'int',
136
+ Method: 'string'
137
+ }
138
+ }
139
+
140
+ def self.transaction(config, &control)
141
+ # find jstat files and push to "task".
142
+ paths = config.param('paths', :array, default: ['/tmp']).map do |path|
143
+ next [] unless Dir.exists?(path)
144
+ Dir.entries(path).sort.select do |f|
145
+ f =~ /^.+\.log$/
146
+ end.map do |file|
147
+ File.expand_path(File.join(path, file))
148
+ end
149
+ end.flatten
150
+ # remove checked jstat files by other threads.
151
+ paths -= config.param('done', :array, default: [])
152
+ task = {'paths' => paths}
153
+
154
+ # generate schema by parsing a given options of jstat.
155
+ option = config.param('option', :string, default: 'gcutil')
156
+ option[0] = '' if option =~ /^\-/
157
+ unless JSTAT_COLUMNS.has_key?(option.to_sym)
158
+ raise "Wrong configuration: \"option: #{option}\". Specify a stat option of jstat correctly."
159
+ end
160
+
161
+ timestamp = config.param('timestamp', :bool, default: false)
162
+
163
+ i = timestamp ? 1 : 0
164
+ columns = JSTAT_COLUMNS[option.to_sym].each.with_index(i).map do |column, index|
165
+ stat, type = column
166
+ case type
167
+ when 'string'
168
+ Column.new(index, stat.to_s, :string)
169
+ when 'int', 'long'
170
+ Column.new(index, stat.to_s, :long)
171
+ when 'double', 'float'
172
+ Column.new(index, stat.to_s, :double)
173
+ end
174
+ end
175
+
176
+ if timestamp
177
+ columns.unshift(Column.new(0, 'Timestamp', :double))
178
+ end
179
+
180
+ #TODO: Now, force to set threads as amount of found files. Need a better idea.
181
+ report = yield(task, columns, paths.length)
182
+
183
+ config.merge( report['done'].flatten.compact )
184
+
185
+ return {}
186
+ end
187
+
188
+ def initialize(task, schema, index, page_builder)
189
+ super
190
+ end
191
+
192
+ def run
193
+ # if no path, returns empty.
194
+ unless path = @task['paths'][@index]
195
+ return { 'done' => [] }
196
+ end
197
+
198
+ File.read(path).each_line.with_index(0) do |line, i|
199
+ stats = line.strip.split(/\s+/)
200
+
201
+ # maybe not jstat file if a number of column is not match.
202
+ if stats.size != @schema.size
203
+ # if not header, maybe injected other log, e.g. console.
204
+ i == 0 ? break : next
205
+ end
206
+
207
+ # ignore column heading line
208
+ next if i == 0 && stats[0] == @schema[0]['name']
209
+
210
+ page = []
211
+ @schema.each_with_index do |s, i|
212
+ case s['type']
213
+ when :string
214
+ page << stats[i]
215
+ # TODO: If not numeric, raise error.
216
+ when :long
217
+ page << stats[i].to_i
218
+ when :double
219
+ page << stats[i].to_f
220
+ else
221
+ raise "unknown type: #{s['type']}"
222
+ end
223
+ end
224
+ @page_builder.add(page)
225
+ end
226
+ @page_builder.finish
227
+
228
+ { # commit report
229
+ 'done' => path
230
+ }
231
+ end
232
+ end
233
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-input-jstat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - KUBOTA Yuji
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Embulk input plugin for Java Virtual Machine statistics by jstat command.
42
+ email:
43
+ - kubota.yuji@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - embulk-input-jstat.gemspec
54
+ - lib/embulk/input/jstat.rb
55
+ homepage: https://github.com/ykubota/embulk-input-jstat
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.1.11
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Embulk plugin for jstat input.
79
+ test_files: []