metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus metrics collection

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enabled

func Enabled() bool

Enabled returns whether Prometheus metrics should be exposed.

Defaults: - production: disabled unless explicitly enabled via METRICS_ENABLED - non-production: enabled unless explicitly disabled via METRICS_ENABLED

Types

type Metrics

type Metrics struct {
	// HTTP metrics
	RequestsTotal    *prometheus.CounterVec
	RequestDuration  *prometheus.HistogramVec
	RequestsInFlight prometheus.Gauge

	// Error metrics
	ErrorsTotal *prometheus.CounterVec

	// Business metrics
	BlockchainTxTotal    *prometheus.CounterVec
	BlockchainTxDuration *prometheus.HistogramVec

	// Database metrics
	DatabaseQueriesTotal    *prometheus.CounterVec
	DatabaseQueryDuration   *prometheus.HistogramVec
	DatabaseConnectionsOpen prometheus.Gauge

	// Service health
	ServiceUptime prometheus.Gauge
	ServiceInfo   *prometheus.GaugeVec
}

Metrics holds all Prometheus metrics

func Global

func Global() *Metrics

Global returns the global metrics instance

func Init

func Init(serviceName string) *Metrics

Init initializes the global metrics instance

func New

func New(serviceName string) *Metrics

New creates a new Metrics instance with all collectors registered

func NewWithRegistry

func NewWithRegistry(serviceName string, registerer prometheus.Registerer) *Metrics

NewWithRegistry creates a new Metrics instance with a custom registry

func (*Metrics) DecrementInFlight

func (m *Metrics) DecrementInFlight()

DecrementInFlight decrements the in-flight requests counter

func (*Metrics) IncrementInFlight

func (m *Metrics) IncrementInFlight()

IncrementInFlight increments the in-flight requests counter

func (*Metrics) RecordBlockchainTx

func (m *Metrics) RecordBlockchainTx(service, chain, operation, status string, duration time.Duration)

RecordBlockchainTx records a blockchain transaction

func (*Metrics) RecordDatabaseQuery

func (m *Metrics) RecordDatabaseQuery(service, operation, status string, duration time.Duration)

RecordDatabaseQuery records a database query

func (*Metrics) RecordError

func (m *Metrics) RecordError(service, errorType, operation string)

RecordError records an error

func (*Metrics) RecordHTTPRequest

func (m *Metrics) RecordHTTPRequest(service, method, path, status string, duration time.Duration)

RecordHTTPRequest records an HTTP request

func (*Metrics) SetDatabaseConnections

func (m *Metrics) SetDatabaseConnections(count int)

SetDatabaseConnections sets the number of open database connections

func (*Metrics) UpdateUptime

func (m *Metrics) UpdateUptime(startTime time.Time)

UpdateUptime updates the service uptime

Jump to

Keyboard shortcuts

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