Interface LogMetrics
public sealed interface LogMetrics
Metrics are cheap, numeric counters about the logging system itself - for example how
many events an appender has dropped, or how often a reused encoder buffer had to shrink
itself back down. Unlike
LogAlerts, which records discrete events (each with a
message/throwable, kept in a bounded ring buffer), metrics are just running totals: no
per-call allocation, no ring buffer entry, no listener dispatch.
An instance is available from every LogConfig.metrics(). Components that are
provided config, or that are
started with config, should prefer
capturing config.metrics() over reaching for global state.
Deliberately a separate type from LogAlerts rather than more methods on it -
the two are meant to be independently replaceable (e.g. a future Micrometer-backed
LogMetrics without needing to also replace how alerts are recorded).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA single named counter's current value, as returned bycounters().static enumThe fixed, well known set of counters RainbowGum itself records - as opposed to the open ended, per logger name countersLogAlerts.error(LogEvent)also drives intoerrorCounter(String, long). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCounter name for the global count of times a reused encoder buffer had its backing storage shrunk back down after growing past its configured max size (seeLogEncoder.Buffer.isOversized()).static final StringCounter name for the global count of log events dropped without ever being written anywhere - for example an appender dropping events on reentry.static final StringCounter name for the global count of log events an appender failed to write - the encoder or output threw while appending, so the event was caught, alerted (seeLogAlerts.error(Class, String, Throwable)), and lost rather than retried. -
Method Summary
Modifier and TypeMethodDescriptioncounters()A snapshot of every counter recorded viaerrorCounter(String, long)andwarnCounter(String, long).voiderrorCounter(String name, long increment) Increments a counter for something worth tracking as "this happens and it matters".voidwarnCounter(String name, long increment) LikeerrorCounter(String, long)but for something worth tracking yet less significant than an error - a trend worth watching rather than something that, by itself, indicates a problem.
-
Field Details
-
EVENTS_DROPPED_METRIC
Counter name for the global count of log events dropped without ever being written anywhere - for example an appender dropping events on reentry. Incremented whenever a drop happens regardless of whether that particular drop is also logged/alerted, since counting and alerting/logging are separate concerns.- See Also:
-
BUFFER_TRIMMED_METRIC
Counter name for the global count of times a reused encoder buffer had its backing storage shrunk back down after growing past its configured max size (seeLogEncoder.Buffer.isOversized()). An occasional trim is normal and expected once in a while, but resizing often is a sign the configured max size (or the initial size) doesn't match the actual event sizes being logged - worth watching, not erroring on, hencewarnCounter(String, long)rather thanerrorCounter(String, long).- See Also:
-
EVENTS_FAILED_METRIC
Counter name for the global count of log events an appender failed to write - the encoder or output threw while appending, so the event was caught, alerted (seeLogAlerts.error(Class, String, Throwable)), and lost rather than retried. Kept separate fromEVENTS_DROPPED_METRIC: a drop is a deliberate skip (the appender chose not to write), while this is an unexpected failure partway through actually trying to - different root causes worth distinguishing when triaging.- See Also:
-
-
Method Details
-
errorCounter
Increments a counter for something worth tracking as "this happens and it matters".- Parameters:
name- counter name, e.g.EVENTS_DROPPED_METRICor a logger name.increment- amount to add, usually1.
-
warnCounter
LikeerrorCounter(String, long)but for something worth tracking yet less significant than an error - a trend worth watching rather than something that, by itself, indicates a problem. Kept as a separate counter namespace fromerrorCounter(String, long): the samenamepassed to both is two distinct counters, not one shared one.- Parameters:
name- counter name, e.g.BUFFER_TRIMMED_METRIC.increment- amount to add, usually1.
-
counters
A snapshot of every counter recorded viaerrorCounter(String, long)andwarnCounter(String, long). Counters are monotonically increasing for the life of the process, like a Prometheus/Micrometer counter - there is no reset method; a downstream metrics system computes rate of change rather than relying on the counter itself being reset.- Returns:
- immutable snapshot.
-