rboss 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in rboss.gemspec
4
4
  gemspec
5
+
6
+ gem 'wirble'
data/bin/jboss-profile CHANGED
File without changes
data/bin/twiddle CHANGED
@@ -58,7 +58,7 @@ end
58
58
  opts.on('--port PORT', 'Defines the JBoss jnp port') do |port|
59
59
  params[:port] = port
60
60
  end
61
- opts.on('-c', '--config SERVER_NAME',
61
+ opts.on('-c', '--connect SERVER_NAME',
62
62
  "Uses a configured server in #{servers_file}") do |server|
63
63
  config = load_yaml[server]
64
64
  abort "No configuration for #{server}" unless config
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require_relative '../table_builder'
24
+
23
25
  module JBoss
24
26
  module CommandActions
25
27
  class Twiddle
@@ -43,59 +45,66 @@ module JBoss
43
45
  def set id, property, value
44
46
  mbean, name = extract id
45
47
  puts @twiddle.set :mbean => mbean.to_sym,
46
- :name => name,
47
- :property => property,
48
- :value => value
48
+ :name => name,
49
+ :property => property,
50
+ :value => value
49
51
  end
50
52
 
51
53
  def get id, property
52
54
  mbean, name = extract id
53
55
  puts @twiddle.get :mbean => mbean.to_sym,
54
- :name => name,
55
- :property => property
56
+ :name => name,
57
+ :property => property
56
58
  end
57
59
 
58
60
  def invoke id, method, *args
59
61
  mbean, name = extract id
60
62
  puts @twiddle.invoke :mbean => mbean.to_sym,
61
- :name => name,
62
- :method => method,
63
- :args => normalize(args)
63
+ :name => name,
64
+ :method => method,
65
+ :args => normalize(args)
64
66
  end
65
67
 
66
68
  def query id, *args
67
69
  mbean, name = extract id
68
70
  puts @twiddle.query :mbean => mbean.to_sym,
69
- :name => name,
70
- :args => normalize(args)
71
+ :name => name,
72
+ :args => normalize(args)
71
73
  end
72
74
 
73
75
  def info id, *args
74
76
  mbean, name = extract id
75
77
  puts @twiddle.info :mbean => mbean.to_sym,
76
- :name => name,
77
- :args => normalize(args)
78
+ :name => name,
79
+ :args => normalize(args)
78
80
  end
79
81
 
80
82
  def detail mbeans
81
83
  mbeans.each do |mbean_id, resources|
82
- puts " - #{@opts[:mbeans][mbean_id][:description]}"
84
+ table = TableBuilder::new @opts[:mbeans][mbean_id]
85
+ table.title = @opts[:mbeans][mbean_id][:description]
86
+ rows = []
83
87
  if resources.is_a? TrueClass
88
+ row = []
84
89
  @monitor.mbean(mbean_id).detail do |name, value|
85
- puts " - #{name}=#{value}"
90
+ row << value
86
91
  end
92
+ rows << row
87
93
  elsif @opts[:no_details]
88
94
  @monitor.mbean(mbean_id).scan.each do |name|
89
95
  puts " - #{name}"
90
96
  end
91
97
  else
92
98
  @monitor.mbean(mbean_id).detail resources do |resource, detail|
93
- puts " - #{resource}"
99
+ row = [resource]
94
100
  detail.each do |name, value|
95
- puts " - #{name}=#{value}"
101
+ row << value
96
102
  end
103
+ rows << row
97
104
  end
98
105
  end
106
+ rows.each { |row| table.add :normal, *row }
107
+ table.print
99
108
  end
100
109
  end
101
110
 
@@ -104,4 +113,3 @@ module JBoss
104
113
  end
105
114
 
106
115
  end
107
-
@@ -0,0 +1,174 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'wirble'
24
+
25
+ class TableBuilder
26
+
27
+ attr_writer :title
28
+
29
+ def initialize params = {}
30
+ params[:colors] ||= {}
31
+ @colors = {
32
+ :title => :yellow,
33
+ :header => :light_blue,
34
+ :good => :green,
35
+ :bad => :red,
36
+ :warn => :brown,
37
+ :line => :purple,
38
+ :normal => nil
39
+ }.merge! params[:colors]
40
+ @health = params[:health]
41
+ @header = params[:header]
42
+ @formatter = params[:formatter]
43
+ @print_type = (params[:print_as] or :table)
44
+ @single_result = params[:single_result]
45
+
46
+ @data = []
47
+ @types = []
48
+ @title = nil
49
+ end
50
+
51
+ def add(type, *args)
52
+ @types << type
53
+ @data << args
54
+ end
55
+
56
+ def print
57
+ build_header @header
58
+ check_health
59
+ puts colorize(:title, @title)
60
+ print_as_table if @print_type == :table
61
+ print_as_single_list if @print_type == :single_list
62
+ end
63
+
64
+ def print_as_single_list
65
+ header = @data[0]
66
+ data ||= @data[1]
67
+ type = @types[1]
68
+ format_row(1, type)
69
+
70
+ line = colorize :line, '-'
71
+ data.each_index do |i|
72
+ description = colorize :header, header[i]
73
+ value = colorize type, data[i]
74
+ puts " #{line} #{description} = #{value}"
75
+ end
76
+ end
77
+
78
+ def print_as_table colspan = 2
79
+ @data.each_index do |i|
80
+ type = @types[i]
81
+ format_row(i, type)
82
+ @data[i].each_index do |j|
83
+ column = @data[i][j]
84
+ width = max_width j
85
+ value = column.to_s.ljust(width) if j == 0
86
+ value ||= column.to_s.rjust(width)
87
+ printf colorize(type, value)
88
+ printf(" " * colspan)
89
+ end
90
+ puts
91
+ end
92
+ end
93
+
94
+ def format_row(i, type)
95
+ if @formatter and type != :header
96
+ if @formatter.is_a? Hash
97
+ @formatter[:humanize].each do |index|
98
+ @data[i][index] = humanize @data[i][index]
99
+ end
100
+ else
101
+ @data[i] = @formatter.call(@data[i])
102
+ end
103
+ end
104
+ end
105
+
106
+ def check_health
107
+ return unless @health
108
+ @data.each_index do |i|
109
+ if @types[i] == :normal
110
+ row = @data[i]
111
+ if @health.is_a? Hash
112
+ indexes = @health[:indexes]
113
+ @health[:max] = row[indexes[:max]].to_f
114
+ @health[:using] = row[indexes[:using]].to_f if indexes[:using]
115
+ @health[:free] = row[indexes[:free]].to_f if indexes[:free]
116
+ @types[i] = health @health
117
+ else
118
+ @types[i] = @health.call(row)
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ def health params
125
+ warn_limit = (params[:warn_at] or 0.3)
126
+ bad_limit = (params[:alert_at] or 0.15)
127
+ return :bad if under_limit? bad_limit, params
128
+ return :warn if warn_limit and under_limit? warn_limit, params
129
+ :good
130
+ end
131
+
132
+ def under_limit? threshold, params
133
+ if params[:free]
134
+ free = (params[:free] / params[:max].to_f)
135
+ (free < threshold)
136
+ elsif params[:using]
137
+ free = params[:max] - params[:using]
138
+ under_limit? threshold, :free => free, :max => params[:max]
139
+ end
140
+ end
141
+
142
+ def humanize bytes
143
+ bytes = bytes.to_i
144
+ return (bytes / (1024 * 1024)).to_s << " MB" if bytes > (1024 * 1024)
145
+ (bytes / (1024)).to_s << " KB" if bytes > (1024)
146
+ end
147
+
148
+ def build_header header
149
+ return unless header
150
+ if header.is_a? Array
151
+ if header.first.is_a? Array
152
+ header.reverse.each do |value|
153
+ build_header value
154
+ end
155
+ else
156
+ @data = [header] + @data
157
+ @types = [:header] + @types
158
+ end
159
+ end
160
+ end
161
+
162
+ def colorize(type, value)
163
+ Wirble::Colorize::colorize_string(value, @colors[type])
164
+ end
165
+
166
+ def max_width column
167
+ max = 0
168
+ @data.each do |row|
169
+ max = [row[column].to_s.length, max].max
170
+ end
171
+ max
172
+ end
173
+
174
+ end
@@ -34,6 +34,11 @@ module JBoss
34
34
  :pattern => 'jboss.web:type=Manager,host=localhost,path=/#{resource}',
35
35
  :properties => %W(activeSessions maxActive distributable maxActiveSessions
36
36
  expiredSessions rejectedSessions),
37
+ :header => [
38
+ ['Context', 'Active', 'Max', 'Distributable', 'Max Active', 'Expired', 'Rejected'],
39
+ ['', 'Sessions', 'Active', '',
40
+ 'Sessions', 'Sessions', 'Sessions'],
41
+ ],
37
42
  :scan => proc do
38
43
  query "jboss.web:type=Manager,*" do |path|
39
44
  path.gsub! "jboss.web:type=Manager,path=/", ""
@@ -50,6 +55,13 @@ module JBoss
50
55
  :description => 'JBossWeb connector',
51
56
  :pattern => 'jboss.web:type=ThreadPool,name=#{resource}',
52
57
  :properties => %W(maxThreads currentThreadCount currentThreadsBusy),
58
+ :header => ['Connector', 'Max Threads', 'Current Threads', 'Busy Threads'],
59
+ :health => {
60
+ :indexes => {
61
+ :max => 1,
62
+ :using => 2
63
+ }
64
+ },
53
65
  :scan => proc do
54
66
  query "jboss.web:type=ThreadPool,*" do |path|
55
67
  path.gsub "jboss.web:type=ThreadPool,name=", ""
@@ -59,7 +71,9 @@ module JBoss
59
71
  :cached_connection_manager => {
60
72
  :description => 'JBoss JCA cached connections',
61
73
  :pattern => 'jboss.jca:service=CachedConnectionManager',
62
- :properties => %W(InUseConnections)
74
+ :properties => %W(InUseConnections),
75
+ :header => ['In Use Connections'],
76
+ :print_as => :single_list
63
77
  },
64
78
  :main_deployer => {
65
79
  :description => 'Main Deployer',
@@ -68,29 +82,47 @@ module JBoss
68
82
  :engine => {
69
83
  :description => 'JBossWeb engine',
70
84
  :pattern => 'jboss.web:type=Engine',
71
- :properties => %W(jvmRoute name defaultHost)
85
+ :properties => %W(jvmRoute name defaultHost),
86
+ :header => ['JVM Route', 'Name', 'Default Host'],
87
+ :print_as => :single_list
72
88
  },
73
89
  :log4j => {
74
90
  :description => 'JBoss Log4J Service',
75
91
  :pattern => 'jboss.system:service=Logging,type=Log4jService',
76
- :properties => %W(DefaultJBossServerLogThreshold)
92
+ :properties => %W(DefaultJBossServerLogThreshold),
93
+ :header => ['Default Server Log Threshold'],
94
+ :print_as => :single_list
77
95
  },
78
96
  :server => {
79
97
  :description => 'JBoss Server specifications',
80
98
  :pattern => 'jboss.system:type=Server',
81
- :properties => %W(VersionName VersionNumber Version)
99
+ :properties => %W(VersionName VersionNumber Version),
100
+ :header => ['Version Name', 'Version Number', 'Version'],
101
+ :print_as => :single_list
82
102
  },
83
103
  :server_info => {
84
104
  :description => 'JBoss Server runtime info',
85
105
  :pattern => 'jboss.system:type=ServerInfo',
86
106
  :properties => %W(ActiveThreadCount MaxMemory FreeMemory AvailableProcessors
87
- HostAddress JavaVendor JavaVersion JavaVMVersion
88
- JavaVMVendor JavaVMName OSName OSArch)
107
+ JavaVendor JavaVersion OSName OSArch),
108
+ :header => ['Active Threads', 'Max Memory', 'Free Memory',
109
+ 'Processors', 'Java Vendor',
110
+ 'Java Version', 'OS Name', 'OS Arch'],
111
+ :formatter => {:humanize => [1, 2]},
112
+ :print_as => :single_list,
113
+ :health => {
114
+ :indexes => {
115
+ :max => 1,
116
+ :free => 2
117
+ }
118
+ },
89
119
  },
90
120
  :server_config => {
91
121
  :description => 'JBoss Server configuration',
92
122
  :pattern => 'jboss.system:type=ServerConfig',
93
- :properties => %W(ServerName HomeDir ServerLogDir ServerHomeURL)
123
+ :properties => %W(ServerName HomeDir ServerLogDir ServerHomeURL),
124
+ :header => ['Server Name', 'Home Dir', 'Log Dir', 'Home URL'],
125
+ :print_as => :single_list
94
126
  },
95
127
  :system_properties => {
96
128
  :description => 'System properties',
@@ -100,6 +132,13 @@ module JBoss
100
132
  :description => 'JBossWeb connector requests',
101
133
  :pattern => 'jboss.web:type=GlobalRequestProcessor,name=#{resource}',
102
134
  :properties => %W(requestCount errorCount maxTime),
135
+ :header => ['Connector', 'Requests', 'Errors', 'Max Time'],
136
+ :health => {
137
+ :indexes => {
138
+ :max => 1,
139
+ :using => 2
140
+ }
141
+ },
103
142
  :scan => proc do
104
143
  query "jboss.web:type=ThreadPool,*" do |path|
105
144
  path.gsub "jboss.web:type=ThreadPool,name=", ""
@@ -111,6 +150,16 @@ module JBoss
111
150
  :pattern => 'jboss.jca:service=ManagedConnectionPool,name=#{resource}',
112
151
  :properties => %W(MinSize MaxSize AvailableConnectionCount
113
152
  InUseConnectionCount ConnectionCount),
153
+ :header => [
154
+ ['JNDI Name', 'Min', 'Max', 'Connections', 'Connections', 'Connection'],
155
+ ['', 'Size', 'Size', 'Avaliable', 'In Use', 'Count']
156
+ ],
157
+ :health => {
158
+ :indexes => {
159
+ :max => 2,
160
+ :using => 4
161
+ }
162
+ },
114
163
  :scan => proc do
115
164
  query "jboss.jca:service=ManagedConnectionPool,*" do |path|
116
165
  path.gsub "jboss.jca:service=ManagedConnectionPool,name=", ""
@@ -120,8 +169,10 @@ module JBoss
120
169
  :queue => {
121
170
  :description => 'JMS Queue',
122
171
  :pattern => 'jboss.messaging.destination:service=Queue,name=#{resource}',
123
- :properties => %W(Name JNDIName MessageCount DeliveringCount
172
+ :properties => %W(JNDIName MessageCount DeliveringCount
124
173
  ScheduledMessageCount MaxSize FullSize Clustered ConsumerCount),
174
+ :header => ['Name', 'JNDI', 'Messages', 'Deliveries', 'Scheduleded', 'Max Size',
175
+ 'Full Size', 'Clustered', 'Consumed'],
125
176
  :scan => proc do
126
177
  query "jboss.messaging.destination:service=Queue,*" do |path|
127
178
  path.gsub "jboss.messaging.destination:service=Queue,name=", ""
@@ -136,6 +187,7 @@ module JBoss
136
187
  :description => 'EJB',
137
188
  :pattern => 'jboss.j2ee:#{resource},service=EJB3',
138
189
  :properties => %W(CreateCount RemoveCount CurrentSize AvailableCount),
190
+ :header => ['EJB', 'Created', 'Removed', 'Current', 'Available'],
139
191
  :scan => proc do
140
192
  result = query "jboss.j2ee:*"
141
193
  (result.find_all do |path|
@@ -146,14 +198,12 @@ module JBoss
146
198
  end
147
199
  }
148
200
  }
149
- @@defaults
150
201
  end
151
202
 
152
203
  module_function :defaults
153
204
 
154
205
  def mbeans
155
206
  @mbeans ||= {}
156
- @mbeans
157
207
  end
158
208
 
159
209
  def monitor mbean_id, params
@@ -174,4 +224,3 @@ module JBoss
174
224
  end
175
225
 
176
226
  end
177
-
data/lib/rboss/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module RBoss
24
- VERSION = "0.4.1"
24
+ VERSION = "0.5.0"
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rboss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
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: 2012-03-21 00:00:00.000000000Z
12
+ date: 2012-03-22 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: ! "A tool to create profiles for JBoss Application Server and use\n twiddle
15
15
  to manage a running JBoss AS."
@@ -57,6 +57,7 @@ files:
57
57
  - lib/rboss/resources/mod_cluster.sar/META-INF/mod_cluster-jboss-beans.xml
58
58
  - lib/rboss/resources/mod_cluster.sar/mod_cluster-1.1.2.Final.jar
59
59
  - lib/rboss/resources/run.conf.erb
60
+ - lib/rboss/table_builder.rb
60
61
  - lib/rboss/twiddle.rb
61
62
  - lib/rboss/twiddle/base_monitor.rb
62
63
  - lib/rboss/twiddle/mbean.rb