rcrowley / go-metrics

Go port of Coda Hale's Metrics library
Other
3.43k stars 493 forks source link

Adding FunctionalGauge #157

Closed pszymczyk closed 7 years ago

pszymczyk commented 8 years ago

Hi

I would like to add new type of Gauge. Main use case is passing function which returns different values over the time instead of explicit call gauge.Updata(newValue). It's standard use case in origin Java matrics:

registry.register(name(SessionStore.class, "cache-evictions"), new Gauge<Integer>() {
    @Override
    public Integer getValue() {
        return cache.getEvictionsCount();
    }
});

Now I have to implement FunctionalGauge in all my projects which are using go-metrics, e.g: https://github.com/allegro/marathon-consul/commit/e548d70f7a27be6476550b58e527b67cc9a36e41

Regards Paweł Szymczyk

janisz commented 8 years ago

:+1:

mihasya commented 7 years ago

Although I agree with most of @rcrowley's comments in #35 and am generally worried about what folks will do to themselves with this (burying mutex calls in metrics collection etc), it does appear there's significant sustained demand for this functionality. Merging. Thank you!