Package com.tnsai.quality.observability
Class Metrics
java.lang.Object
com.tnsai.quality.observability.Metrics
Simple metrics collection for agent operations.
Provides counters, gauges, and histograms for tracking:
- Action execution counts and durations
- LLM call counts, tokens, and latencies
- Message throughput
- Error rates
Example usage:
Metrics metrics = Metrics.getInstance();
// Count events
metrics.increment("agent.actions.total");
metrics.increment("agent.actions.success");
// Record values
metrics.record("agent.action.duration_ms", 150);
metrics.record("llm.tokens.prompt", 500);
// Get current values
long totalActions = metrics.getCount("agent.actions.total");
double avgDuration = metrics.getAverage("agent.action.duration_ms");
Integration with monitoring systems:
// Export all metrics Map<String, Number> snapshot = metrics.snapshot(); // Clear metrics (e.g., after export) metrics.reset();
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringHistogram: Action duration in msstatic final StringCounter: Failed actionsstatic final StringCounter: Successful actionsstatic final StringCounter: Total actions executedstatic final StringGauge: Active agentsstatic final StringCounter: LLM call errorsstatic final StringCounter: Total LLM callsstatic final StringCounter: Total completion tokensstatic final StringHistogram: LLM call latency in msstatic final StringCounter: Total prompt tokensstatic final StringCounter: Messages receivedstatic final StringCounter: Messages sent -
Method Summary
Modifier and TypeMethodDescriptionvoidSets a gauge to a specific value.doublegetAverage(String name) Gets the average value for a histogram.longGets the current count for a counter.longGets the current gauge value.longgetHistogramCount(String name) Gets the count of values recorded in a histogram.static MetricsGets the singleton metrics instance.longGets the maximum value for a histogram.longGets the minimum value for a histogram.voidIncrements a counter by 1.voidIncrements a counter by a specified amount.voidRecords a value in a histogram.voidreset()Resets all metrics to zero.snapshot()Creates a snapshot of all metrics.
-
Field Details
-
ACTIONS_TOTAL
Counter: Total actions executed- See Also:
-
ACTIONS_SUCCESS
Counter: Successful actions- See Also:
-
ACTIONS_FAILED
Counter: Failed actions- See Also:
-
ACTION_DURATION
Histogram: Action duration in ms- See Also:
-
LLM_CALLS_TOTAL
Counter: Total LLM calls- See Also:
-
LLM_CALLS_FAILED
Counter: LLM call errors- See Also:
-
LLM_LATENCY
Histogram: LLM call latency in ms- See Also:
-
LLM_PROMPT_TOKENS
Counter: Total prompt tokens- See Also:
-
LLM_COMPLETION_TOKENS
Counter: Total completion tokens- See Also:
-
MESSAGES_SENT
Counter: Messages sent- See Also:
-
MESSAGES_RECEIVED
Counter: Messages received- See Also:
-
ACTIVE_AGENTS
Gauge: Active agents- See Also:
-
-
Method Details
-
getInstance
Gets the singleton metrics instance.- Returns:
- the metrics instance
-
increment
Increments a counter by 1.- Parameters:
name- the counter name
-
increment
Increments a counter by a specified amount.- Parameters:
name- the counter namedelta- the amount to add
-
getCount
Gets the current count for a counter.- Parameters:
name- the counter name- Returns:
- the current count
-
gauge
Sets a gauge to a specific value.- Parameters:
name- the gauge namevalue- the value
-
getGauge
Gets the current gauge value.- Parameters:
name- the gauge name- Returns:
- the current value
-
record
Records a value in a histogram.- Parameters:
name- the histogram namevalue- the value to record
-
getAverage
Gets the average value for a histogram.- Parameters:
name- the histogram name- Returns:
- the average, or 0 if no values
-
getMin
Gets the minimum value for a histogram.- Parameters:
name- the histogram name- Returns:
- the minimum, or 0 if no values
-
getMax
Gets the maximum value for a histogram.- Parameters:
name- the histogram name- Returns:
- the maximum, or 0 if no values
-
getHistogramCount
Gets the count of values recorded in a histogram.- Parameters:
name- the histogram name- Returns:
- the count
-
snapshot
Creates a snapshot of all metrics.- Returns:
- map of metric names to values
-
reset
public void reset()Resets all metrics to zero.
-