librato / librato-metrics

Ruby wrapper to make it easy to interact with Librato's API.
https://librato.com
Other
108 stars 51 forks source link

Incrementing Counters (similar to Librato Rails gem) #105

Closed harlow closed 9 years ago

harlow commented 9 years ago

Hello, the quick-start in librato-rails (https://github.com/librato/librato-rails#quick-start)

Shows an example of incrementing a counter:

# keep counts of key events
Librato.increment 'user.signup'

In README in this repo shows counters in this format:

Librato::Metrics.submit :my_metric => {:type => :counter, :value => 1002, :source => 'myapp'}

How does this translate? Would this be the equiv?

Librato::Metrics.submit 'user.signup' => { :type => :counter, :value => 1 }
nextmat commented 9 years ago

@harlow Our native counter type is actually only intended for a single use case, when you want to track the derivative (delta) of a monotonically increasing value. Here is some more info about that.

librato-rails actually reports everything as our native gauge type, with server-side aggregation enabled, using this strategy and a 60 second period.

So if you wanted to do something equivalent you would do something like:

Librato::Metrics.submit 'user.signup' => <number you want to increment by>

...and then ensure that server-side aggregation is turned on for the metric you are submitting to.

Note that librato-rack/rails do the work for you of aggregating things locally and then just reporting all cumulative measurements in a single request once per minute. If you are incrementing rapidly you may want to do something similar rather than sending a lot of requests.

This is how librato-rails incrementing counters actually work under the hood.

Let me know if you have further questions, hope this helps!

harlow commented 9 years ago

@nextmat thanks for the swift reply! Yes this makes sense :+1: