metrics

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package metrics provides gRPC interceptors for metrics.

Package metrics provides utilities for collecting and exposing application metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler() http.Handler

Handler returns an http.Handler for the /metrics endpoint.

Returns:

  • An http.Handler that serves the Prometheus metrics.

func IncrCounter

func IncrCounter(name []string, val float32)

IncrCounter increments a counter.

Parameters:

  • name: The name of the counter (as a path).
  • val: The amount to increment.

func IncrCounterWithLabels added in v0.0.2

func IncrCounterWithLabels(name []string, val float32, labels []metrics.Label)

IncrCounterWithLabels increments a counter with labels.

Parameters:

  • name: The name of the counter (as a path).
  • val: The amount to increment.
  • labels: The labels to apply.

func Initialize

func Initialize() error

Initialize prepares the metrics system with a Prometheus sink. It sets up a global metrics collector that can be used throughout the application. The metrics are exposed on the /metrics endpoint.

Returns:

  • An error if the initialization fails.

func MeasureSince

func MeasureSince(name []string, start time.Time)

MeasureSince measures the time since a given start time and records it.

Parameters:

  • name: The name of the metric (as a path).
  • start: The start time.

func NewPrometheusSink

func NewPrometheusSink() (*prometheus.PrometheusSink, error)

NewPrometheusSink creates a new Prometheus sink for metrics collection.

Returns:

  • A pointer to a prometheus.PrometheusSink.
  • An error if the sink creation fails.

func SetGauge

func SetGauge(name string, val float32, labels ...string)

SetGauge sets the value of a gauge.

Parameters:

  • name: The name of the gauge.
  • val: The value to set.
  • labels: A list of labels to apply to the gauge.

func StartServer

func StartServer(addr string) error

StartServer starts an HTTP server to expose the metrics.

Parameters:

  • addr: The address to listen on (e.g., ":8080").

Returns:

  • An error if the server fails to start.

Types

type GrpcStatsHandler

type GrpcStatsHandler struct{}

GrpcStatsHandler is a gRPC stats handler that records metrics for RPCs and connections.

func (*GrpcStatsHandler) HandleConn

func (h *GrpcStatsHandler) HandleConn(_ context.Context, s stats.ConnStats)

HandleConn processes connection stats and increments counters for opened and closed connections.

Parameters:

  • ctx: The context of the connection.
  • s: The connection stats.

func (*GrpcStatsHandler) HandleRPC

func (h *GrpcStatsHandler) HandleRPC(_ context.Context, s stats.RPCStats)

HandleRPC processes RPC stats and increments counters for started and finished RPCs.

Parameters:

  • ctx: The context of the RPC.
  • s: The RPC stats.

func (*GrpcStatsHandler) TagConn

TagConn can be used to tag connections with custom information.

Parameters:

  • ctx: The context of the connection.
  • _ : Information about the connection tag (unused).

Returns:

  • The context, potentially modified with new tags.

func (*GrpcStatsHandler) TagRPC

TagRPC can be used to tag RPCs with custom information.

Parameters:

  • ctx: The context of the RPC.
  • _ : Information about the RPC tag (unused).

Returns:

  • The context, potentially modified with new tags.

type Label added in v0.0.2

type Label = metrics.Label

Label is an alias for metrics.Label. It represents a key-value pair for labeling metrics.

Jump to

Keyboard shortcuts

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