Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Librato Metrics' counters #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
module Metriksd
class LibratoMetricsReporter::TimesliceRollup

class Counter
attr_accessor :name, :source, :value
def initialize(name, source)
@name = name
@source = source
@value = 0.0
end

def increment(val)
@value += val
end

def to_hash
{
:name => name,
:source => source,
:value => value,
:type => 'counter'
}
end
end


class AverageGauge
attr_accessor :name, :source, :count, :sum, :sum_of_squares, :min, :max

Expand Down Expand Up @@ -69,6 +93,7 @@ def initialize(timeslice)
def process
return if @gauges
@gauges = {}
@counters = {}

@timeslice.flush.each do |data|
case data[:type]
Expand All @@ -89,7 +114,7 @@ def process
def to_hash
process

@gauges.map do |name, gauge|
@gauges.merge(@counters).map do |name, gauge|
[ gauge.name, gauge.to_hash.merge(:measure_time => @timeslice.time) ]
end
end
Expand Down Expand Up @@ -135,6 +160,12 @@ def average_gauge(name, source, value)
@gauges[key].mark(value)
end

def counter(name, source, increment)
key = [ name, source ].join('/')
@counters[key] ||= Counter.new(name, source)
@counters[key].increment(increment)
end

def sum_gauge(name, source, value)
key = [ name, source ].join('/')
@gauges[key] ||= SumGauge.new(name, source)
Expand Down