Class: StatsCollector
- Inherits:
-
Object
- Object
- StatsCollector
- Defined in:
- lib/pimon/stats_collector.rb
Instance Method Summary collapse
- #collect_stats ⇒ Object
-
#initialize(config) ⇒ StatsCollector
constructor
A new instance of StatsCollector.
- #last_update ⇒ Object
- #show_stats ⇒ Object
Constructor Details
#initialize(config) ⇒ StatsCollector
Returns a new instance of StatsCollector.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pimon/stats_collector.rb', line 13 def initialize(config) @config = config @probes = [ Probe::TimeCheck, Probe::CpuUsage, Probe::MemoryUsage, Probe::SwapUsage, Probe::DiskUsage, Probe::Temperature, Probe::Uptime ] @stats = Stats.new(@probes.map(&:symbol).concat([:time])) end |
Instance Method Details
#collect_stats ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pimon/stats_collector.rb', line 27 def collect_stats pop_old_stats @probes.each do |probe| @stats.push(probe.symbol, probe.check) end end |
#last_update ⇒ Object
35 36 37 38 39 |
# File 'lib/pimon/stats_collector.rb', line 35 def last_update time = @stats.index(:time, @config.stats[:number_of_stats] - 1) DateTime.parse(time) if time end |
#show_stats ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pimon/stats_collector.rb', line 41 def show_stats time = @stats.range(:time) uptime = @stats.range(:uptime) stats = { :time => { :stats => time.map { |t| (/\d\d:\d\d:\d\d/.match(t))[0] } }, :hostname => @config.hostname, :uptime => uptime } @probes.each do |probe| stats[probe.symbol] = { :stats => @stats.range(probe.symbol), :color => @config.chart[probe.symbol][:color], :unit => probe.unit } unless [:time, :uptime].include?(probe.symbol) end stats.to_json end |