metrics

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package metrics provides OpenTelemetry metrics integration for Bifrost.

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
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

func NewBridge() sdkmetric.Producer

NewBridge creates a new OTel Metric Producer that bridges existing Prometheus metrics. It collects from prometheus.DefaultGatherer.

func NewTracer

func NewTracer(opts ...Option) tracer.Tracer

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

func WithAITPSBuckets(buckets []float64) Option

WithAITPSBuckets define your custom AI TPS buckets.

func WithDisableServer

func WithDisableServer(disable bool) Option

WithDisableServer disable prometheus server.

func WithEnableGoCollector

func WithEnableGoCollector(enable bool) Option

WithEnableGoCollector enable go collector.

func WithGoCollectorRule

func WithGoCollectorRule(rules ...collectors.GoRuntimeMetricsRule) Option

WithGoCollectorRule define your custom go collector rule.

func WithHistogramBuckets

func WithHistogramBuckets(buckets []float64) Option

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

func NewProvider(ctx context.Context, metricsOpts config.MetricsOptions) (*Provider, error)

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

func (p *Provider) MetricsHandler() http.Handler

MetricsHandler returns the HTTP handler for /metrics endpoint.

func (*Provider) PrometheusOptions

func (p *Provider) PrometheusOptions() config.PrometheusOptions

PrometheusOptions returns the Prometheus configuration options.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the MeterProvider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL