Code Monkey home page Code Monkey logo

Comments (8)

rcrowley avatar rcrowley commented on July 3, 2024

Does embedding metrics.Gauge in your own type and metrics.Registering that struct serve your purposes? The main reason the various metrics are interface types is to allow this so we don't have to register callbacks and such.

from go-metrics.

usmanismail avatar usmanismail commented on July 3, 2024

Yes that would work.
However, in Java even the counter had a set operation and it could be implemented in go-metrics as well. At which point a gauge would not be very different from a standard counter. The pull mechanic is useful as it means the user of the library does not have to think about how often the value changes or how to setup a periodic update. Not that that is very difficult in go. As you suggest this can be done using embedding would be nice to have that hidden in go-metrics rather than application code.

from go-metrics.

rcrowley avatar rcrowley commented on July 3, 2024

I'm sorry but I still don't understand what a callback-based API would buy us.

I often embed a metrics.Gauge and override the Value() method to do something non-standard and register the embedding struct with metrics.Register. Then the pulling you describe is handled by the reporter that's iterating over the registry every once-in-a-while.

from go-metrics.

usmanismail avatar usmanismail commented on July 3, 2024

I am just proposing that, what you describe should be the standard way of using a gauge. And the counter metric be extended to give the functionality currently supported by gauges. However, this is just a minor gripe at this point as I can embed externally to go-metrics.

from go-metrics.

rcrowley avatar rcrowley commented on July 3, 2024

By your last comment it sounds like you're actually asking for an arbitrarily-valued version of metrics.Counter.Clear()?

I'm 100% not interested in a callback-based API for individual metrics and, as you agreed yourself, intervals are so easy in Go that there's barely a reason for the various emitters to even think about them.

from go-metrics.

jhiemer avatar jhiemer commented on July 3, 2024

@rcrowley I am quite new to Go. If I put all my Gauges into a map. How would I manage to retrieve new values for the map periodically?

from go-metrics.

mihasya avatar mihasya commented on July 3, 2024

@jhiemer were you able to resolve your question? If you have all your Gauges in a map, you can do something like this (may not actually compile, but should get you most of the way):

timer := time.NewTicker(5 * time.Second)
for {
    <- timer
    for label, gauge := range mapOfGauges {
        // do something with gauge
    }
}

Closing this issue, as it no longer appears to be an issue.

from go-metrics.

mihasya avatar mihasya commented on July 3, 2024

@jhiemer You can also look at the implementation of various reporters, see log.go for example.

from go-metrics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.