Module: CollectdPlot::RRDRead

Defined in:
lib/collectd-plot/rrd_read.rb

Constant Summary collapse

RRDDIR =
'/var/lib/collectd/rrd/'

Class Method Summary collapse

Class Method Details

.get_data(props) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/collectd-plot/rrd_read.rb', line 19

def self.get_data(props)
   data = {}
   rrd_name = "#{RRDDIR}#{props.host}/load/load.rrd"      
   rrd = Errand.new(:filename => rrd_name)

puts rrd.fetch(:function => 'AVERAGE', :start => props.start, :finish => props.finish).inspect
   rrd_data = rrd.fetch(:function => 'AVERAGE', :start => props.start, :finish => props.finish)[:data]
   res = {}
   rrd_data.each_pair do |source, metric|
     metric.map! do |datapoint|
       case
       when datapoint && datapoint.nan?
         @tripped = true
         @last_valid
       when @tripped
         @last_valid
       else
         @last_valid = datapoint
       end
     end
     data[props.host] = metric
  end
  data
end

.list_hostsObject



7
8
9
# File 'lib/collectd-plot/rrd_read.rb', line 7

def self.list_hosts
  Dir.glob("#{RRDDIR}/*").map { |p| File.basename p }
end

.list_metrics_for(h) ⇒ Object



15
16
17
# File 'lib/collectd-plot/rrd_read.rb', line 15

def self.list_metrics_for(h)
  Dir.glob("#{RRDDIR}/#{h}/*").map { |m| File.basename m }
end

.regexp_hosts(glob) ⇒ Object



11
12
13
# File 'lib/collectd-plot/rrd_read.rb', line 11

def self.regexp_hosts(glob)
  Dir.glob("#{RRDDIR}/*").each { |d| puts d }
end