Class: NewRelic::IA::DiskSampler

Inherits:
Agent::Sampler
  • Object
show all
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

Constructor Details

#initializeDiskSampler

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

#pollObject

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