require 'ganymed/sampler/datasource' module Ganymed class Sampler ## # A Derive {DataSource data source} will store the derivative of the line # going from the last to the current value of the data source. Derive is # similar to a {Counter} {DataSource data source} in that it produces a # rate/s gauge, but only accepts absolute values and produces the # derivative instead of summation of all samples. # class Derive < DataSource def flush each do |ns, origin, ts| values = ts.each_cons(2).map do |a, b| (b[1].last - a[1].last)/(b[0] - a[0]) # ∆value / ∆ts end.reject do |value| value < 0 # ignore overflow/counter wrap end yield ns, origin, values end end end end end