Documentation
¶
Overview ¶
Package metrics provides gRPC interceptors for metrics.
Package metrics provides utilities for collecting and exposing application metrics.
Index ¶
- func Handler() http.Handler
- func IncrCounter(name []string, val float32)
- func IncrCounterWithLabels(name []string, val float32, labels []metrics.Label)
- func Initialize() error
- func MeasureSince(name []string, start time.Time)
- func NewPrometheusSink() (*prometheus.PrometheusSink, error)
- func SetGauge(name string, val float32, labels ...string)
- func StartServer(addr string) error
- type GrpcStatsHandler
- func (h *GrpcStatsHandler) HandleConn(_ context.Context, s stats.ConnStats)
- func (h *GrpcStatsHandler) HandleRPC(_ context.Context, s stats.RPCStats)
- func (h *GrpcStatsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
- func (h *GrpcStatsHandler) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context
- type Label
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns an http.Handler for the /metrics endpoint.
Returns:
- An http.Handler that serves the Prometheus metrics.
func IncrCounter ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
func (h *GrpcStatsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
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 ¶
func (h *GrpcStatsHandler) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context
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.