Class: NewRelic::IA::DiskSampler
- Inherits:
-
Agent::Sampler
- Object
- Agent::Sampler
- NewRelic::IA::DiskSampler
- Includes:
- MetricNames
- Defined in:
- lib/new_relic/ia/disk_sampler.rb
Overview
This is some demo code which shows how you might install your own sampler. This one theoretically monitors cpu.
Constant Summary
Constants included from MetricNames
MetricNames::DISK, MetricNames::DISK_IO, MetricNames::MEMCACHED, MetricNames::SYSTEM_CPU, MetricNames::USER_CPU
Instance Method Summary collapse
- #disk_stats(filesystem) ⇒ Object
-
#initialize ⇒ DiskSampler
constructor
A new instance of DiskSampler.
-
#poll ⇒ Object
This gets called every 10 seconds, or once a minute depending on how you add the sampler to the stats engine.
Constructor Details
#initialize ⇒ DiskSampler
Returns a new instance of DiskSampler.
19 20 21 22 |
# File 'lib/new_relic/ia/disk_sampler.rb', line 19 def initialize super 'disk_sampler' @disk_stats = {} end |
Instance Method Details
#disk_stats(filesystem) ⇒ Object
24 25 26 27 |
# File 'lib/new_relic/ia/disk_sampler.rb', line 24 def disk_stats(filesystem) name = File.basename(filesystem) @disk_stats[name] ||= stats_engine.get_stats(DISK.gsub('_name_', name), false) end |
#poll ⇒ Object
This gets called every 10 seconds, or once a minute depending on how you add the sampler to the stats engine. It only looks at fs partitions beginning with ‘/’
32 33 34 35 36 37 38 39 40 |
# File 'lib/new_relic/ia/disk_sampler.rb', line 32 def poll stats = `df -k` stats.each_line do | line | if line =~ /^(\/[^\s]+)\s.*\s(\d+)%/ name = $1; alloc = $2 disk_stats(name).record_data_point alloc.to_i end end end |