oneops-admin/lib/shared/cookbooks/monitor/files/default/calc_perf_buckets.rb
# supports gauge and counter/derive dstypes
supports gauge and counter/derive dstypes
supports gauge and counter / derive dstypes
def append (sample,k,v,bucket)
  config = sample[:config]
  dstype = config["#{k}-dstype"]
  if dstype == "gauge" || dstype.nil?
    val = v.to_f
  else
    if !config.has_key?("#{k}-last_counter_value")
      sample[:next]["#{k}-last_counter_value"] = v
      return    
    end
    last_update = config["last_update"].to_i
    last_counter_value = config["#{k}-last_counter_value"].to_i
    delta_sec = sample[:time] - last_update
    delta_val = v.to_f - last_counter_value
    if delta_val < 0
      val = 0.0/0
    else
      val = delta_val / delta_sec
    end
    sample[:next]["#{k}-last_counter_value"] = v
  end
  bucket_file = "#{config[:dir]}/#{k}-#{bucket}"
  File.open(bucket_file, "a") do |f|
    if !val.nan?
      f.write sample[:time].to_s+":"+val.to_s+"\n"
    end
  end
end
def append ( sample , k , v , bucket ) config = sample [ :config ] dstype = config [ "#{k}-dstype" ] if dstype == "gauge" || dstype . nil? val = v . to_f else if ! config . has_key? ( "#{k}-last_counter_value" ) sample [ :next ] [ "#{k}-last_counter_value" ] = v return end last_update = config [ "last_update" ] . to_i last_counter_value = config [ "#{k}-last_counter_value" ] . to_i delta_sec = sample [ :time ] - last_update delta_val = v . to_f - last_counter_value if delta_val < 0 val = 0.0 / 0 else val = delta_val / delta_sec end sample [ :next ] [ "#{k}-last_counter_value" ] = v end bucket_file = "#{config[:dir]}/#{k}-#{bucket}" File . open ( bucket_file , "a" ) do | f | if ! val . nan? f . write sample [ :time ] . to_s + ":" + val . to_s + "\n" end end end
supports gauge and counter/derive dstypes
supports gauge and counter / derive dstypes
sample
k
v
bucket