Class: Pimon::StatsCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/pimon/stats_collector.rb

Constant Summary collapse

CHART_PROBES =
[
  Pimon::Probe::CpuUsage,
  Pimon::Probe::MemoryUsage,
  Pimon::Probe::SwapUsage,
  Pimon::Probe::DiskUsage,
  Pimon::Probe::Temperature
]
SINGLE_PROBES =
[
  Pimon::Probe::Uptime,
  Pimon::Probe::CpuFreq
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StatsCollector

Returns a new instance of StatsCollector.



27
28
29
30
31
32
33
34
35
36
# File 'lib/pimon/stats_collector.rb', line 27

def initialize(config)
  @config = config
  @probes = {
    charts: CHART_PROBES,
    single: SINGLE_PROBES
  }
  @stats = { colors: config.colors, charts: {}, single: {}, hostname: config.hostname }
  @probe_threads = []
  @collection_mutex = Mutex.new
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



8
9
10
# File 'lib/pimon/stats_collector.rb', line 8

def config
  @config
end

#last_updateObject

Returns the value of attribute last_update.



9
10
11
# File 'lib/pimon/stats_collector.rb', line 9

def last_update
  @last_update
end

#probe_threadsObject

Returns the value of attribute probe_threads.



11
12
13
# File 'lib/pimon/stats_collector.rb', line 11

def probe_threads
  @probe_threads
end

#probesObject

Returns the value of attribute probes.



10
11
12
# File 'lib/pimon/stats_collector.rb', line 10

def probes
  @probes
end

#statsObject (readonly)

Returns the value of attribute stats.



12
13
14
# File 'lib/pimon/stats_collector.rb', line 12

def stats
  @stats
end

Instance Method Details

#chartsObject



58
59
60
# File 'lib/pimon/stats_collector.rb', line 58

def charts
  wait_for_stats_collection { stats[:charts].keys }
end

#collect_statsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pimon/stats_collector.rb', line 38

def collect_stats
  @collection_mutex.synchronize do
    self.last_update = Time.now

    [:charts, :single].each do |stats_type|
      probes[stats_type].each do |probe|
        self.probe_threads = []
        probe_threads << Thread.new do
          sample = probe.check(last_update)
          stats[stats_type][sample.probe_name] = sample
        end
      end
    end
  end
end

#show_statsObject



54
55
56
# File 'lib/pimon/stats_collector.rb', line 54

def show_stats
  wait_for_stats_collection { stats }
end

#single_statsObject



62
63
64
# File 'lib/pimon/stats_collector.rb', line 62

def single_stats
  wait_for_stats_collection { stats[:single].keys }
end