Sha256: cf506647ff03b2c496198ba0280622f7625598b64fefd83db19a937a0acc38fc
Contents?: true
Size: 865 Bytes
Versions: 7
Compression:
Stored size: 865 Bytes
Contents
require 'ganymed/sampler/datasource' module Ganymed class Sampler ## # A Counter {DataSource} processes samples counting a specific event (such # as a webserver request, user login, etc) and produces a rate/s gauge. # class Counter < DataSource def flush(tick, &block) each(tick) do |ns, origin, events| values = events.sort_by do |event| # sort by timestamp event[0] end.group_by do |event| # group by timestamp event[0].to_i end.map do |_, events| # calculate counts for each second. events.reduce(0) do |memo, event| # sum(event.count) memo + event[1] end end yield ns, origin, values end end def feed(ns, origin, ts, value) add(ns, origin, [ts, value]) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems