Add @Counted annotation similar to @Timed
See original GitHub issueSometimes the execution time is not that relevant, but the number of executions is.
It would be nice if there were a @Counted
annotation that could be used to count how often the annotated method has been called. I know this is currently already possible with a Counter
, but this is quite tendious, as I have to inject the MeterRegistry
create a Counter
for each method and store it in a field and increment it in the method.
Environment: Spring 5+ / Spring Boot 2+ / Spring Boot Actuator
My current thoughts:
- name: The name of the counter/metric
- mode(s) : COUNT_INVOKED/COUNT_RETURNED/COUNT_THROWED - Which modes to record (via tags).
Usecase
Easy way to check for sudden bursts in method calls (client connect) and easy way to check critical components (open DB connection) for liveliness.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Get the count per status in micrometer @Timed annotation
I am using @Timed annotation in SpringBoot application to monitor a method. I also want to know the count of response per status....
Read more >@Timed Annotation Using Metrics and AspectJ | Baeldung
We look at how to add lightweight timing instrumentation to an app using a combination of Metrics and AspectJ, making it as simple...
Read more >Spring Metrics
The Spectator Atlas Timer produces four time series, each with a different statistic tag: count - Rate of calls per second. totalTime -...
Read more >Removing cross-cutting concerns with Micrometer and Spring ...
After that, you can add a line of code wherever you like, and hey presto! ... In Micrometer the Counted Annotation Type is...
Read more >Micrometer Application Monitoring
Different meter types result in a different number of time series metrics. ... a @Timed annotation that frameworks can use to add timing...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ST-DDT See the recently merged https://github.com/micrometer-metrics/micrometer/pull/707, which adds an
exception
tag to@Timed
. So you could drill down dimensionally onexception=none
for “success” and anything else for “throwing”.Yes,
Timer
always ships at a minimum count (of invocations), total time, and max. Optionally distribution statistics like percentiles, histograms, SLAs. Depending on the monitoring system, sometimes also min, standard deviation, etc. Standard deviation is an insane metric to even think about for most real world latencies which are almost never normally distributed, but I digress…It is because timers also count invocations that we say “don’t count something you can time”. Counter statistics are a strict subset, best used for things you can’t time. For example, one counter is
jvm.gc.memory.promoted
. I can’t time the promotion of bytes.We have this principle… “never gauge something you can count, never count something you can time”. Method executions are by definition time-able. Even if you don’t intend to use timing information now, what harm is there in sending the rest of the timing data which of course includes the count?
I’m worried that this feature would help people do the wrong thing… Many start out thinking just about throughput, and it isn’t immediately apparent that timing information is just as relevant.
I’m thinking about the example of “checking open DB connection for liveliness”. I think I’d almost immediately want to know what the max latency looks like on DB connection interactions right after I’ve satisfied my initial desire to verify that there is a certain throughput of queries going through it.