question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add @Counted annotation similar to @Timed

See original GitHub issue

Sometimes 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:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
jkschneidercommented, Sep 13, 2018

However does @Timed also verify the return type (success/throwing)?

@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 on exception=none for “success” and anything else for “throwing”.

Does it count invocations at all, or just time them?

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.

3reactions
jkschneidercommented, Sep 12, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found