metrics

package
v0.0.0-...-54f4ef6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BandwidthMbpsBuckets

func BandwidthMbpsBuckets() []float64

BandwidthMbpsBuckets is for per-request throughput in MiB/s, covering everything from slow long-tail clients (a few MiB/s) up through saturated 10 GbE links (~1.2 GiB/s) and the parallel-stream-on-localhost ceiling.

func ByteBuckets

func ByteBuckets() []float64

ByteBuckets covers cachew payload sizes, which range from tiny bundles (a few KiB) to multi-GiB snapshot tarballs.

func FastLatencyBuckets

func FastLatencyBuckets() []float64

FastLatencyBuckets is for operations expected to complete in well under a minute (spool follower waits, ensure-refs round trips).

func LatencyBuckets

func LatencyBuckets() []float64

LatencyBuckets covers operations that span sub-millisecond cache hits all the way to multi-minute clone/repack/generation work. The default OTel histogram boundaries (0..10 seconds) compress everything beyond 10s into the +Inf bucket, which makes p50/p90/avg unusable for cachew's git path.

func NewHistogram

func NewHistogram(meter metric.Meter, path, unit, description string, buckets []float64) metric.Float64Histogram

NewHistogram creates a Float64Histogram with explicit bucket boundaries. Prefer this over NewMetric for histograms: the OTel SDK default boundaries only go up to 10 seconds, which is far too narrow for most cachew metrics.

func NewMetric

func NewMetric[OM any](meter metric.Meter, path, unit, description string) OM

func SmallCountBuckets

func SmallCountBuckets() []float64

SmallCountBuckets is for low-cardinality integer counts (e.g. number of pack files on a mirror), where the values of interest are mostly in the 1–100 range with a long tail.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides OpenTelemetry metrics with configurable exporters.

func New

func New(ctx context.Context, cfg Config) (*Client, error)

New creates a new OpenTelemetry metrics client with configurable exporters.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the meter provider.

func (*Client) Handler

func (c *Client) Handler() http.Handler

Handler returns the HTTP handler for the /metrics endpoint.

func (*Client) ServeMetrics

func (c *Client) ServeMetrics(ctx context.Context) error

ServeMetrics starts a dedicated HTTP server for Prometheus metrics scraping. This is only started if Prometheus exporter is enabled.

type Config

type Config struct {
	ServiceName        string `hcl:"service-name" help:"Service name for metrics." default:"cachew"`
	Port               int    `hcl:"port" help:"Port for Prometheus metrics server." default:"9102"`
	EnablePrometheus   bool   `hcl:"enable-prometheus" help:"Enable Prometheus exporter." default:"true"`
	EnableOTLP         bool   `hcl:"enable-otlp" help:"Enable OTLP exporter." default:"false"`
	OTLPEndpoint       string `hcl:"otlp-endpoint" help:"OTLP endpoint URL." default:"http://localhost:4318"`
	OTLPInsecure       bool   `hcl:"otlp-insecure" help:"Use insecure connection for OTLP." default:"false"`
	OTLPExportInterval int    `hcl:"otlp-export-interval" help:"OTLP export interval in seconds." default:"60"`
}

Config holds metrics configuration.

Jump to

Keyboard shortcuts

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