org.llm4s.metrics.PrometheusMetrics
See thePrometheusMetrics companion object
Prometheus implementation of MetricsCollector.
Tracks request volumes, token usage, errors, and latency across different providers and models using Prometheus metrics.
All operations are wrapped in try-catch to ensure metric failures never propagate to callers. This implementation is thread-safe.
Example usage:
val registry = new PrometheusRegistry()
val metrics = new PrometheusMetrics(registry)
// Use with endpoint
PrometheusEndpoint.start(9090, registry).foreach { endpoint =>
// ... use metrics ...
endpoint.stop()
}
Value parameters
registry
Prometheus collector registry
Attributes
Companion
object
Graph
Reset zoom Hide graph Show graph
Supertypes
class Object
trait Matchable
class Any
Members list
Record token usage.
Safe: catches and logs any Prometheus errors without propagating.
Attributes
Definition Classes
Record an LLM request with its outcome and duration.
Record an LLM request with its outcome and duration.
Safe: catches and logs any Prometheus errors without propagating.
Attributes
Definition Classes
Record estimated cost in USD.
Record estimated cost in USD.
Safe: catches and logs any Prometheus errors without propagating.
Attributes
Definition Classes
Record circuit breaker state transition.
Record circuit breaker state transition.
Value parameters
newState
New circuit breaker state ("open", "closed", "half-open")
provider
Provider name
Attributes
Inherited from:
MetricsCollector
Record a generic error for metrics (when full request tracking not applicable).
Record a generic error for metrics (when full request tracking not applicable).
Value parameters
errorKind
Type of error
provider
Provider name
Attributes
Inherited from:
MetricsCollector
Record a retry attempt for reliability tracking.
Record a retry attempt for reliability tracking.
Value parameters
attemptNumber
Which retry attempt (1 = first retry, 2 = second, etc.)
provider
Provider name
Attributes
Inherited from:
MetricsCollector