Comments (8)
Does embedding metrics.Gauge
in your own type and metrics.Register
ing 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.
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.
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.
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.
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.
@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.
@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.
@jhiemer You can also look at the implementation of various reporters, see log.go for example.
from go-metrics.
Related Issues (20)
- Support for arbitrary times of now
- Feature request: Write metrics to a local file as csv format.
- Remove deprecation message.
- CaptureDebugGCStats panics HOT 1
- lock on global rand causes latency spike
- Improve documentation
- Use runtime.SetFinalizer on registration to avoid the need to Unregister meters or timers
- ExpDecaySample.Update - problem with rand.Float64() divider
- Locks missing on Registry's Each and GetAll functions => concurrent reads/writes in registry map
- Unregistering depleted exponential decay/EWMA counters
- [Question] Count by range of timer metrics?
- How to print metrics in console HOT 1
- Do we expect `StandardEWMA.Tick` to be called concurrently? HOT 2
- Difference with official Prometheus library github.com/prometheus/prometheus HOT 1
- OpenTelemetry exporter HOT 2
- Is this project still maintained? HOT 2
- msg := <-claim.Messages msg == nil
- Can this project be released under standard MIT license?
- PRs wanted?
- Memory leak while doing gracefull shutdown
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-metrics.