Documentation ¶
Index ¶
- Constants
- Variables
- func NewOtlpMeterProvider(ctx context.Context, log *zap.Logger, c *Config, serviceInstanceID string) (*sdkmetric.MeterProvider, error)
- func NewPrometheusMeterProvider(ctx context.Context, c *Config, serviceInstanceID string) (*sdkmetric.MeterProvider, *prometheus.Registry, error)
- func NewPrometheusServer(logger *zap.Logger, listenAddr string, path string, ...) *http.Server
- type Config
- type Measurements
- type Metrics
- func (h *Metrics) Flush(ctx context.Context) error
- func (h *Metrics) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
- func (h *Metrics) MeasureLatency(ctx context.Context, requestStartTime time.Time, attr ...attribute.KeyValue)
- func (h *Metrics) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
- func (h *Metrics) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
- func (h *Metrics) MeasureRequestSize(ctx context.Context, contentLength int64, attr ...attribute.KeyValue)
- func (h *Metrics) MeasureResponseSize(ctx context.Context, size int64, attr ...attribute.KeyValue)
- func (h *Metrics) Shutdown(ctx context.Context) error
- type NoopMetrics
- func (n NoopMetrics) Flush(ctx context.Context) error
- func (n NoopMetrics) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
- func (n NoopMetrics) MeasureLatency(ctx context.Context, requestStartTime time.Time, attr ...attribute.KeyValue)
- func (n NoopMetrics) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
- func (n NoopMetrics) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
- func (n NoopMetrics) MeasureRequestSize(ctx context.Context, contentLength int64, attr ...attribute.KeyValue)
- func (n NoopMetrics) MeasureResponseSize(ctx context.Context, size int64, attr ...attribute.KeyValue)
- func (n NoopMetrics) Shutdown(ctx context.Context) error
- type OpenTelemetry
- type OpenTelemetryExporter
- type Option
- func WithAttributes(attrs ...attribute.KeyValue) Option
- func WithLogger(logger *zap.Logger) Option
- func WithOtlpMeterProvider(otelMeterProvider *metric.MeterProvider) Option
- func WithProcessStartTime(processStartTime time.Time) Option
- func WithPromMeterProvider(promMeterProvider *metric.MeterProvider) Option
- type OtlpMetricStore
- func (h *OtlpMetricStore) Flush(ctx context.Context) error
- func (h *OtlpMetricStore) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
- func (h *OtlpMetricStore) MeasureLatency(ctx context.Context, requestStartTime time.Time, attr ...attribute.KeyValue)
- func (h *OtlpMetricStore) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
- func (h *OtlpMetricStore) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
- func (h *OtlpMetricStore) MeasureRequestSize(ctx context.Context, contentLength int64, attr ...attribute.KeyValue)
- func (h *OtlpMetricStore) MeasureResponseSize(ctx context.Context, size int64, attr ...attribute.KeyValue)
- type PromMetricStore
- func (h *PromMetricStore) Flush(ctx context.Context) error
- func (h *PromMetricStore) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
- func (h *PromMetricStore) MeasureLatency(ctx context.Context, requestStartTime time.Time, attr ...attribute.KeyValue)
- func (h *PromMetricStore) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
- func (h *PromMetricStore) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
- func (h *PromMetricStore) MeasureRequestSize(ctx context.Context, contentLength int64, attr ...attribute.KeyValue)
- func (h *PromMetricStore) MeasureResponseSize(ctx context.Context, size int64, attr ...attribute.KeyValue)
- func (h *PromMetricStore) Shutdown(ctx context.Context) error
- type PrometheusConfig
- type Provider
- type RuntimeMetrics
- type Store
Constants ¶
View Source
const ( RequestCounter = "router.http.requests" // Incoming request count total ServerLatencyHistogram = "router.http.request.duration_milliseconds" // Incoming end to end duration, milliseconds RequestContentLengthCounter = "router.http.request.content_length" // Incoming request bytes total ResponseContentLengthCounter = "router.http.response.content_length" // Outgoing response bytes total InFlightRequestsUpDownCounter = "router.http.requests.in_flight" // Number of requests in flight RequestError = "router.http.requests.error" // Total request error count )
Server HTTP metrics.
View Source
const ( DefaultMinimumReadMemStatsInterval = 15 * time.Second AttributeGoInfoVersion = attribute.Key("version") )
View Source
const DefaultServerName = "cosmo-router"
DefaultServerName Default resource name.
Variables ¶
View Source
var ( RequestCounterDescription = "Total number of requests" RequestCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithDescription(RequestCounterDescription), } RequestErrorCounterDescription = "Total number of failed request" RequestErrorCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithDescription(RequestErrorCounterDescription), } ServerLatencyHistogramDescription = "Server latency in milliseconds" ServerLatencyHistogramOptions = []otelmetric.Float64HistogramOption{ otelmetric.WithUnit("ms"), otelmetric.WithDescription(ServerLatencyHistogramDescription), } RequestContentLengthCounterDescription = "Total number of request bytes" RequestContentLengthCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithUnit("bytes"), otelmetric.WithDescription(RequestContentLengthCounterDescription), } ResponseContentLengthCounterDescription = "Total number of response bytes" ResponseContentLengthCounterOptions = []otelmetric.Int64CounterOption{ otelmetric.WithUnit("bytes"), otelmetric.WithDescription(ResponseContentLengthCounterDescription), } InFlightRequestsUpDownCounterDescription = "Number of requests in flight" InFlightRequestsUpDownCounterOptions = []otelmetric.Int64UpDownCounterOption{ otelmetric.WithDescription(InFlightRequestsUpDownCounterDescription), } )
Functions ¶
func NewOtlpMeterProvider ¶
func NewPrometheusMeterProvider ¶
func NewPrometheusMeterProvider(ctx context.Context, c *Config, serviceInstanceID string) (*sdkmetric.MeterProvider, *prometheus.Registry, error)
func NewPrometheusServer ¶
Types ¶
type Config ¶
type Config struct { // Name represents the service name for metrics. The default value is cosmo-router. Name string // Version represents the service version for metrics. The default value is dev. Version string // OpenTelemetry includes the OpenTelemetry configuration OpenTelemetry OpenTelemetry // Prometheus includes the Prometheus configuration Prometheus PrometheusConfig // AttributesMapper added to the global attributes for all metrics. AttributesMapper func(req *http.Request) []attribute.KeyValue // ResourceAttributes added to the global resource attributes for all metrics. ResourceAttributes []attribute.KeyValue }
Config represents the configuration for the agent.
func DefaultConfig ¶
DefaultConfig returns the default config.
type Measurements ¶
type Measurements struct {
// contains filtered or unexported fields
}
Measurements holds the metrics for the request.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
func (*Metrics) MeasureInFlight ¶
func (*Metrics) MeasureLatency ¶
func (*Metrics) MeasureRequestCount ¶
func (*Metrics) MeasureRequestError ¶
func (*Metrics) MeasureRequestSize ¶
func (*Metrics) MeasureResponseSize ¶
type NoopMetrics ¶
type NoopMetrics struct{}
func (NoopMetrics) MeasureInFlight ¶
func (n NoopMetrics) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
func (NoopMetrics) MeasureLatency ¶
func (NoopMetrics) MeasureRequestCount ¶
func (n NoopMetrics) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
func (NoopMetrics) MeasureRequestError ¶
func (n NoopMetrics) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
func (NoopMetrics) MeasureRequestSize ¶
func (NoopMetrics) MeasureResponseSize ¶
type OpenTelemetry ¶
type OpenTelemetry struct { Enabled bool RouterRuntime bool Exporters []*OpenTelemetryExporter // TestReader is used for testing purposes. If set, the reader will be used instead of the configured exporters. TestReader sdkmetric.Reader }
type OpenTelemetryExporter ¶
type OpenTelemetryExporter struct { Disabled bool Exporter otelconfig.Exporter Endpoint string // Headers represents the headers for HTTP transport. // For example: // Authorization: 'Bearer <token>' Headers map[string]string // HTTPPath represents the path for OTLP HTTP transport. // For example // /v1/metrics HTTPPath string }
func GetDefaultExporter ¶
func GetDefaultExporter(cfg *Config) *OpenTelemetryExporter
type Option ¶
type Option func(svr *Metrics)
func WithAttributes ¶
WithAttributes adds attributes to the base attributes
func WithLogger ¶
func WithOtlpMeterProvider ¶
func WithOtlpMeterProvider(otelMeterProvider *metric.MeterProvider) Option
func WithProcessStartTime ¶
func WithPromMeterProvider ¶
func WithPromMeterProvider(promMeterProvider *metric.MeterProvider) Option
type OtlpMetricStore ¶
type OtlpMetricStore struct {
// contains filtered or unexported fields
}
func (*OtlpMetricStore) MeasureInFlight ¶
func (h *OtlpMetricStore) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
func (*OtlpMetricStore) MeasureLatency ¶
func (*OtlpMetricStore) MeasureRequestCount ¶
func (h *OtlpMetricStore) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
func (*OtlpMetricStore) MeasureRequestError ¶
func (h *OtlpMetricStore) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
func (*OtlpMetricStore) MeasureRequestSize ¶
func (*OtlpMetricStore) MeasureResponseSize ¶
type PromMetricStore ¶
type PromMetricStore struct {
// contains filtered or unexported fields
}
func (*PromMetricStore) MeasureInFlight ¶
func (h *PromMetricStore) MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func()
func (*PromMetricStore) MeasureLatency ¶
func (*PromMetricStore) MeasureRequestCount ¶
func (h *PromMetricStore) MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue)
func (*PromMetricStore) MeasureRequestError ¶
func (h *PromMetricStore) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue)
func (*PromMetricStore) MeasureRequestSize ¶
func (*PromMetricStore) MeasureResponseSize ¶
type PrometheusConfig ¶
type PrometheusConfig struct { Enabled bool ListenAddr string Path string // Metrics to exclude from Prometheus exporter ExcludeMetrics []*regexp.Regexp // Metric labels to exclude from Prometheus exporter ExcludeMetricLabels []*regexp.Regexp // TestRegistry is used for testing purposes. If set, the registry will be used instead of the default one. TestRegistry *prometheus.Registry }
type Provider ¶
type Provider interface { MeasureInFlight(ctx context.Context, attr ...attribute.KeyValue) func() MeasureRequestCount(ctx context.Context, attr ...attribute.KeyValue) MeasureRequestSize(ctx context.Context, contentLength int64, attr ...attribute.KeyValue) MeasureResponseSize(ctx context.Context, size int64, attr ...attribute.KeyValue) MeasureLatency(ctx context.Context, requestStartTime time.Time, attr ...attribute.KeyValue) MeasureRequestError(ctx context.Context, attr ...attribute.KeyValue) Flush(ctx context.Context) error }
func NewOtlpMetricStore ¶
func NewPromMetricStore ¶
type RuntimeMetrics ¶
type RuntimeMetrics struct {
// contains filtered or unexported fields
}
func NewRuntimeMetrics ¶
func NewRuntimeMetrics(logger *zap.Logger, meterProvider *metric.MeterProvider, baseAttributes []attribute.KeyValue, processStartTime time.Time) *RuntimeMetrics
func (*RuntimeMetrics) Shutdown ¶
func (r *RuntimeMetrics) Shutdown() error
func (*RuntimeMetrics) Start ¶
func (r *RuntimeMetrics) Start() error
type Store ¶
func NewNoopMetrics ¶
func NewNoopMetrics() Store
Click to show internal directories.
Click to hide internal directories.