rboss 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in rboss.gemspec
4
3
  gemspec
5
4
 
6
- #gem 'pretty-monitor'
5
+ gem 'yummi'
data/bin/twiddle CHANGED
@@ -27,10 +27,11 @@ require 'optparse'
27
27
  require 'logger'
28
28
  require 'yaml'
29
29
  require 'fileutils'
30
+ require 'yummi'
30
31
 
31
32
  params = {}
32
- mbeans = {}
33
- commands = {}
33
+ @mbeans = {}
34
+ @commands = {}
34
35
  no_details = false
35
36
  @conf_dir = File.expand_path "~/.rboss"
36
37
  servers_file = "#{@conf_dir}/twiddle.yaml"
@@ -69,13 +70,16 @@ end
69
70
  opts.on('--save SERVER_NAME', "Saves the server configuration in #{servers_file}") do |server|
70
71
  save = server
71
72
  end
72
-
73
+ opts.on('--loop INTERVAL', Float, 'Runs the mbean inside a loop') do |interval|
74
+ @loop = true
75
+ @interval = interval
76
+ end
73
77
  opts.on('--all', "Detail all mapped mbeans") do
74
78
  defaults.each do |mbean_id, mbean|
75
79
  if mbean[:scan]
76
- mbeans[mbean_id] = :all
80
+ @mbeans[mbean_id] = :all
77
81
  elsif mbean[:properties]
78
- mbeans[mbean_id] = true
82
+ @mbeans[mbean_id] = true
79
83
  end
80
84
  end
81
85
  end
@@ -85,34 +89,34 @@ end
85
89
  if mbean[:scan]
86
90
  opts.on("--#{command} [name_a,name_b,...]", Array,
87
91
  "Detail \"#{mbean[:description]}\" based on the given names (no names for scan)") do |names|
88
- mbeans[mbean_id] = names || :all
92
+ @mbeans[mbean_id] = names || :all
89
93
  end
90
94
  elsif mbean[:properties]
91
95
  opts.on("--#{command}", "Detail \"#{mbean[:description]}\"") do
92
- mbeans[mbean_id] = true
96
+ @mbeans[mbean_id] = true
93
97
  end
94
98
  end
95
99
  end
96
100
 
97
101
  opts.on('--set mbean_id[:resource_name],property,value', Array,
98
102
  'Sets a value to a resource that the monitor knows') do |set|
99
- commands[:set] = set
103
+ @commands[:set] = set
100
104
  end
101
105
  opts.on('--get mbean_id[:resource_name],property', Array,
102
106
  'Gets a value to a resource that the monitor knows') do |get|
103
- commands[:get] = get
107
+ @commands[:get] = get
104
108
  end
105
109
  opts.on('--query mbean_id[:resource_name],[arguments]', Array,
106
110
  'Queries the mbean') do |query|
107
- commands[:query] = query
111
+ @commands[:query] = query
108
112
  end
109
113
  opts.on('--info mbean_id[:resource_name],[arguments]', Array,
110
114
  'List mbean info') do |info|
111
- commands[:info] = info
115
+ @commands[:info] = info
112
116
  end
113
117
  opts.on('--invoke mbean_id[:resource_name],method,[,args...]', Array,
114
118
  'Invokes a resoruce method') do |invoke|
115
- commands[:invoke] = invoke
119
+ @commands[:invoke] = invoke
116
120
  end
117
121
  opts.on("-l", "--list", "List the mbeans mappings") do
118
122
  (defaults.sort_by { |k, v| k }).each do |mbean_id, mbean|
@@ -127,6 +131,9 @@ end
127
131
  opts.on('--no-detail', 'Do not detail mbeans that needs a name') do
128
132
  no_details = true
129
133
  end
134
+ opts.on('--no-color', 'Do not colorize output') do
135
+ require 'yummi/no_colors'
136
+ end
130
137
  opts.on('-u', '--user USER', 'Defines the JMX User') do |user|
131
138
  params[:user] = user
132
139
  end
@@ -134,7 +141,7 @@ opts.on('-p', '--password PASSWORD', 'Defines the JMX Password') do |password|
134
141
  params[:password] = password
135
142
  end
136
143
  opts.on('-n COMMAND', '--native COMMAND', 'Executes the given command as is') do |command|
137
- commands[:native] = command
144
+ @commands[:native] = command
138
145
  end
139
146
  opts.on('-v', '--verbose', 'Shows the twiddle commands before execution') do
140
147
  params[:log_level] = Logger::DEBUG
@@ -174,13 +181,24 @@ def normalize args
174
181
  end
175
182
  end
176
183
 
177
- puts opts if mbeans.empty? and commands.empty?
184
+ puts opts if @mbeans.empty? and @commands.empty?
178
185
 
179
- actions = JBoss::CommandActions::Twiddle::new @twiddle,
186
+ @actions = JBoss::CommandActions::Twiddle::new @twiddle,
180
187
  :no_details => no_details,
181
188
  :mbeans => defaults
182
189
 
183
- actions.parse_and_execute commands
190
+ def execute_actions
191
+ buff = ""
192
+ buff << Yummi.colorize(Time.now.strftime("At %H:%M:%S%n"), :white) if @loop
193
+ buff << @actions.parse_and_execute(@commands)
194
+ buff << @actions.detail(@mbeans)
195
+ system "clear" if @loop
196
+ puts buff
197
+ end
184
198
 
185
- actions.detail mbeans
199
+ while @loop
200
+ execute_actions
201
+ sleep @interval
202
+ end
186
203
 
204
+ execute_actions
@@ -33,56 +33,58 @@ module JBoss
33
33
  end
34
34
 
35
35
  def parse_and_execute commands
36
+ buff = ""
36
37
  commands.each do |method, args|
37
- send method, *args
38
+ buff << send(method, *args)
38
39
  end
40
+ buff
39
41
  end
40
42
 
41
43
  def native command
42
- puts @twiddle.execute(command)
44
+ @twiddle.execute(command)
43
45
  end
44
46
 
45
47
  def set id, property, value
46
48
  mbean, name = extract id
47
- puts @twiddle.set :mbean => mbean.to_sym,
48
- :name => name,
49
- :property => property,
50
- :value => value
49
+ @twiddle.set :mbean => mbean.to_sym,
50
+ :name => name,
51
+ :property => property,
52
+ :value => value
51
53
  end
52
54
 
53
55
  def get id, property
54
56
  mbean, name = extract id
55
- puts @twiddle.get :mbean => mbean.to_sym,
56
- :name => name,
57
- :property => property
57
+ @twiddle.get :mbean => mbean.to_sym,
58
+ :name => name,
59
+ :property => property
58
60
  end
59
61
 
60
62
  def invoke id, method, *args
61
63
  mbean, name = extract id
62
- puts @twiddle.invoke :mbean => mbean.to_sym,
63
- :name => name,
64
- :method => method,
65
- :args => normalize(args)
64
+ @twiddle.invoke :mbean => mbean.to_sym,
65
+ :name => name,
66
+ :method => method,
67
+ :args => normalize(args)
66
68
  end
67
69
 
68
70
  def query id, *args
69
71
  mbean, name = extract id
70
- puts @twiddle.query :mbean => mbean.to_sym,
71
- :name => name,
72
- :args => normalize(args)
72
+ @twiddle.query :mbean => mbean.to_sym,
73
+ :name => name,
74
+ :args => normalize(args)
73
75
  end
74
76
 
75
77
  def info id, *args
76
78
  mbean, name = extract id
77
- puts @twiddle.info :mbean => mbean.to_sym,
78
- :name => name,
79
- :args => normalize(args)
79
+ @twiddle.info :mbean => mbean.to_sym,
80
+ :name => name,
81
+ :args => normalize(args)
80
82
  end
81
83
 
82
84
  def detail mbeans
85
+ buff = ""
83
86
  mbeans.each do |mbean_id, resources|
84
- table = TableBuilder::new @opts[:mbeans][mbean_id]
85
- table.title = @opts[:mbeans][mbean_id][:description]
87
+ table_builder = TableBuilder::new @opts[:mbeans][mbean_id]
86
88
  rows = []
87
89
  if resources.is_a? TrueClass
88
90
  row = []
@@ -91,8 +93,9 @@ module JBoss
91
93
  end
92
94
  rows << row
93
95
  elsif @opts[:no_details]
96
+ table_builder.no_details
94
97
  @monitor.mbean(mbean_id).scan.each do |name|
95
- rows << name
98
+ rows << [name]
96
99
  end
97
100
  else
98
101
  @monitor.mbean(mbean_id).detail resources do |resource, detail|
@@ -103,9 +106,10 @@ module JBoss
103
106
  rows << row
104
107
  end
105
108
  end
106
- rows.each { |row| table.add :normal, *row }
107
- table.print
109
+ table_builder.data = rows
110
+ buff << table_builder.table.to_s
108
111
  end
112
+ buff
109
113
  end
110
114
 
111
115
  end
@@ -26,6 +26,7 @@ require_relative "component_processor"
26
26
  require_relative "jboss_path"
27
27
 
28
28
  require "logger"
29
+ require "yummi"
29
30
  require "ostruct"
30
31
  require "fileutils"
31
32
 
@@ -124,9 +125,7 @@ module JBoss
124
125
  unless @logger
125
126
  @logger = Logger::new STDOUT
126
127
  @logger.level = opts[:log_level] || Logger::INFO
127
- formatter = Logger::Formatter.new
128
-
129
- def formatter.call(severity, time, program_name, message)
128
+ formatter = Yummi::Formatter::LogFormatter.new do |severity, time, program_name, message|
130
129
  "#{severity} : #{message}\n"
131
130
  end
132
131
 
@@ -135,10 +134,10 @@ module JBoss
135
134
  @profile = @opts[:profile].to_s
136
135
  @base_profile = @opts[:base_profile].to_s
137
136
  @jboss = JBoss::Path::new @jboss_home,
138
- :profile => @profile,
139
- :type => @opts[:type],
140
- :version => @opts[:version],
141
- :logger => @logger
137
+ :profile => @profile,
138
+ :type => @opts[:type],
139
+ :version => @opts[:version],
140
+ :logger => @logger
142
141
  initialize_components
143
142
  end
144
143
 
@@ -20,155 +20,62 @@
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 'wirble'
23
+ require 'yummi'
24
24
 
25
25
  class TableBuilder
26
26
 
27
- attr_writer :title
28
-
29
27
  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}"
28
+ @params = params
29
+ @table = Yummi::Table::new
30
+ @table.title = params[:description]
31
+ @table.header = params[:header]
32
+ if params[:layout] == :vertical
33
+ @table.layout = :vertical
34
+ @table.default_align = :left
75
35
  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
36
+ if params[:health]
37
+ @table.row_colorizer HealthColorizer::new params[:health]
91
38
  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]
39
+ if params[:formatter]
40
+ params[:formatter].each do |column|
41
+ @table.format column do |value|
42
+ Yummi::Formatter::Unit.format :byte, value.to_i
99
43
  end
100
- else
101
- @data[i] = @formatter.call(@data[i])
102
44
  end
103
45
  end
104
46
  end
105
47
 
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
48
+ def no_details
49
+ @table.header = @params[:header][0]
122
50
  end
123
51
 
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
52
+ def data= data
53
+ @table.data = data
130
54
  end
131
55
 
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
56
+ def table
57
+ @table
140
58
  end
141
59
 
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
60
+ end
147
61
 
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
62
+ class HealthColorizer
161
63
 
162
- def colorize(type, value)
163
- Wirble::Colorize::colorize_string(value, @colors[type])
64
+ def initialize params
65
+ @max = params[:max]
66
+ @free = params[:free]
67
+ @using = params[:using]
164
68
  end
165
69
 
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
70
+ def call index, data
71
+ max = data[@max].to_f
72
+ free = @using ? max - data[@using].to_f : data[@free].to_f
73
+
74
+ percentage = free / max
75
+
76
+ return :red if percentage <= 0.15
77
+ return :brown if percentage <= 0.30
78
+ :green
172
79
  end
173
80
 
174
81
  end
@@ -33,12 +33,9 @@ module JBoss
33
33
  :description => 'Deployed webapps',
34
34
  :pattern => 'jboss.web:type=Manager,host=localhost,path=/#{resource}',
35
35
  :properties => %W(activeSessions maxActive distributable maxActiveSessions
36
- expiredSessions rejectedSessions),
37
- :header => [
38
- ['Context', 'Active', 'Max', 'Distributable', 'Max Active', 'Expired', 'Rejected'],
39
- ['', 'Sessions', 'Active', '',
40
- 'Sessions', 'Sessions', 'Sessions'],
41
- ],
36
+ expiredSessions rejectedSessions),
37
+ :header => ["Context", "Active\nSessions", "Max\nSessions", "Distributable",
38
+ "Max Active\nSession", "Expired\nSessions", "Rejected\nSessions"],
42
39
  :scan => proc do
43
40
  query "jboss.web:type=Manager,*" do |path|
44
41
  path.gsub! "jboss.web:type=Manager,path=/", ""
@@ -57,10 +54,8 @@ module JBoss
57
54
  :properties => %W(maxThreads currentThreadCount currentThreadsBusy),
58
55
  :header => ['Connector', 'Max Threads', 'Current Threads', 'Busy Threads'],
59
56
  :health => {
60
- :indexes => {
61
- :max => 1,
62
- :using => 2
63
- }
57
+ :max => :max_threads,
58
+ :using => :current_threads
64
59
  },
65
60
  :scan => proc do
66
61
  query "jboss.web:type=ThreadPool,*" do |path|
@@ -73,7 +68,6 @@ module JBoss
73
68
  :pattern => 'jboss.jca:service=CachedConnectionManager',
74
69
  :properties => %W(InUseConnections),
75
70
  :header => ['In Use Connections'],
76
- :print_as => :single_list
77
71
  },
78
72
  :main_deployer => {
79
73
  :description => 'Main Deployer',
@@ -84,45 +78,39 @@ module JBoss
84
78
  :pattern => 'jboss.web:type=Engine',
85
79
  :properties => %W(jvmRoute name defaultHost),
86
80
  :header => ['JVM Route', 'Name', 'Default Host'],
87
- :print_as => :single_list
88
81
  },
89
82
  :log4j => {
90
83
  :description => 'JBoss Log4J Service',
91
84
  :pattern => 'jboss.system:service=Logging,type=Log4jService',
92
85
  :properties => %W(DefaultJBossServerLogThreshold),
93
86
  :header => ['Default Server Log Threshold'],
94
- :print_as => :single_list
95
87
  },
96
88
  :server => {
97
89
  :description => 'JBoss Server specifications',
98
90
  :pattern => 'jboss.system:type=Server',
99
91
  :properties => %W(VersionName VersionNumber Version),
100
92
  :header => ['Version Name', 'Version Number', 'Version'],
101
- :print_as => :single_list
102
93
  },
103
94
  :server_info => {
104
95
  :description => 'JBoss Server runtime info',
105
96
  :pattern => 'jboss.system:type=ServerInfo',
106
97
  :properties => %W(ActiveThreadCount MaxMemory FreeMemory AvailableProcessors
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,
98
+ JavaVendor JavaVersion OSName OSArch),
99
+ :header => ["Active Threads", "Max Memory", "Free Memory",
100
+ "Processors", "Java Vendor", "Java Version", "OS Name", "OS Arch"],
101
+ :layout => :vertical,
102
+ :formatter => [:max_memory, :free_memory],
113
103
  :health => {
114
- :indexes => {
115
- :max => 1,
116
- :free => 2
117
- }
104
+ :max => :max_memory,
105
+ :free => :free_memory
118
106
  },
119
107
  },
120
108
  :server_config => {
121
109
  :description => 'JBoss Server configuration',
122
110
  :pattern => 'jboss.system:type=ServerConfig',
123
111
  :properties => %W(ServerName HomeDir ServerLogDir ServerHomeURL),
112
+ :layout => :vertical,
124
113
  :header => ['Server Name', 'Home Dir', 'Log Dir', 'Home URL'],
125
- :print_as => :single_list
126
114
  },
127
115
  :system_properties => {
128
116
  :description => 'System properties',
@@ -134,10 +122,8 @@ module JBoss
134
122
  :properties => %W(requestCount errorCount maxTime),
135
123
  :header => ['Connector', 'Requests', 'Errors', 'Max Time'],
136
124
  :health => {
137
- :indexes => {
138
- :max => 1,
139
- :using => 2
140
- }
125
+ :max => :request,
126
+ :using => :errors
141
127
  },
142
128
  :scan => proc do
143
129
  query "jboss.web:type=ThreadPool,*" do |path|
@@ -149,16 +135,12 @@ module JBoss
149
135
  :description => 'Datasource',
150
136
  :pattern => 'jboss.jca:service=ManagedConnectionPool,name=#{resource}',
151
137
  :properties => %W(MinSize MaxSize AvailableConnectionCount
152
- InUseConnectionCount ConnectionCount),
153
- :header => [
154
- ['JNDI Name', 'Min', 'Max', 'Connections', 'Connections', 'Connection'],
155
- ['', 'Size', 'Size', 'Avaliable', 'In Use', 'Count']
156
- ],
138
+ InUseConnectionCount ConnectionCount),
139
+ :header => ["JNDI Name", "Min\nSize", "Max\nSize", "Avaliable\nConnections",
140
+ "In Use\nConnections", "Connection\nCount"],
157
141
  :health => {
158
- :indexes => {
159
- :max => 2,
160
- :using => 4
161
- }
142
+ :max => :max_size,
143
+ :using => :in_use_connections
162
144
  },
163
145
  :scan => proc do
164
146
  query "jboss.jca:service=ManagedConnectionPool,*" do |path|
@@ -170,7 +152,7 @@ module JBoss
170
152
  :description => 'JMS Queue',
171
153
  :pattern => 'jboss.messaging.destination:service=Queue,name=#{resource}',
172
154
  :properties => %W(JNDIName MessageCount DeliveringCount
173
- ScheduledMessageCount MaxSize FullSize Clustered ConsumerCount),
155
+ ScheduledMessageCount MaxSize FullSize Clustered ConsumerCount),
174
156
  :header => ['Name', 'JNDI', 'Messages', 'Deliveries', 'Scheduleded', 'Max Size',
175
157
  'Full Size', 'Clustered', 'Consumed'],
176
158
  :scan => proc do
@@ -224,3 +206,4 @@ module JBoss
224
206
  end
225
207
 
226
208
  end
209
+
data/lib/rboss/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module RBoss
24
- VERSION = "0.5.1"
24
+ VERSION = "0.5.2"
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.5.1
4
+ version: 0.5.2
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-27 00:00:00.000000000Z
12
+ date: 2012-05-01 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."