Class: KPM::System
- Inherits:
-
Object
- Object
- KPM::System
- Defined in:
- lib/kpm/system.rb
Constant Summary collapse
- MAX_VALUE_COLUMN_WIDTH =
60
- DEFAULT_BUNDLE_DIR =
Dir['/var' + File::SEPARATOR + 'lib' + File::SEPARATOR + 'killbill' + File::SEPARATOR + 'bundles'][0] || Dir['/var' + File::SEPARATOR + 'tmp' + File::SEPARATOR + 'bundles'][0]
- DEFAULT_KAUI_SEARCH_BASE_DIR =
'**' + File::SEPARATOR + 'kaui'
- DEFAULT_KILLBILL_SEARCH_BASE_DIR =
'**' + File::SEPARATOR + 'ROOT'
Instance Method Summary collapse
- #get_apache_tomcat_pid ⇒ Object
- #get_command ⇒ Object
- #get_kaui_standalone_version(kaui_web_path = nil) ⇒ Object
- #get_kaui_version(kaui_web_path = nil) ⇒ Object
- #get_kaui_web_path ⇒ Object
- #get_killbill_version(killbill_web_path = nil) ⇒ Object
- #get_killbill_web_path ⇒ Object
- #get_plugin_path ⇒ Object
- #information(bundles_dir = nil, output_as_json = false, config_file = nil, kaui_web_path = nil, killbill_web_path = nil) ⇒ Object
-
#initialize ⇒ System
constructor
A new instance of System.
- #set_config(config_file = nil) ⇒ Object
- #show_cpu_information(output_as_json) ⇒ Object
- #show_disk_space_information(output_as_json) ⇒ Object
- #show_entropy_available(output_as_json) ⇒ Object
- #show_environment_information(java_version, output_as_json) ⇒ Object
- #show_java_system_information(command, output_as_json) ⇒ Object
- #show_killbill_information(kaui_web_path, killbill_web_path, output_as_json) ⇒ Object
- #show_memory_information(output_as_json) ⇒ Object
- #show_os_information(output_as_json) ⇒ Object
- #show_plugin_information(bundles_dir, output_as_json) ⇒ Object
Constructor Details
Instance Method Details
#get_apache_tomcat_pid ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/kpm/system.rb', line 301 def get_apache_tomcat_pid apache_tomcat_pid = nil; `jcmd -l 2>&1`.split("\n").each do |line| if /org.apache.catalina/.match(line) words = line.split(' ') apache_tomcat_pid = words[0] end end return apache_tomcat_pid unless apache_tomcat_pid.nil? jcmd = ( ENV['JAVA_HOME'] || '/**' ) + File::Separator + 'bin' + File::Separator + 'jcmd' jcmd = Dir[jcmd][0] return nil if jcmd.nil? apache_tomcat_pid = `#{jcmd} | awk '/org.apache.catalina/' | cut -d ' ' -f 1`.gsub("\n",'') return nil if apache_tomcat_pid.nil? || apache_tomcat_pid.empty? apache_tomcat_pid end |
#get_command ⇒ Object
290 291 292 293 294 295 296 297 298 299 |
# File 'lib/kpm/system.rb', line 290 def get_command command = 'java -XshowSettings:properties -version 2>&1' apache_tomcat_pid = get_apache_tomcat_pid if not apache_tomcat_pid.nil? command = "jcmd #{apache_tomcat_pid} VM.system_properties" end command end |
#get_kaui_standalone_version(kaui_web_path = nil) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/kpm/system.rb', line 222 def get_kaui_standalone_version(kaui_web_path = nil) kaui_search_default_dir = kaui_web_path.nil? ? DEFAULT_KAUI_SEARCH_BASE_DIR : Dir[kaui_web_path][0] return nil if kaui_search_default_dir.nil? kaui_search_default_dir.gsub!('.war','') version = nil yaml_file = kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'version.yml' unless Dir[yaml_file][0].nil? yml_data = YAML::load_file(Dir[yaml_file][0]) version = yml_data['version'] end version end |
#get_kaui_version(kaui_web_path = nil) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/kpm/system.rb', line 238 def get_kaui_version(kaui_web_path = nil) kaui_search_default_dir = kaui_web_path.nil? ? DEFAULT_KAUI_SEARCH_BASE_DIR : Dir[kaui_web_path][0] return nil if kaui_search_default_dir.nil? kaui_search_default_dir.gsub!('.war','') version = nil gemfile = Dir[kaui_search_default_dir + File::SEPARATOR + 'WEB-INF' + File::SEPARATOR + 'Gemfile'] unless gemfile[0].nil? absolute_gemfile_path = File.absolute_path(gemfile[0]) version = open(absolute_gemfile_path) do |f| f.each_line.detect do |line| if /kaui/.match(line) version = /(\d+)\.(\d+)\.(\d+)/.match(line) break unless version.nil? end end version end end version end |
#get_kaui_web_path ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/kpm/system.rb', line 335 def get_kaui_web_path kaui_web_path = nil; if not @config.nil? config_kaui = @config['kaui'] if not config_kaui.nil? kaui_web_path = Dir[config_kaui['webapp_path']][0] end end kaui_web_path end |
#get_killbill_version(killbill_web_path = nil) ⇒ Object
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/kpm/system.rb', line 265 def get_killbill_version(killbill_web_path = nil) killbill_search_default_dir = killbill_web_path.nil? ? DEFAULT_KILLBILL_SEARCH_BASE_DIR : Dir[killbill_web_path][0] return nil if killbill_search_default_dir.nil? killbill_search_default_dir.gsub!('.war','') killbill_search_default_dir.gsub!('webapps','**') file = Dir[killbill_search_default_dir + File::SEPARATOR + 'META-INF' + File::SEPARATOR + '**' + File::SEPARATOR + 'pom.properties'] version = nil unless file[0].nil? absolute_file_path = File.absolute_path(file[0]) version = open(absolute_file_path) do |f| f.each_line.detect do |line| version = /(\d+)\.(\d+)\.(\d+)/.match(line) break unless version.nil? end version end end version end |
#get_killbill_web_path ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/kpm/system.rb', line 349 def get_killbill_web_path killbill_web_path = nil; if not @config.nil? config_killbill = @config['killbill'] if not config_killbill.nil? killbill_web_path = Dir[config_killbill['webapp_path']][0] end end killbill_web_path end |
#get_plugin_path ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/kpm/system.rb', line 363 def get_plugin_path plugin_path = nil; if not @config.nil? config_killbill = @config['killbill'] if not config_killbill.nil? plugin_path = Dir[config_killbill['plugins_dir']][0] end end plugin_path end |
#information(bundles_dir = nil, output_as_json = false, config_file = nil, kaui_web_path = nil, killbill_web_path = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kpm/system.rb', line 16 def information(bundles_dir = nil, output_as_json = false, config_file = nil, kaui_web_path = nil, killbill_web_path = nil) set_config(config_file) killbill_information = show_killbill_information(kaui_web_path,killbill_web_path,output_as_json) java_version = `java -version 2>&1`.split("\n")[0].split('"')[1] environment_information = show_environment_information(java_version, output_as_json) os_information = show_os_information(output_as_json) cpu_information = show_cpu_information(output_as_json) memory_information = show_memory_information(output_as_json) disk_space_information = show_disk_space_information(output_as_json) entropy_available = show_entropy_available(output_as_json) if not java_version.nil? command = get_command java_system_information = show_java_system_information(command,output_as_json) end plugin_information = show_plugin_information(get_plugin_path || bundles_dir || DEFAULT_BUNDLE_DIR, output_as_json) json_data = Hash.new json_data[:killbill_information] = killbill_information json_data[:environment_information] = environment_information json_data[:os_information] = os_information json_data[:cpu_information] = cpu_information json_data[:memory_information] = memory_information json_data[:disk_space_information] = disk_space_information json_data[:entropy_available] = entropy_available json_data[:java_system_information] = java_system_information json_data[:plugin_information] = plugin_information json_data.to_json end |
#set_config(config_file = nil) ⇒ Object
324 325 326 327 328 329 330 331 332 333 |
# File 'lib/kpm/system.rb', line 324 def set_config(config_file = nil) @config = nil if not config_file.nil? if not Dir[config_file][0].nil? @config = YAML::load_file(config_file) end end end |
#show_cpu_information(output_as_json) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/kpm/system.rb', line 87 def show_cpu_information(output_as_json) cpu_info = KPM::SystemProxy::CpuInformation.fetch labels = KPM::SystemProxy::CpuInformation.get_labels unless output_as_json @formatter.format(cpu_info,labels) end cpu_info end |
#show_disk_space_information(output_as_json) ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/kpm/system.rb', line 109 def show_disk_space_information(output_as_json) disk_space_info = KPM::SystemProxy::DiskSpaceInformation.fetch labels = KPM::SystemProxy::DiskSpaceInformation.get_labels unless output_as_json @formatter.format(disk_space_info,labels) end disk_space_info end |
#show_entropy_available(output_as_json) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/kpm/system.rb', line 120 def show_entropy_available(output_as_json) entropy_available = KPM::SystemProxy::EntropyAvailable.fetch labels = KPM::SystemProxy::EntropyAvailable.get_labels unless output_as_json @formatter.format(entropy_available,labels) end entropy_available end |
#show_environment_information(java_version, output_as_json) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kpm/system.rb', line 72 def show_environment_information(java_version, output_as_json) environment = Hash[:ruby => {:environment=>'Ruby',:version => RUBY_VERSION}, :java => {:environment=>'Java',:version => java_version.nil? ? 'no version found' : java_version}] labels = [{:label => :environment}, {:label => :version}] if not output_as_json @formatter.format(environment,labels) end environment end |
#show_java_system_information(command, output_as_json) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/kpm/system.rb', line 142 def show_java_system_information(command, output_as_json) java_system = Hash.new property_count = 0; last_key = '' `#{command}`.split("\n").each do |prop| if prop.to_s.strip.empty? break; end if property_count > 0 props = prop.split('=') if (not props[1].nil? && props[1].to_s.strip.size > MAX_VALUE_COLUMN_WIDTH) && output_as_json == false chunks = ".{1,#{MAX_VALUE_COLUMN_WIDTH}}" props[1].to_s.scan(/#{chunks}/).each_with_index do |p, index| java_system[property_count] = {:java_property => index.equal?(0) ? props[0] : '', :value => p} property_count += 1 end elsif output_as_json key = (props[1].nil? ? last_key : props[0]).to_s.strip value = props[1].nil? ? props[0] : props[1] if java_system.has_key?(key) java_system[key][:value] = java_system[key][:value].to_s.concat(' ').concat(value) else java_system[key] = {:java_property => key, :value => value} end else java_system[property_count] = {:java_property => props[1].nil? ? '' : props[0], :value => props[1].nil? ? props[0] : props[1]} end last_key = props[1].nil? ? last_key : props[0] end property_count += 1 end labels = [{:label => :java_property}, {:label => :value}] if not output_as_json @formatter.format(java_system,labels) end java_system end |
#show_killbill_information(kaui_web_path, killbill_web_path, output_as_json) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kpm/system.rb', line 50 def show_killbill_information(kaui_web_path, killbill_web_path, output_as_json) kpm_version = KPM::VERSION kaui_version = get_kaui_version(get_kaui_web_path || kaui_web_path) killbill_version = get_killbill_version(get_killbill_web_path || killbill_web_path) kaui_standalone_version = get_kaui_standalone_version(get_kaui_web_path || kaui_web_path) environment = Hash[:kpm => {:system=>'KPM',:version => kpm_version}, :kaui => {:system=>'Kaui',:version => kaui_version.nil? ? 'not found' : kaui_version}, :kaui_standalone => {:system=>'Kaui standalone',:version => kaui_standalone_version.nil? ? 'not found' : kaui_standalone_version}, :killbill => {:system=>'Killbill',:version => killbill_version.nil? ? 'not found' : killbill_version}] labels = [{:label => :system}, {:label => :version}] if not output_as_json @formatter.format(environment,labels) end environment end |
#show_memory_information(output_as_json) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/kpm/system.rb', line 98 def show_memory_information(output_as_json) memory_info = KPM::SystemProxy::MemoryInformation.fetch labels = KPM::SystemProxy::MemoryInformation.get_labels unless output_as_json @formatter.format(memory_info,labels) end memory_info end |
#show_os_information(output_as_json) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/kpm/system.rb', line 131 def show_os_information(output_as_json) os_information = KPM::SystemProxy::OsInformation.fetch labels = KPM::SystemProxy::OsInformation.get_labels unless output_as_json @formatter.format(os_information,labels) end os_information end |
#show_plugin_information(bundles_dir, output_as_json) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/kpm/system.rb', line 199 def show_plugin_information(bundles_dir, output_as_json) if bundles_dir.nil? all_plugins = nil else inspector = KPM::Inspector.new all_plugins = inspector.inspect(bundles_dir) end unless output_as_json if all_plugins.nil? || all_plugins.size == 0 puts "\e[91;1mNo KB plugin information available\e[0m\n\n" else @formatter.format(all_plugins) end end if output_as_json && (all_plugins.nil? || all_plugins.size == 0) all_plugins = 'No KB plugin information available' end all_plugins end |