monitoring

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	// ID is a unique identifier for the alert
	ID string
	// Rule is the rule that generated the alert
	Rule *AlertRule
	// Value is the value that triggered the alert
	Value float64
	// Timestamp is the time the alert was generated
	Timestamp time.Time
	// Message is the alert message
	Message string
	// Acknowledged indicates if the alert has been acknowledged
	Acknowledged bool
	// AcknowledgedBy is the entity that acknowledged the alert
	AcknowledgedBy string
	// AcknowledgedAt is the time the alert was acknowledged
	AcknowledgedAt time.Time
}

Alert represents an alert generated by the system

type AlertHandler

type AlertHandler interface {
	// HandleAlert handles an alert
	HandleAlert(alert *Alert)
}

AlertHandler is an interface for handling alerts

type AlertManager

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

AlertManager manages alert rules and generates alerts

func NewAlertManager

func NewAlertManager(metricsManager *MetricsManager) *AlertManager

NewAlertManager creates a new alert manager

func (*AlertManager) AcknowledgeAlert

func (m *AlertManager) AcknowledgeAlert(alertID, acknowledgedBy string) error

AcknowledgeAlert acknowledges an alert

func (*AlertManager) AddConcurrencyAlertRules

func (m *AlertManager) AddConcurrencyAlertRules(queueUtilizationWarning, queueUtilizationCritical float64, cooldown time.Duration)

AddConcurrencyAlertRules adds alert rules for concurrency

func (*AlertManager) AddExecutionTimeAlertRules

func (m *AlertManager) AddExecutionTimeAlertRules(executionTimeWarningMs, executionTimeCriticalMs float64, cooldown time.Duration)

AddExecutionTimeAlertRules adds alert rules for execution time

func (*AlertManager) AddHandler

func (m *AlertManager) AddHandler(handler AlertHandler)

AddHandler adds an alert handler

func (*AlertManager) AddMemoryAlertRules

func (m *AlertManager) AddMemoryAlertRules(heapAllocWarningMB, heapAllocCriticalMB float64, cooldown time.Duration)

AddMemoryAlertRules adds standard memory alert rules

func (*AlertManager) AddResourcePoolAlertRules

func (m *AlertManager) AddResourcePoolAlertRules(poolUtilizationWarning, poolUtilizationCritical float64, cooldown time.Duration)

AddResourcePoolAlertRules adds alert rules for resource pools

func (*AlertManager) AddRule

func (m *AlertManager) AddRule(rule *AlertRule)

AddRule adds a rule to the alert manager

func (*AlertManager) GetActiveAlerts

func (m *AlertManager) GetActiveAlerts() []*Alert

GetActiveAlerts returns all active alerts

func (*AlertManager) GetAlert

func (m *AlertManager) GetAlert(alertID string) (*Alert, bool)

GetAlert gets an alert by ID

func (*AlertManager) GetAllRules

func (m *AlertManager) GetAllRules() []*AlertRule

GetAllRules returns all rules

func (*AlertManager) GetRule

func (m *AlertManager) GetRule(ruleName string) (*AlertRule, bool)

GetRule gets a rule by name

func (*AlertManager) OnMetricUpdate

func (m *AlertManager) OnMetricUpdate(metric *Metric)

OnMetricUpdate is called when a metric is updated

func (*AlertManager) RemoveRule

func (m *AlertManager) RemoveRule(ruleName string)

RemoveRule removes a rule from the alert manager

func (*AlertManager) ResolveAlert

func (m *AlertManager) ResolveAlert(alertID string) error

ResolveAlert resolves an alert

type AlertManagerAdapter

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

AlertManagerAdapter adapts the existing AlertManager to implement the AlertManagerInterface

func NewAlertManagerAdapter

func NewAlertManagerAdapter(manager interface {
	CheckThreshold(name string, value interface{}, labels map[string]string) error
}) *AlertManagerAdapter

NewAlertManagerAdapter creates a new adapter for AlertManager

func (*AlertManagerAdapter) CheckThreshold

func (a *AlertManagerAdapter) CheckThreshold(name string, value interface{}, tags map[string]string) error

CheckThreshold checks if a value exceeds a threshold

type AlertManagerImpl

type AlertManagerImpl struct {
}

AlertManagerImpl is a simple implementation of the AlertManager for testing

func NewAlertManagerImpl

func NewAlertManagerImpl() *AlertManagerImpl

NewAlertManagerImpl creates a new AlertManagerImpl

func (*AlertManagerImpl) CheckThreshold

func (a *AlertManagerImpl) CheckThreshold(name string, value interface{}, tags map[string]string) error

CheckThreshold checks if a value exceeds a threshold

type AlertManagerInterface

type AlertManagerInterface interface {
	CheckThreshold(name string, value interface{}, tags map[string]string) error
}

AlertManagerInterface defines the interface for an alert manager

type AlertRule

type AlertRule struct {
	// Name of the rule
	Name string
	// Description of the rule
	Description string
	// MetricName is the name of the metric to check
	MetricName string
	// Threshold is the value that triggers the alert
	Threshold float64
	// Operator is the comparison operator (>, <, >=, <=, ==, !=)
	Operator string
	// Severity is the severity of the alert
	Severity AlertSeverity
	// Duration is the minimum duration the condition must be true before alerting
	Duration time.Duration
	// Cooldown is the minimum time between alerts for this rule
	Cooldown time.Duration
	// LastTriggered is the time the rule was last triggered
	LastTriggered time.Time
	// Active indicates if the rule is currently active
	Active bool
}

AlertRule defines a rule for generating alerts based on metric values

type AlertSeverity

type AlertSeverity string

AlertSeverity defines the severity level of an alert

const (
	// InfoSeverity indicates an informational alert
	InfoSeverity AlertSeverity = "info"
	// WarningSeverity indicates a warning alert
	WarningSeverity AlertSeverity = "warning"
	// ErrorSeverity indicates an error alert
	ErrorSeverity AlertSeverity = "error"
	// CriticalSeverity indicates a critical alert
	CriticalSeverity AlertSeverity = "critical"
)

type FileHandlerInterface

type FileHandlerInterface interface {
	GetStats() *Stats
	GetCacheSize() int64
	GetCacheItemCount() int64
}

FileHandlerInterface defines the interface for a static file handler

type LogAlertHandler

type LogAlertHandler struct {
	Logger *log.Logger
}

LogAlertHandler is an alert handler that logs alerts

func (*LogAlertHandler) HandleAlert

func (h *LogAlertHandler) HandleAlert(alert *Alert)

HandleAlert logs the alert

type Metric

type Metric struct {
	Name        string
	Type        MetricType
	Value       float64
	Labels      map[string]string
	LastUpdated time.Time
	Buckets     map[float64]int // For histogram metrics
	Sum         float64         // For histogram metrics
	Count       int             // For histogram metrics
}

Metric represents a single metric

type MetricType

type MetricType string

MetricType defines the type of metric

const (
	// CounterMetric is a cumulative metric that only increases
	CounterMetric MetricType = "counter"
	// GaugeMetric is a metric that can increase and decrease
	GaugeMetric MetricType = "gauge"
	// HistogramMetric is a metric that samples observations and counts them in configurable buckets
	HistogramMetric MetricType = "histogram"
)

type MetricsManager

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

MetricsManager manages metrics collection and reporting

func NewMetricsManager

func NewMetricsManager() *MetricsManager

NewMetricsManager creates a new metrics manager

func (*MetricsManager) CollectSystemMetrics

func (m *MetricsManager) CollectSystemMetrics()

CollectSystemMetrics collects system metrics

func (*MetricsManager) GetAllMetrics

func (m *MetricsManager) GetAllMetrics() map[string]*Metric

GetAllMetrics returns all metrics

func (*MetricsManager) GetHistogramStats

func (m *MetricsManager) GetHistogramStats(name string) (sum float64, count int, buckets map[float64]int, err error)

GetHistogramStats gets statistics for a histogram metric

func (*MetricsManager) GetMetric

func (m *MetricsManager) GetMetric(name string) (*Metric, bool)

GetMetric gets a metric by name

func (*MetricsManager) GetMetricValue

func (m *MetricsManager) GetMetricValue(name string) (float64, error)

GetMetricValue gets the value of a metric

func (*MetricsManager) GetMetricsByPrefix

func (m *MetricsManager) GetMetricsByPrefix(prefix string) map[string]*Metric

GetMetricsByPrefix returns all metrics with the given prefix

func (*MetricsManager) IncrementCounter

func (m *MetricsManager) IncrementCounter(name string, value float64) error

IncrementCounter increments a counter metric by the given value

func (*MetricsManager) ObserveHistogram

func (m *MetricsManager) ObserveHistogram(name string, value float64) error

ObserveHistogram adds an observation to a histogram metric

func (*MetricsManager) RegisterCounter

func (m *MetricsManager) RegisterCounter(name, description string, labels map[string]string) *Metric

RegisterCounter registers a new counter metric

func (*MetricsManager) RegisterGauge

func (m *MetricsManager) RegisterGauge(name, description string, labels map[string]string) *Metric

RegisterGauge registers a new gauge metric

func (*MetricsManager) RegisterHistogram

func (m *MetricsManager) RegisterHistogram(name, description string, buckets []float64, labels map[string]string) *Metric

RegisterHistogram registers a new histogram metric

func (*MetricsManager) ResetMetric

func (m *MetricsManager) ResetMetric(name string) error

ResetMetric resets a metric to its initial value

func (*MetricsManager) SetGauge

func (m *MetricsManager) SetGauge(name string, value float64) error

SetGauge sets a gauge metric to the given value

func (*MetricsManager) StartCollectingSystemMetrics

func (m *MetricsManager) StartCollectingSystemMetrics(interval time.Duration) chan struct{}

StartCollectingSystemMetrics starts collecting system metrics at the specified interval

func (*MetricsManager) Subscribe

func (m *MetricsManager) Subscribe(subscriber MetricsSubscriber)

Subscribe adds a subscriber to be notified of metric updates

func (*MetricsManager) Unsubscribe

func (m *MetricsManager) Unsubscribe(subscriber MetricsSubscriber)

Unsubscribe removes a subscriber

type MetricsManagerAdapter

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

MetricsManagerAdapter adapts the existing MetricsManager to implement the MetricsManagerInterface

func NewMetricsManagerAdapter

func NewMetricsManagerAdapter(manager *MetricsManager) *MetricsManagerAdapter

NewMetricsManagerAdapter creates a new adapter for MetricsManager

func (*MetricsManagerAdapter) RecordCounter

func (a *MetricsManagerAdapter) RecordCounter(name string, value int64, tags map[string]string) error

RecordCounter records a counter metric

func (*MetricsManagerAdapter) RecordGauge

func (a *MetricsManagerAdapter) RecordGauge(name string, value interface{}, tags map[string]string) error

RecordGauge records a gauge metric

func (*MetricsManagerAdapter) RegisterGauge

func (a *MetricsManagerAdapter) RegisterGauge(name string, description string, tags map[string]string) error

RegisterGauge registers a gauge metric

type MetricsManagerInterface

type MetricsManagerInterface interface {
	RecordCounter(name string, value int64, tags map[string]string) error
	RecordGauge(name string, value interface{}, tags map[string]string) error
	RegisterGauge(name string, description string, tags map[string]string) error
}

MetricsManagerInterface defines the interface for a metrics manager

type MetricsSubscriber

type MetricsSubscriber interface {
	OnMetricUpdate(metric *Metric)
}

MetricsSubscriber is an interface for components that want to be notified of metric updates

type MonitoringService

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

MonitoringService provides monitoring and alerting for memory optimization components

func NewMonitoringService

func NewMonitoringService(options *MonitoringServiceOptions) (*MonitoringService, error)

NewMonitoringService creates a new monitoring service

func (*MonitoringService) AddStaticFileMonitor

func (s *MonitoringService) AddStaticFileMonitor(fileHandler FileHandlerInterface) *StaticFileMonitor

AddStaticFileMonitor adds a static file handler to the monitoring service

func (*MonitoringService) CaptureMemorySnapshot

func (s *MonitoringService) CaptureMemorySnapshot(label string) uint64

CaptureMemorySnapshot captures a memory snapshot and returns memory stats

func (*MonitoringService) DisableStaticFileMonitoring

func (s *MonitoringService) DisableStaticFileMonitoring()

DisableStaticFileMonitoring disables monitoring for all static file handlers

func (*MonitoringService) EnableStaticFileMonitoring

func (s *MonitoringService) EnableStaticFileMonitoring()

EnableStaticFileMonitoring enables monitoring for all static file handlers

func (*MonitoringService) GetAlertManager

func (s *MonitoringService) GetAlertManager() interface{}

GetAlertManager returns the alert manager

func (*MonitoringService) GetMemoryUsageMB

func (s *MonitoringService) GetMemoryUsageMB() float64

GetMemoryUsageMB returns the current memory usage in MB

func (*MonitoringService) GetMetricsManager

func (s *MonitoringService) GetMetricsManager() interface{}

GetMetricsManager returns the metrics manager

func (*MonitoringService) GetStaticFileMetrics

func (s *MonitoringService) GetStaticFileMetrics() []*StaticFileMetrics

GetStaticFileMetrics returns metrics for all static file handlers

func (*MonitoringService) GetStaticFileMonitors

func (s *MonitoringService) GetStaticFileMonitors() []*StaticFileMonitor

GetStaticFileMonitors returns all static file monitors

func (*MonitoringService) IsRunning

func (s *MonitoringService) IsRunning() bool

IsRunning returns true if the service is running

func (*MonitoringService) LogMemoryStats

func (s *MonitoringService) LogMemoryStats()

LogMemoryStats logs memory statistics

func (*MonitoringService) MonitorConcurrencyManager

func (s *MonitoringService) MonitorConcurrencyManager(manager interface{})

MonitorConcurrencyManager monitors a concurrency manager

func (*MonitoringService) MonitorResourcePool

func (s *MonitoringService) MonitorResourcePool(pool interface{}, poolName string)

MonitorResourcePool monitors a resource pool

func (*MonitoringService) RecordTemplateExecution

func (s *MonitoringService) RecordTemplateExecution(executionTime time.Duration, memoryBefore, memoryAfter uint64, err error)

RecordTemplateExecution records metrics for a template execution

func (*MonitoringService) Start

func (s *MonitoringService) Start()

Start starts the monitoring service

func (*MonitoringService) Stop

func (s *MonitoringService) Stop()

Stop stops the monitoring service

type MonitoringServiceOptions

type MonitoringServiceOptions struct {
	// CollectionInterval is the interval at which metrics are collected
	CollectionInterval time.Duration
	// LogFile is the file to log to (if empty, logs to stderr)
	LogFile string
	// EnableConsoleLogging enables logging to console
	EnableConsoleLogging bool
	// HeapAllocWarningMB is the heap allocation warning threshold in MB
	HeapAllocWarningMB float64
	// HeapAllocCriticalMB is the heap allocation critical threshold in MB
	HeapAllocCriticalMB float64
	// AlertCooldown is the minimum time between alerts
	AlertCooldown time.Duration
}

MonitoringServiceOptions contains options for the monitoring service

func DefaultMonitoringServiceOptions

func DefaultMonitoringServiceOptions() *MonitoringServiceOptions

DefaultMonitoringServiceOptions returns default options for the monitoring service

type MultiWriter

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

MultiWriter is a writer that writes to multiple writers

func NewMultiWriter

func NewMultiWriter(writers ...interface {
	Write(p []byte) (n int, err error)
}) *MultiWriter

NewMultiWriter creates a new MultiWriter

func (*MultiWriter) Write

func (w *MultiWriter) Write(p []byte) (n int, err error)

Write writes to all writers

type SimpleMetric

type SimpleMetric struct {
	Name        string
	Description string
	Tags        map[string]string
}

SimpleMetric represents a simple metric for testing

type SimpleMetricsManager

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

SimpleMetricsManager is a simple implementation for testing

func (*SimpleMetricsManager) IncrementCounter

func (m *SimpleMetricsManager) IncrementCounter(name string, value float64) error

IncrementCounter increments a counter metric

func (*SimpleMetricsManager) RecordCounter

func (m *SimpleMetricsManager) RecordCounter(name string, value int64, tags map[string]string) error

RecordCounter records a counter metric

func (*SimpleMetricsManager) RecordGauge

func (m *SimpleMetricsManager) RecordGauge(name string, value interface{}, tags map[string]string) error

RecordGauge records a gauge metric

func (*SimpleMetricsManager) RegisterGauge

func (m *SimpleMetricsManager) RegisterGauge(name string, description string, tags map[string]string) *Metric

RegisterGauge registers a gauge metric

func (*SimpleMetricsManager) SetGauge

func (m *SimpleMetricsManager) SetGauge(name string, value float64) error

SetGauge sets a gauge metric value

type StaticFileMetrics

type StaticFileMetrics struct {
	FilesServed      int64
	CacheHits        int64
	CacheMisses      int64
	CacheHitRatio    float64
	CompressedFiles  int64
	TotalSize        int64
	CompressedSize   int64
	CompressionRatio float64
	CacheSize        int64
	CacheItemCount   int64
	AverageServeTime time.Duration
}

StaticFileMetrics contains metrics for the static file handler

type StaticFileMonitor

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

StaticFileMonitor monitors a static file handler

func NewStaticFileMonitor

func NewStaticFileMonitor(fileHandler FileHandlerInterface, metricsManager MetricsManagerInterface, alertManager AlertManagerInterface) *StaticFileMonitor

NewStaticFileMonitor creates a new static file handler monitor

func (*StaticFileMonitor) CheckAlerts

func (m *StaticFileMonitor) CheckAlerts() error

CheckAlerts checks for alert conditions

func (*StaticFileMonitor) CollectMetrics

func (m *StaticFileMonitor) CollectMetrics() error

CollectMetrics collects metrics from the static file handler

func (*StaticFileMonitor) Disable

func (m *StaticFileMonitor) Disable()

Disable disables the monitor

func (*StaticFileMonitor) Enable

func (m *StaticFileMonitor) Enable()

Enable enables the monitor

func (*StaticFileMonitor) GetMetrics

func (m *StaticFileMonitor) GetMetrics() *StaticFileMetrics

GetMetrics returns the current metrics

func (*StaticFileMonitor) SetSampleInterval

func (m *StaticFileMonitor) SetSampleInterval(interval time.Duration)

SetSampleInterval sets the sample interval for metrics collection

func (*StaticFileMonitor) Start

func (m *StaticFileMonitor) Start()

Start starts the monitoring process

type Stats

type Stats struct {
	FilesServed      int64
	CacheHits        int64
	CacheMisses      int64
	CompressedFiles  int64
	TotalSize        int64
	CompressedSize   int64
	CompressionRatio float64
	AverageServeTime time.Duration
}

Stats represents statistics for the file handler

Jump to

Keyboard shortcuts

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