Documentation
¶
Overview ¶
Package metrics provides OpenTelemetry metrics integration for Bifrost.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // AIRequestTTFB represents the AI model thinking speed (TTFB) in seconds. AIRequestTTFB *prom.HistogramVec // AIRequestDuration represents the total AI request duration in seconds. AIRequestDuration *prom.HistogramVec // AIGenerationTPS represents the AI generation tokens per second rate. AIGenerationTPS *prom.HistogramVec // AIInputTokens represents the total prompt tokens consumed. AIInputTokens *prom.CounterVec // AIInputCachedTokens represents the total cached prompt tokens consumed. AIInputCachedTokens *prom.CounterVec // AIOutputTokens represents the total completion tokens consumed. AIOutputTokens *prom.CounterVec // AIOutputReasoningTokens represents the total reasoning tokens consumed. AIOutputReasoningTokens *prom.CounterVec // AITotalTokens represents the total tokens consumed (input + output). AITotalTokens *prom.CounterVec // AIRequestCost represents the total AI request cost in USD. AIRequestCost *prom.CounterVec )
var ( // HTTPServerOpenConnections represents the number of open connections for servers. HTTPServerOpenConnections *prom.GaugeVec // HTTPServiceOpenConnections represents the number of open connections for services. HTTPServiceOpenConnections *prom.GaugeVec )
Functions ¶
func GetMeterProvider ¶
func GetMeterProvider() *sdkmetric.MeterProvider
GetMeterProvider returns the global MeterProvider. This allows users to use OTel SDK for custom metrics if they choose to.
func InitAI ¶ added in v0.11.0
func InitAI(latencyBuckets, tpsBuckets []float64)
InitAI initializes AI-related Prometheus metrics with custom or default buckets.
func NewBridge ¶
NewBridge creates a new OTel Metric Producer that bridges existing Prometheus metrics. It collects from prometheus.DefaultGatherer.
func NewTracer ¶
NewTracer provides tracer for server access, addr and path is the scrape_configs for prometheus server.
func SetMeterProvider ¶
func SetMeterProvider(mp *sdkmetric.MeterProvider)
SetMeterProvider sets the global MeterProvider.
Types ¶
type MetricMiddleware ¶
type MetricMiddleware struct {
// contains filtered or unexported fields
}
MetricMiddleware serves the /metrics endpoint for Prometheus scraping.
func NewMetricMiddleware ¶
func NewMetricMiddleware(path string, provider *Provider) *MetricMiddleware
NewMetricMiddleware creates a new middleware that serves the /metrics endpoint. If provider has a MetricsHandler (OTel Prometheus Exporter), it uses that. Otherwise, falls back to the default promhttp.Handler() for compatibility.
func (*MetricMiddleware) ServeHTTP ¶
func (m *MetricMiddleware) ServeHTTP(ctx context.Context, c *app.RequestContext)
ServeHTTP handles the /metrics endpoint requests.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option defines the configuration options for the metrics tracer.
func WithAITPSBuckets ¶ added in v0.11.0
WithAITPSBuckets define your custom AI TPS buckets.
func WithDisableServer ¶
WithDisableServer disable prometheus server.
func WithEnableGoCollector ¶
WithEnableGoCollector enable go collector.
func WithGoCollectorRule ¶
func WithGoCollectorRule(rules ...collectors.GoRuntimeMetricsRule) Option
WithGoCollectorRule define your custom go collector rule.
func WithHistogramBuckets ¶
WithHistogramBuckets define your custom histogram buckets base on your biz.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider holds the MeterProvider and associated resources.
func NewProvider ¶
NewProvider creates a new metrics Provider with the configured exporters. It supports both Prometheus (pull) and OTLP (push) export modes simultaneously.
func (*Provider) MeterProvider ¶
func (p *Provider) MeterProvider() *sdkmetric.MeterProvider
MeterProvider returns the underlying OTel MeterProvider.
func (*Provider) MetricsHandler ¶
MetricsHandler returns the HTTP handler for /metrics endpoint.
func (*Provider) PrometheusOptions ¶
func (p *Provider) PrometheusOptions() config.PrometheusOptions
PrometheusOptions returns the Prometheus configuration options.