Ambiguity in README.md
yerden opened this issue · 3 comments
I have a question regarding this part of README.md:
m := &funcMetrics{}
m.calls.count = 1
m.calls.time = callTime
// Equivalent to:
//
// stats.Incr("func.calls.count")
// stats.Observe("func.calls.time", callTime)
//
stats.Report(m)
As stated here, setting counter to 1 in the struct is equivalent to calling stats.Incr()
. Does it mean that counters in structs should always be deltas from previous values? Perhaps that should be stated explicitly. If so, how can I provide new measure as an absolute value?
There is currently no way to provide absolute values for counters, the program would have to keep track of the last value it reported and compute the delta before submitting the next value.
This design decision results from the statsd/dogstatsd model that this package was initially designed around.
If you have a generic solution for a counter that would automatically manage the delta feel free to open a pull request, I'll be happy to review and merge your contribution!
Thanks for the answer. I guess managing absolute values would require new FieldType
, like AbsCounter
or so in order to maintain backward compatibility.
You could also use a Gauge as a pseudo-counter. I think that would probably be the best option given that no metrics implementations (that I know of) have the concept of an absolute counter.