jmx_client-parser 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.
- checksums.yaml +7 -0
- data/lib/jmx_client/parser/version.rb +5 -0
- data/lib/jmx_client/parser.rb +173 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a19428165fe743e2ded03fa6d12e5c8bdf7ea92
|
4
|
+
data.tar.gz: 530eeaf7d2f3a9b5bc7182898cf8f51fb3f7d02b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec3b410b561b507bb220dc70ec2c7cef56158a5ec4070543cca5c6f4f3f21b0373e8d55bcf4f94ae6bbb9032e4b92e4de893d504086f24ed7d77f0f57213e247
|
7
|
+
data.tar.gz: 0b45619028fa456b4cfe13c64f99375fbddd7e092f0c8ce0375f1fc9dc07ce515e44b8a67b2573caf4ecd0a4f005671656b6d3992b957977a2cfe86366953b80
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# Interface for parsing cmdline-jmxclient output into usable Ruby objects.
|
2
|
+
# Reads cmdline-jmxclient output and returns a Ruby hash.
|
3
|
+
#
|
4
|
+
# Result looks like:
|
5
|
+
# {
|
6
|
+
# 'ThreadCount' => '45',
|
7
|
+
# 'HeapMemoryUsage' => {
|
8
|
+
# 'committed' => '224...',
|
9
|
+
# 'init' => '167...',
|
10
|
+
# 'max' => '259...',
|
11
|
+
# 'used' => '145...'
|
12
|
+
# }
|
13
|
+
# }
|
14
|
+
#
|
15
|
+
module JmxClient
|
16
|
+
|
17
|
+
class Parser
|
18
|
+
|
19
|
+
MULTILINE_FIRST = %r(^
|
20
|
+
[0-9/]+\s+ # Matches calendar day, like 12/12/2013.
|
21
|
+
[0-9:]+\s+ # Matches timestamp, like 19:11:28.
|
22
|
+
[-+0-9]+\s+ # Matches timezone, like +0800 or -0700.
|
23
|
+
[a-zA-Z.]+\s+ # Matches Java Bean name, like org.archive.jmx.Client.
|
24
|
+
\w+:\s*\n # Matches Bean attribute, like ThreadCount:.
|
25
|
+
)x
|
26
|
+
MULTILINE_LAST = /^\s*$/
|
27
|
+
MULTILINE_DATA = /^[a-zA-Z]+?: .+$/
|
28
|
+
|
29
|
+
def self.parse(cmd_output)
|
30
|
+
self.new.parse(cmd_output)
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse(cmd_output)
|
34
|
+
parse_all_output(cmd_output)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def parse_all_output(cmd_output, formatted_output = {})
|
40
|
+
if cmd_output.nil? || cmd_output.empty?
|
41
|
+
return formatted_output
|
42
|
+
elsif single_line?(cmd_output)
|
43
|
+
remaining, formatted = parse_single_line(cmd_output)
|
44
|
+
return parse_all_output(remaining, formatted_output.merge(formatted))
|
45
|
+
elsif multiline?(cmd_output)
|
46
|
+
remaining, formatted = parse_multiple_lines(cmd_output)
|
47
|
+
return parse_all_output(remaining, formatted_output.merge(formatted))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def single_line?(output)
|
52
|
+
regex = %r(^
|
53
|
+
[0-9/]+\s+ # Matches calendar day, like 12/12/2013.
|
54
|
+
[0-9:]+\s+ # Matches timestamp, like 19:11:28.
|
55
|
+
[-+0-9]+\s+ # Matches timezone, like +0800 or -0700.
|
56
|
+
[a-zA-Z.]+\s+ # Matches Java Bean name, like org.archive.jmx.Client.
|
57
|
+
\w+:\s+ # Matches Bean attribute, like ThreadCount:.
|
58
|
+
[0-9a-zA-Z]+$ # Matches Bean attribute value.
|
59
|
+
)x
|
60
|
+
output.chomp.match(regex)
|
61
|
+
end
|
62
|
+
|
63
|
+
def multiline?(output)
|
64
|
+
output.match(MULTILINE_FIRST)
|
65
|
+
end
|
66
|
+
|
67
|
+
# cmd_output looks like:
|
68
|
+
# 12/12/2013 19:11:28 +0000 org.archive.jmx.Client ThreadCount: 45
|
69
|
+
#
|
70
|
+
# Output:
|
71
|
+
# [
|
72
|
+
# <cmd_output, less the first line>
|
73
|
+
# <Ruby hash representation of first line of cmd_output>
|
74
|
+
# ]
|
75
|
+
#
|
76
|
+
def parse_single_line(cmd_output)
|
77
|
+
_, _, _, bean, attribute, value = split_single_line(cmd_output)
|
78
|
+
[
|
79
|
+
drop_first_line(cmd_output),
|
80
|
+
{ attribute => value.chomp }
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
# cmd_output looks like:
|
85
|
+
# 12/12/2013 19:11:28 +0000 org.archive.jmx.Client ThreadCount: 45
|
86
|
+
#
|
87
|
+
def split_single_line(cmd_output)
|
88
|
+
date, time, timezone, bean, attribute, value = cmd_output.split(' ')
|
89
|
+
if value.nil?
|
90
|
+
[date, time, timezone, bean, attribute[0..-2]]
|
91
|
+
else
|
92
|
+
[date, time, timezone, bean, attribute[0..-2], value.chomp]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def drop_first_line(cmd_output)
|
97
|
+
cmd_output.split("\n").drop(1).join("\n")
|
98
|
+
end
|
99
|
+
|
100
|
+
def first_line?(output_line)
|
101
|
+
output_line.match(MULTILINE_FIRST)
|
102
|
+
end
|
103
|
+
|
104
|
+
def data_line?(output_line)
|
105
|
+
!output_line.match(MULTILINE_FIRST) && output_line.match(MULTILINE_DATA)
|
106
|
+
end
|
107
|
+
|
108
|
+
def last_line?(output_line)
|
109
|
+
output_line.match(MULTILINE_LAST)
|
110
|
+
end
|
111
|
+
|
112
|
+
# cmd_output looks like:
|
113
|
+
# 12/12/2013 19:11:19 +0000 org.archive.jmx.Client HeapMemoryUsage:
|
114
|
+
# committed: 22429696
|
115
|
+
# init: 16777216
|
116
|
+
# max: 259522560
|
117
|
+
# used: 14500760
|
118
|
+
#
|
119
|
+
# 12/12/2013 19:11:19 +0000 org.archive.jmx.Client NonHeapMemoryUsage:
|
120
|
+
# committed: 25886720
|
121
|
+
# init: 12746752
|
122
|
+
# max: 100663296
|
123
|
+
# used: 25679472
|
124
|
+
#
|
125
|
+
# Result is like:
|
126
|
+
# {
|
127
|
+
# 'HeapMemoryUsage' => {
|
128
|
+
# committed: '2242...',
|
129
|
+
# init: '167...',
|
130
|
+
# max: '259...',
|
131
|
+
# used: '145...'
|
132
|
+
# },
|
133
|
+
# 'NonHeapMemoryUsage' => {
|
134
|
+
# 'committed' => '258...',
|
135
|
+
# 'init' => '127...',
|
136
|
+
# 'max' => '100...',
|
137
|
+
# 'used: '256...'
|
138
|
+
# }
|
139
|
+
# }
|
140
|
+
#
|
141
|
+
# #parse_multiple_lines returns an array:
|
142
|
+
# [
|
143
|
+
# <unconsumed portion of cmd_output>,
|
144
|
+
# <formatted output from consumed portion of cmd_output>
|
145
|
+
# ]
|
146
|
+
#
|
147
|
+
def parse_multiple_lines(cmd_output)
|
148
|
+
report = {}
|
149
|
+
current_attribute = nil
|
150
|
+
|
151
|
+
cmd_output.each_line do |line|
|
152
|
+
case
|
153
|
+
when first_line?(line)
|
154
|
+
_, _, _, bean, attribute, _ = split_single_line(line)
|
155
|
+
report[attribute] = {}
|
156
|
+
current_attribute = attribute
|
157
|
+
when data_line?(line)
|
158
|
+
next if current_attribute.nil?
|
159
|
+
sub_attribute, value = line.split(' ')
|
160
|
+
sub_attribute = sub_attribute[0..-2] # Drop the trailing ':'
|
161
|
+
value = value.chomp
|
162
|
+
report[current_attribute][sub_attribute] = value
|
163
|
+
when last_line?(line)
|
164
|
+
current_attribute = nil
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
["", report]
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jmx_client-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Oman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: debugger
|
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
|
+
description: Utility to parse cmdline-jmxclient output into Ruby hash data.
|
56
|
+
email:
|
57
|
+
- aaron@unbounce.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/jmx_client/parser.rb
|
63
|
+
- lib/jmx_client/parser/version.rb
|
64
|
+
homepage: https://github.com/GrooveStomp/jmx_client-parser
|
65
|
+
licenses: []
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.0.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Utility to parse cmdline-jmxclient output into Ruby hash data.
|
87
|
+
test_files: []
|