Documentation
¶
Overview ¶
Package pulse provides standardized metrics collection for hop applications
Index ¶
- Variables
- type Collector
- type Config
- type Counter
- type Gauge
- type Histogram
- type Labels
- type MemoryStatus
- type Module
- func (m *Module) AuthMiddleware() func(http.Handler) http.Handler
- func (m *Module) ID() string
- func (m *Module) Init() error
- func (m *Module) MetricsMiddleware() func(http.Handler) http.Handler
- func (m *Module) RegisterRoutes(handler http.Handler)
- func (m *Module) Start(ctx context.Context) error
- func (m *Module) Stop(ctx context.Context) error
- type StandardCollector
- func (c *StandardCollector) Counter(name string) Counter
- func (c *StandardCollector) DecrementConcurrentRequests()
- func (c *StandardCollector) Gauge(name string) Gauge
- func (c *StandardCollector) Handler() http.Handler
- func (c *StandardCollector) Histogram(name string) Histogram
- func (c *StandardCollector) IncrementConcurrentRequests()
- func (c *StandardCollector) RecordCPUStats()
- func (c *StandardCollector) RecordDiskStats()
- func (c *StandardCollector) RecordGoroutineCount()
- func (c *StandardCollector) RecordHTTPRequest(method, path string, duration time.Duration, statusCode int)
- func (c *StandardCollector) RecordMemStats()
- type StandardCollectorOption
- type ThresholdLevel
- type Thresholds
Constants ¶
This section is empty.
Variables ¶
var DefaultThresholds = Thresholds{
CPUPercent: 75.0,
ClientErrorRatePercent: 40.0,
DiskPercent: 85.0,
GCPauseMs: 100.0,
GoroutineCount: 1000,
MaxGCFrequency: 100.0,
MemoryGrowthRatePercent: 20.0,
MemoryPercent: 80.0,
ServerErrorRatePercent: 1.0,
}
DefaultThresholds provides default threshold values
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector interface { // Counter is for cumulative metrics that only increase Counter(name string) Counter // Gauge is for metrics that can go up and down Gauge(name string) Gauge // Histogram tracks the distribution of a metric Histogram(name string) Histogram // RecordMemStats records memory statistics RecordMemStats() // RecordGoroutineCount records the number of goroutines RecordGoroutineCount() // RecordHTTPRequest records an HTTP request RecordHTTPRequest(method, path string, duration time.Duration, statusCode int) IncrementConcurrentRequests() DecrementConcurrentRequests() // Handler returns an http.Handler for the metrics endpoint Handler() http.Handler }
Collector defines the interface for metrics collection
type Config ¶
type Config struct { // RoutePath is the endpoint where metrics are exposed RoutePath string // RouteUsername is the username required to access the metrics endpoint RouteUsername string // RoutePassword is the password required to access the metrics endpoint RoutePassword string // EnablePprof enables pprof endpoints EnablePprof bool // CollectionInterval is how often to collect system metrics CollectionInterval time.Duration }
type MemoryStatus ¶
type MemoryStatus struct { Level ThresholdLevel Reason string Current float64 Threshold float64 TrendInfo string // Additional information about trends }
MemoryStatus represents the status of a specific memory metric
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements hop.Module for metrics collection
func (*Module) AuthMiddleware ¶
AuthMiddleware creates route.Middleware for authenticating requests to the metrics endpoint
func (*Module) MetricsMiddleware ¶
MetricsMiddleware creates route.Middleware for collecting HTTP metrics
func (*Module) RegisterRoutes ¶
type StandardCollector ¶
type StandardCollector struct {
// contains filtered or unexported fields
}
StandardCollector implements Collector using the standard library
func NewStandardCollector ¶
func NewStandardCollector(opts ...StandardCollectorOption) *StandardCollector
NewStandardCollector creates a new StandardCollector
func (*StandardCollector) Counter ¶
func (c *StandardCollector) Counter(name string) Counter
Counter returns a counter metric
func (*StandardCollector) DecrementConcurrentRequests ¶ added in v0.0.24
func (c *StandardCollector) DecrementConcurrentRequests()
func (*StandardCollector) Gauge ¶
func (c *StandardCollector) Gauge(name string) Gauge
Gauge returns a gauge metric
func (*StandardCollector) Handler ¶
func (c *StandardCollector) Handler() http.Handler
Handler returns an http.Handler for the metrics endpoint as an HTML page
func (*StandardCollector) Histogram ¶
func (c *StandardCollector) Histogram(name string) Histogram
Histogram returns a histogram metric
func (*StandardCollector) IncrementConcurrentRequests ¶ added in v0.0.24
func (c *StandardCollector) IncrementConcurrentRequests()
func (*StandardCollector) RecordCPUStats ¶
func (c *StandardCollector) RecordCPUStats()
RecordCPUStats collects CPU usage statistics
func (*StandardCollector) RecordDiskStats ¶
func (c *StandardCollector) RecordDiskStats()
RecordDiskStats collects disk space usage statistics
func (*StandardCollector) RecordGoroutineCount ¶
func (c *StandardCollector) RecordGoroutineCount()
RecordGoroutineCount captures the number of goroutines
func (*StandardCollector) RecordHTTPRequest ¶
func (c *StandardCollector) RecordHTTPRequest(method, path string, duration time.Duration, statusCode int)
RecordHTTPRequest records metrics about an HTTP request
func (*StandardCollector) RecordMemStats ¶
func (c *StandardCollector) RecordMemStats()
RecordMemStats captures memory statistics
type StandardCollectorOption ¶
type StandardCollectorOption func(*StandardCollector)
StandardCollectorOption is a functional option for configuring a StandardCollector
func WithServerName ¶
func WithServerName(name string) StandardCollectorOption
WithServerName sets the server name for the collector
func WithThresholds ¶
func WithThresholds(thresholds Thresholds) StandardCollectorOption
WithThresholds sets the alert thresholds for the collector
type ThresholdLevel ¶
type ThresholdLevel int
ThresholdLevel is an enumeration of threshold levels
const ( // ThresholdInfo indicates a threshold is informational ThresholdInfo ThresholdLevel = iota // ThresholdOK indicates a threshold is within acceptable limits ThresholdOK // ThresholdWarning indicates a threshold is approaching a warning level ThresholdWarning // ThresholdCritical indicates a threshold has exceeded a critical level ThresholdCritical )
type Thresholds ¶
type Thresholds struct { CPUPercent float64 // CPU usage percentage ClientErrorRatePercent float64 // Higher threshold for 4xx errors DiskPercent float64 // Percentage of disk space used GCPauseMs float64 // Warning when GC pauses exceed this duration GoroutineCount int // Number of goroutines MaxGCFrequency float64 // Warning when GC runs too frequently (times per minute) MemoryGrowthRatePercent float64 // Warning when memory grows too fast (percent per minute) MemoryPercent float64 // Percentage of total memory used ServerErrorRatePercent float64 // Lower threshold for 5xx errors }
Thresholds configuration