Module: Zenoss::Model::RRDView

Includes:
Zenoss::Model
Included in:
Device
Defined in:
lib/zenoss/model/rrd_view.rb

Instance Method Summary collapse

Methods included from Zenoss::Model

#model_init

Methods included from Zenoss

connect, #parse_array, #pdatetime_to_datetime, #pdict_to_hash, #plist_to_array, #ptuples_to_hash, #sanitize_str

Instance Method Details

#fetch_rrd_value(dpname, vstart, vend = DateTime.now, cf = 'AVERAGE', resolution = 300) ⇒ Object

Get all of the data point falues between a certain time period

Examples:

An example of the actuall HTTP call

http://myhost:8080/zport/dmd/Devices/path/callZenossMethod?methodName=fetchRRDValue&args=[my_dpoint===AVERAGE===300===1300761000===1300776100]

Parameters:

  • dpname (String)

    the name of the data point to retrieve values for

  • cf (String) (defaults to: 'AVERAGE')

    the RRD consolidation function to use AVERAGE,MIN,MAX,LAST

  • resolution (Fixnum) (defaults to: 300)

    the RRD resolution to use. This is the interval between values. It defaults to 300 seconds (5 minutes).

  • start (DateTime)

    the time to begin fetching values from

  • end (DataTime)

    the time to stop fetching values at. It defaults to now.



51
52
53
54
55
56
57
58
# File 'lib/zenoss/model/rrd_view.rb', line 51

def fetch_rrd_value(dpname,vstart,vend=DateTime.now,cf='AVERAGE',resolution=300)
  method =  "fetchRRDValue?dpname=#{dpname}"
  method << "&cf=#{cf}&resolution=#{resolution}"
  method << "&start=#{vstart.strftime('%s')}"
  method << "&end=#{vend.strftime('%s')}"
  custom_rest(method)
  parse_rrd_fetch(custom_rest(method))
end

#get_rrd_data_pointsArray

Returns of datapoints.

Returns:

  • (Array)

    of datapoints



26
27
28
29
30
31
# File 'lib/zenoss/model/rrd_view.rb', line 26

def get_rrd_data_points
  (plist_to_array( custom_rest('getRRDDataPoints').chomp )).map do |dstr|
    dp = dstr.sub(/^<([\w]+)\s+at\s+(.*)>$/,'\2')
    RRDDataPoint.new(@zenoss,dp)
  end
end

#get_rrd_values(dsnames) ⇒ Hash

Get key/value pairs of RRD Values for the passed data source names.

Parameters:

  • dsnames (Array <String>)

    data source names from RRDDataPoint#name

Returns:

  • (Hash)

    key/value pairs of data source name and data source values



37
38
39
# File 'lib/zenoss/model/rrd_view.rb', line 37

def get_rrd_values(dsnames)
  pdict_to_hash(custom_rest("getRRDValues?dsnames=[#{dsnames.join(',')}]"))
end

#parse_rrd_fetch(vstr) ⇒ Object

Parse the string returned by the REST call fetchRRDValue.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zenoss/model/rrd_view.rb', line 64

def parse_rrd_fetch(vstr)
  vstr = vstr.chomp
  vstr = vstr.slice 1, (vstr.length - 2)
  parts = vstr.match(/^\(([^\)]+)\),\s*\(([^\)]+)\),\s*\[([^\]]+)\]/)

  # Get the first part of the return, start, end, resolution
  retparms = Hash[[:start,:end,:resolution].zip( parts[1].split(/\s*,\s*/).map {|v| v.to_i} )]
  # Get the datasource name. This will almost always be 'ds0'
  retparms[:rrdds] = parts[2].gsub(/['"]/,'').split(/,/).first
  # Get the values
  retparms[:rrdvalues] = plist_to_array(parts[3]).map do |v|
    atom = v.gsub(/(\(|\))/,'').split(/\s*,\s*/)[0]
    case atom
    when /\d\.\d/
      atom.to_f
    when /^\d$/
      atom.to_i
    when /None/
      nil
    end
  end
  retparms
end