Class: Pimon::StatsCollector
- Inherits:
-
Object
- Object
- Pimon::StatsCollector
- 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
-
#config ⇒ Object
Returns the value of attribute config.
-
#last_update ⇒ Object
Returns the value of attribute last_update.
-
#probe_threads ⇒ Object
Returns the value of attribute probe_threads.
-
#probes ⇒ Object
Returns the value of attribute probes.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #charts ⇒ Object
- #collect_stats ⇒ Object
-
#initialize(config) ⇒ StatsCollector
constructor
A new instance of StatsCollector.
- #show_stats ⇒ Object
- #single_stats ⇒ Object
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
#config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/pimon/stats_collector.rb', line 8 def config @config end |
#last_update ⇒ Object
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_threads ⇒ Object
Returns the value of attribute probe_threads.
11 12 13 |
# File 'lib/pimon/stats_collector.rb', line 11 def probe_threads @probe_threads end |
#probes ⇒ Object
Returns the value of attribute probes.
10 11 12 |
# File 'lib/pimon/stats_collector.rb', line 10 def probes @probes end |
#stats ⇒ Object (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
#charts ⇒ Object
58 59 60 |
# File 'lib/pimon/stats_collector.rb', line 58 def charts wait_for_stats_collection { stats[:charts].keys } end |
#collect_stats ⇒ Object
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_stats ⇒ Object
54 55 56 |
# File 'lib/pimon/stats_collector.rb', line 54 def show_stats wait_for_stats_collection { stats } end |
#single_stats ⇒ Object
62 63 64 |
# File 'lib/pimon/stats_collector.rb', line 62 def single_stats wait_for_stats_collection { stats[:single].keys } end |