metrics

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package metrics provides comprehensive metrics collection for Hockeypuck

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter provides a simple counter interface

func NewCounter

func NewCounter(name, help string) *Counter

NewCounter creates a new counter

func (*Counter) Add

func (c *Counter) Add(value float64)

Add adds a value to the counter

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments the counter

type Gauge

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

Gauge provides a simple gauge interface

func NewGauge

func NewGauge(name, help string) *Gauge

NewGauge creates a new gauge

func (*Gauge) Add

func (g *Gauge) Add(value float64)

Add adds a value to the gauge

func (*Gauge) Dec

func (g *Gauge) Dec()

Dec decrements the gauge

func (*Gauge) Inc

func (g *Gauge) Inc()

Inc increments the gauge

func (*Gauge) Set

func (g *Gauge) Set(value float64)

Set sets the gauge value

func (*Gauge) Sub

func (g *Gauge) Sub(value float64)

Sub subtracts a value from the gauge

type HTTPMetrics

type HTTPMetrics struct {
	RequestsInFlight prometheus.Gauge
	RequestsTotal    *prometheus.CounterVec
	RequestDuration  *prometheus.HistogramVec
	RequestSize      *prometheus.HistogramVec
	ResponseSize     *prometheus.HistogramVec
	ResponseTime     *prometheus.HistogramVec

	// Status code metrics
	StatusCodes *prometheus.CounterVec

	// Endpoint metrics
	EndpointCalls    *prometheus.CounterVec
	EndpointDuration *prometheus.HistogramVec
	EndpointErrors   *prometheus.CounterVec

	// User agent metrics
	UserAgents *prometheus.CounterVec

	// Geographic metrics
	RequestsByCountry *prometheus.CounterVec
}

HTTPMetrics contains HTTP-related metrics

func NewHTTPMetrics

func NewHTTPMetrics(registry *prometheus.Registry) *HTTPMetrics

NewHTTPMetrics creates new HTTP metrics

type HealthMetrics

type HealthMetrics struct {
	HealthChecks        *prometheus.GaugeVec
	HealthCheckDuration *prometheus.HistogramVec
	ComponentStatus     *prometheus.GaugeVec
	LastHealthCheck     prometheus.Gauge
}

HealthMetrics contains health check metrics

func NewHealthMetrics

func NewHealthMetrics() *HealthMetrics

NewHealthMetrics creates new health metrics

type Metrics

type Metrics struct {

	// Core server metrics
	ServerMetrics *ServerMetrics

	// Storage metrics
	StorageMetrics *StorageMetrics

	// Rate limiting metrics
	RateLimitMetrics *RateLimitMetrics

	// Plugin metrics
	PluginMetrics *PluginMetrics

	// HTTP metrics
	HTTPMetrics *HTTPMetrics

	// Custom metrics
	CustomMetrics map[string]interface{}
	// contains filtered or unexported fields
}

Metrics represents the main metrics system

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new metrics system (singleton)

func (*Metrics) Collect

func (m *Metrics) Collect() (map[string]interface{}, error)

Collect collects metrics from all registered collectors

func (*Metrics) DeleteCustomMetric

func (m *Metrics) DeleteCustomMetric(name string)

DeleteCustomMetric deletes a custom metric

func (*Metrics) GetCustomMetric

func (m *Metrics) GetCustomMetric(name string) (interface{}, bool)

GetCustomMetric gets a custom metric value

func (*Metrics) JSONHandler

func (m *Metrics) JSONHandler() http.HandlerFunc

JSONHandler returns a JSON metrics HTTP handler

func (*Metrics) PrometheusHandler

func (m *Metrics) PrometheusHandler() http.Handler

PrometheusHandler returns a Prometheus metrics HTTP handler

func (*Metrics) RegisterCollector

func (m *Metrics) RegisterCollector(collector MetricsCollector) error

RegisterCollector registers a custom metrics collector

func (*Metrics) Registry

func (m *Metrics) Registry() *prometheus.Registry

Registry provides access to the Prometheus registry

func (*Metrics) SetCustomMetric

func (m *Metrics) SetCustomMetric(name string, value interface{})

SetCustomMetric sets a custom metric value

func (*Metrics) UnregisterCollector

func (m *Metrics) UnregisterCollector(name string) error

UnregisterCollector unregisters a metrics collector

type MetricsCollector

type MetricsCollector interface {
	Collect() (map[string]interface{}, error)
	Name() string
	Description() string
}

MetricsCollector interface for custom metrics collectors

type MetricsUpdater

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

MetricsUpdater manages periodic metrics updates

func NewMetricsUpdater

func NewMetricsUpdater(interval time.Duration) *MetricsUpdater

NewMetricsUpdater creates a new metrics updater

func (*MetricsUpdater) AddUpdater

func (mu *MetricsUpdater) AddUpdater(updater UpdaterFunc)

AddUpdater adds a metrics updater function

func (*MetricsUpdater) Start

func (mu *MetricsUpdater) Start()

Start starts the metrics updater

func (*MetricsUpdater) Stop

func (mu *MetricsUpdater) Stop()

Stop stops the metrics updater

type PluginMetrics

type PluginMetrics struct {
	PluginsLoaded     prometheus.Gauge
	PluginLoadTime    *prometheus.HistogramVec
	PluginErrors      *prometheus.CounterVec
	PluginInitTime    *prometheus.HistogramVec
	PluginMemoryUsage *prometheus.GaugeVec
	PluginCPUUsage    *prometheus.GaugeVec

	// Plugin lifecycle
	PluginLifecycle    *prometheus.CounterVec
	PluginDependencies *prometheus.GaugeVec

	// Plugin performance
	PluginExecution *prometheus.HistogramVec
	PluginCalls     *prometheus.CounterVec
}

PluginMetrics contains plugin-related metrics

func NewPluginMetrics

func NewPluginMetrics(registry *prometheus.Registry) *PluginMetrics

NewPluginMetrics creates new plugin metrics

type RateLimitMetrics

type RateLimitMetrics struct {
	ViolationsTotal *prometheus.CounterVec
	BannedIPs       *prometheus.GaugeVec
	TrackedIPs      prometheus.Gauge
	TorExitCount    prometheus.Gauge
	BackendDuration *prometheus.HistogramVec
	BackendErrors   *prometheus.CounterVec

	// Connection metrics
	ConnectionsRejected *prometheus.CounterVec
	ConnectionsActive   *prometheus.GaugeVec

	// Request metrics
	RequestsRejected *prometheus.CounterVec
	RequestRate      *prometheus.GaugeVec

	// Error tracking
	ErrorRate   *prometheus.GaugeVec
	ErrorsTotal *prometheus.CounterVec
}

RateLimitMetrics contains rate limiting metrics

func NewRateLimitMetrics

func NewRateLimitMetrics(registry *prometheus.Registry) *RateLimitMetrics

NewRateLimitMetrics creates new rate limiting metrics

type ServerMetrics

type ServerMetrics struct {
	StartTime       prometheus.Gauge
	Uptime          prometheus.Gauge
	Version         *prometheus.GaugeVec
	BuildInfo       *prometheus.GaugeVec
	GoVersion       prometheus.Gauge
	GoRoutines      prometheus.Gauge
	MemoryUsage     prometheus.Gauge
	CPUUsage        prometheus.Gauge
	FileDescriptors prometheus.Gauge

	// Request metrics
	RequestsTotal   *prometheus.CounterVec
	RequestDuration *prometheus.HistogramVec
	RequestSize     *prometheus.HistogramVec
	ResponseSize    *prometheus.HistogramVec

	// Connection metrics
	ActiveConnections prometheus.Gauge
	TotalConnections  prometheus.Counter
}

ServerMetrics contains core server metrics

func NewServerMetrics

func NewServerMetrics(registry *prometheus.Registry) *ServerMetrics

NewServerMetrics creates new server metrics

type StorageMetrics

type StorageMetrics struct {
	KeysTotal      prometheus.Gauge
	KeysInserted   prometheus.Counter
	KeysUpdated    prometheus.Counter
	KeysDeleted    prometheus.Counter
	KeysIgnored    prometheus.Counter
	KeysDuplicated prometheus.Counter

	// Storage operations
	OperationsTotal   *prometheus.CounterVec
	OperationDuration *prometheus.HistogramVec
	OperationErrors   *prometheus.CounterVec

	// Database metrics
	DatabaseConnections     prometheus.Gauge
	DatabaseConnectionsIdle prometheus.Gauge
	DatabaseQueries         *prometheus.CounterVec
	DatabaseQueryDuration   *prometheus.HistogramVec
	DatabaseSize            prometheus.Gauge

	// Index metrics
	IndexSize        *prometheus.GaugeVec
	IndexUsage       *prometheus.CounterVec
	IndexMaintenance *prometheus.CounterVec
}

StorageMetrics contains storage-related metrics

func NewStorageMetrics

func NewStorageMetrics(registry *prometheus.Registry) *StorageMetrics

NewStorageMetrics creates new storage metrics

type Timer

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

Timer provides timing functionality for metrics

func NewTimer

func NewTimer(observer prometheus.Observer) *Timer

NewTimer creates a new timer

func (*Timer) ObserveDuration

func (t *Timer) ObserveDuration()

ObserveDuration observes the elapsed time since timer creation

type UpdaterFunc

type UpdaterFunc func(context.Context) error

UpdaterFunc represents a function that updates metrics

Jump to

Keyboard shortcuts

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