Class: Dbwatcher::Services::SystemInfo::SystemInfoCollector

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/dbwatcher/services/system_info/system_info_collector.rb

Overview

Main system information collector service

Orchestrates the collection of system information from various sources including machine, database, and runtime information.

Examples:

info = SystemInfo::SystemInfoCollector.call
puts info[:machine][:hostname]
puts info[:database][:adapter]
puts info[:runtime][:ruby_version]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug_enabled?, #log_debug, #log_error, #log_info, #log_warn

Class Method Details

.callHash

Class method to create instance and call

Returns:

  • (Hash)

    system information



27
28
29
# File 'lib/dbwatcher/services/system_info/system_info_collector.rb', line 27

def self.call
  new.call
end

Instance Method Details

#callHash

Collect system information from all sources

This method needs to be longer to properly handle all the collection steps and error handling in a consistent way.

rubocop:disable Metrics/MethodLength

Returns:

  • (Hash)

    collected system information



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dbwatcher/services/system_info/system_info_collector.rb', line 38

def call
  start_time = current_time
  log_info "#{self.class.name}: Starting system information collection"

  info = {
    machine: collect_machine_info,
    database: collect_database_info,
    runtime: collect_runtime_info,
    collected_at: current_time.iso8601,
    collection_duration: nil
  }

  info[:collection_duration] = (current_time - start_time).round(3)
  log_info "#{self.class.name}: Completed system information collection in #{info[:collection_duration]}s"

  info
rescue StandardError => e
  log_error "System information collection failed: #{e.message}"
  {
    machine: {},
    database: {},
    runtime: {},
    collected_at: current_time.iso8601,
    collection_duration: nil,
    error: e.message
  }
end