monitoring

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatedMetric

type AggregatedMetric struct {
	Name       string
	Type       MetricType
	Tags       map[string]string
	Count      int64
	Sum        float64
	Min        float64
	Max        float64
	LastUpdate time.Time
}

AggregatedMetric holds aggregated data for a metric

type CompositeObservabilityHook

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

CompositeObservabilityHook combines multiple hooks

func NewCompositeObservabilityHook

func NewCompositeObservabilityHook(hooks ...ObservabilityHook) *CompositeObservabilityHook

NewCompositeObservabilityHook creates a new composite hook

func (*CompositeObservabilityHook) OnError

func (c *CompositeObservabilityHook) OnError(ctx context.Context, operation string, err error, metadata map[string]any)

func (*CompositeObservabilityHook) OnKeyOperation

func (c *CompositeObservabilityHook) OnKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)

func (*CompositeObservabilityHook) OnProcessComplete

func (c *CompositeObservabilityHook) OnProcessComplete(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

func (*CompositeObservabilityHook) OnProcessStart

func (c *CompositeObservabilityHook) OnProcessStart(ctx context.Context, operation string, metadata map[string]any)

type ConsoleHandler

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

ConsoleHandler provides colorized console output

func NewConsoleHandler

func NewConsoleHandler(output io.Writer, opts *slog.HandlerOptions) *ConsoleHandler

NewConsoleHandler creates a new console handler

func (*ConsoleHandler) Enabled

func (h *ConsoleHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*ConsoleHandler) Handle

func (h *ConsoleHandler) Handle(ctx context.Context, record slog.Record) error

func (*ConsoleHandler) WithAttrs

func (h *ConsoleHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ConsoleHandler) WithGroup

func (h *ConsoleHandler) WithGroup(name string) slog.Handler

type EnhancedMetricsCollector

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

EnhancedMetricsCollector provides advanced metrics collection with multiple backends

func NewEnhancedMetricsCollector

func NewEnhancedMetricsCollector(config EnhancedMetricsConfig) *EnhancedMetricsCollector

NewEnhancedMetricsCollector creates a new enhanced metrics collector

func (*EnhancedMetricsCollector) Flush

func (e *EnhancedMetricsCollector) Flush() error

Flush exports all metrics to backends

func (*EnhancedMetricsCollector) GetAggregatedMetrics

func (e *EnhancedMetricsCollector) GetAggregatedMetrics() map[string]*AggregatedMetric

GetAggregatedMetrics returns current aggregated metrics

func (*EnhancedMetricsCollector) IncrementCounter

func (e *EnhancedMetricsCollector) IncrementCounter(name string, tags map[string]string)

IncrementCounter increments a counter metric

func (*EnhancedMetricsCollector) IncrementCounterBy

func (e *EnhancedMetricsCollector) IncrementCounterBy(name string, value int64, tags map[string]string)

IncrementCounterBy increments a counter by a specific value

func (*EnhancedMetricsCollector) RecordBusinessMetric

func (e *EnhancedMetricsCollector) RecordBusinessMetric(name string, value float64, unit string, tags map[string]string)

RecordBusinessMetric records a business-specific metric

func (*EnhancedMetricsCollector) RecordPerformanceMetric

func (e *EnhancedMetricsCollector) RecordPerformanceMetric(operation string, duration time.Duration, success bool, tags map[string]string)

RecordPerformanceMetric records performance-related metrics

func (*EnhancedMetricsCollector) RecordSecurityMetric

func (e *EnhancedMetricsCollector) RecordSecurityMetric(event string, severity string, tags map[string]string)

RecordSecurityMetric records security-related metrics

func (*EnhancedMetricsCollector) RecordTiming

func (e *EnhancedMetricsCollector) RecordTiming(name string, duration time.Duration, tags map[string]string)

RecordTiming records a timing/duration metric

func (*EnhancedMetricsCollector) RecordValue

func (e *EnhancedMetricsCollector) RecordValue(name string, value float64, tags map[string]string)

RecordValue records a value metric

func (*EnhancedMetricsCollector) SetGauge

func (e *EnhancedMetricsCollector) SetGauge(name string, value float64, tags map[string]string)

SetGauge sets a gauge metric value

func (*EnhancedMetricsCollector) Stop

func (e *EnhancedMetricsCollector) Stop() error

Stop stops the metrics collector and exports remaining metrics

type EnhancedMetricsConfig

type EnhancedMetricsConfig struct {
	ExportPeriod      time.Duration
	AggregationPeriod time.Duration
	Backends          []MetricsBackend
	Logger            Logger
	EnableRateLimit   bool
}

EnhancedMetricsConfig configures the enhanced metrics collector

type EnhancedObservabilityConfig

type EnhancedObservabilityConfig struct {
	Logger                *StructuredLogger
	MetricsCollector      *EnhancedMetricsCollector
	EnablePerfMetrics     bool
	EnableSecurityMetrics bool
}

EnhancedObservabilityConfig configures the enhanced observability hook

type EnhancedObservabilityHook

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

EnhancedObservabilityHook combines structured logging and enhanced metrics

func NewEnhancedObservabilityHook

func NewEnhancedObservabilityHook(config EnhancedObservabilityConfig) *EnhancedObservabilityHook

NewEnhancedObservabilityHook creates a new enhanced observability hook

func (*EnhancedObservabilityHook) GetLogger

GetLogger returns the structured logger for external use

func (*EnhancedObservabilityHook) GetMetricsCollector

func (e *EnhancedObservabilityHook) GetMetricsCollector() *EnhancedMetricsCollector

GetMetricsCollector returns the metrics collector for external use

func (*EnhancedObservabilityHook) OnCacheOperation

func (e *EnhancedObservabilityHook) OnCacheOperation(ctx context.Context, operation string, hit bool, duration time.Duration, metadata map[string]any)

OnCacheOperation logs cache-related operations

func (*EnhancedObservabilityHook) OnDatabaseOperation

func (e *EnhancedObservabilityHook) OnDatabaseOperation(ctx context.Context, operation string, table string, duration time.Duration, err error, metadata map[string]any)

OnDatabaseOperation logs database-related operations

func (*EnhancedObservabilityHook) OnError

func (e *EnhancedObservabilityHook) OnError(ctx context.Context, operation string, err error, metadata map[string]any)

OnError logs and records metrics when errors occur

func (*EnhancedObservabilityHook) OnKeyOperation

func (e *EnhancedObservabilityHook) OnKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)

OnKeyOperation logs and records metrics for key operations

func (*EnhancedObservabilityHook) OnProcessComplete

func (e *EnhancedObservabilityHook) OnProcessComplete(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

OnProcessComplete logs and records metrics when processing completes

func (*EnhancedObservabilityHook) OnProcessStart

func (e *EnhancedObservabilityHook) OnProcessStart(ctx context.Context, operation string, metadata map[string]any)

OnProcessStart logs and records metrics when processing starts

func (*EnhancedObservabilityHook) Stop

func (e *EnhancedObservabilityHook) Stop() error

Stop gracefully stops the observability hook

type FileMetricsBackend

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

FileMetricsBackend writes metrics to a file

func NewFileMetricsBackend

func NewFileMetricsBackend(filepath string) *FileMetricsBackend

func (*FileMetricsBackend) Close

func (f *FileMetricsBackend) Close() error

func (*FileMetricsBackend) Export

func (f *FileMetricsBackend) Export(ctx context.Context, metrics []Metric) error

func (*FileMetricsBackend) Name

func (f *FileMetricsBackend) Name() string

type InMemoryMetricsCollector

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

InMemoryMetricsCollector is an in-memory implementation for testing

func NewInMemoryMetricsCollector

func NewInMemoryMetricsCollector() *InMemoryMetricsCollector

NewInMemoryMetricsCollector creates a new in-memory metrics collector

func (*InMemoryMetricsCollector) Flush

func (m *InMemoryMetricsCollector) Flush() error

func (*InMemoryMetricsCollector) GetCounter

func (m *InMemoryMetricsCollector) GetCounter(name string, tags map[string]string) int64

GetCounter returns the value of a counter

func (*InMemoryMetricsCollector) GetGauge

func (m *InMemoryMetricsCollector) GetGauge(name string, tags map[string]string) float64

GetGauge returns the value of a gauge

func (*InMemoryMetricsCollector) GetTimings

func (m *InMemoryMetricsCollector) GetTimings(name string, tags map[string]string) []time.Duration

GetTimings returns all recorded timings

func (*InMemoryMetricsCollector) GetValues

func (m *InMemoryMetricsCollector) GetValues(name string, tags map[string]string) []float64

GetValues returns all recorded values

func (*InMemoryMetricsCollector) IncrementCounter

func (m *InMemoryMetricsCollector) IncrementCounter(name string, tags map[string]string)

func (*InMemoryMetricsCollector) IncrementCounterBy

func (m *InMemoryMetricsCollector) IncrementCounterBy(name string, value int64, tags map[string]string)

func (*InMemoryMetricsCollector) RecordTiming

func (m *InMemoryMetricsCollector) RecordTiming(name string, duration time.Duration, tags map[string]string)

func (*InMemoryMetricsCollector) RecordValue

func (m *InMemoryMetricsCollector) RecordValue(name string, value float64, tags map[string]string)

func (*InMemoryMetricsCollector) Reset

func (m *InMemoryMetricsCollector) Reset()

Reset clears all metrics

func (*InMemoryMetricsCollector) SetGauge

func (m *InMemoryMetricsCollector) SetGauge(name string, value float64, tags map[string]string)

type LogFormat

type LogFormat int

LogFormat represents the output format for logs

const (
	FormatJSON LogFormat = iota
	FormatText
	FormatConsole
)

type LogLevel

type LogLevel int

LogLevel represents the severity level of a log message

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

func (LogLevel) String

func (l LogLevel) String() string

String returns the string representation of the log level

type Logger

type Logger interface {
	Info(msg string, args ...any)
	Error(msg string, args ...any)
	Debug(msg string, args ...any)
}

Logger defines the interface for logging

type LoggerConfig

type LoggerConfig struct {
	Level     LogLevel
	Format    LogFormat
	Output    io.Writer
	Component string
	Fields    map[string]any
}

LoggerConfig configures the structured logger

type LoggingObservabilityHook

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

LoggingObservabilityHook logs all operations

func NewLoggingObservabilityHook

func NewLoggingObservabilityHook(logger Logger) *LoggingObservabilityHook

NewLoggingObservabilityHook creates a new logging observability hook

func (*LoggingObservabilityHook) OnError

func (l *LoggingObservabilityHook) OnError(ctx context.Context, operation string, err error, metadata map[string]any)

func (*LoggingObservabilityHook) OnKeyOperation

func (l *LoggingObservabilityHook) OnKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)

func (*LoggingObservabilityHook) OnProcessComplete

func (l *LoggingObservabilityHook) OnProcessComplete(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

func (*LoggingObservabilityHook) OnProcessStart

func (l *LoggingObservabilityHook) OnProcessStart(ctx context.Context, operation string, metadata map[string]any)

type Metric

type Metric struct {
	Name      string            `json:"name"`
	Type      MetricType        `json:"type"`
	Value     float64           `json:"value"`
	Tags      map[string]string `json:"tags,omitempty"`
	Timestamp time.Time         `json:"timestamp"`
	Unit      string            `json:"unit,omitempty"`
}

Metric represents a single metric measurement

type MetricType

type MetricType string

MetricType represents the type of metric

const (
	MetricTypeCounter   MetricType = "counter"
	MetricTypeGauge     MetricType = "gauge"
	MetricTypeHistogram MetricType = "histogram"
	MetricTypeSummary   MetricType = "summary"
)

type MetricsBackend

type MetricsBackend interface {
	// Export metrics to the backend
	Export(ctx context.Context, metrics []Metric) error

	// Close the backend connection
	Close() error

	// Name returns the backend name for logging
	Name() string
}

MetricsBackend defines the interface for metrics storage/export

type MetricsCollector

type MetricsCollector interface {
	// Counters
	IncrementCounter(name string, tags map[string]string)
	IncrementCounterBy(name string, value int64, tags map[string]string)

	// Gauges
	SetGauge(name string, value float64, tags map[string]string)

	// Histograms/Timing
	RecordTiming(name string, duration time.Duration, tags map[string]string)
	RecordValue(name string, value float64, tags map[string]string)

	// Flush any buffered metrics
	Flush() error
}

MetricsCollector defines the interface for collecting and reporting metrics

type MetricsObservabilityHook

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

MetricsObservabilityHook collects metrics for operations

func NewMetricsObservabilityHook

func NewMetricsObservabilityHook(collector MetricsCollector) *MetricsObservabilityHook

NewMetricsObservabilityHook creates a new metrics observability hook

func (*MetricsObservabilityHook) OnError

func (m *MetricsObservabilityHook) OnError(ctx context.Context, operation string, err error, metadata map[string]any)

func (*MetricsObservabilityHook) OnKeyOperation

func (m *MetricsObservabilityHook) OnKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)

func (*MetricsObservabilityHook) OnProcessComplete

func (m *MetricsObservabilityHook) OnProcessComplete(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

func (*MetricsObservabilityHook) OnProcessStart

func (m *MetricsObservabilityHook) OnProcessStart(ctx context.Context, operation string, metadata map[string]any)

type NoOpMetricsCollector

type NoOpMetricsCollector struct{}

NoOpMetricsCollector is a no-op implementation of MetricsCollector

func (*NoOpMetricsCollector) Flush

func (n *NoOpMetricsCollector) Flush() error

func (*NoOpMetricsCollector) IncrementCounter

func (n *NoOpMetricsCollector) IncrementCounter(name string, tags map[string]string)

func (*NoOpMetricsCollector) IncrementCounterBy

func (n *NoOpMetricsCollector) IncrementCounterBy(name string, value int64, tags map[string]string)

func (*NoOpMetricsCollector) RecordTiming

func (n *NoOpMetricsCollector) RecordTiming(name string, duration time.Duration, tags map[string]string)

func (*NoOpMetricsCollector) RecordValue

func (n *NoOpMetricsCollector) RecordValue(name string, value float64, tags map[string]string)

func (*NoOpMetricsCollector) SetGauge

func (n *NoOpMetricsCollector) SetGauge(name string, value float64, tags map[string]string)

type NoOpObservabilityHook

type NoOpObservabilityHook struct{}

NoOpObservabilityHook is a no-op implementation of ObservabilityHook

func (*NoOpObservabilityHook) OnError

func (n *NoOpObservabilityHook) OnError(ctx context.Context, operation string, err error, metadata map[string]any)

func (*NoOpObservabilityHook) OnKeyOperation

func (n *NoOpObservabilityHook) OnKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)

func (*NoOpObservabilityHook) OnProcessComplete

func (n *NoOpObservabilityHook) OnProcessComplete(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

func (*NoOpObservabilityHook) OnProcessStart

func (n *NoOpObservabilityHook) OnProcessStart(ctx context.Context, operation string, metadata map[string]any)

type ObservabilityHook

type ObservabilityHook interface {
	// Called before processing starts
	OnProcessStart(ctx context.Context, operation string, metadata map[string]any)

	// Called after processing completes (success or failure)
	OnProcessComplete(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

	// Called when errors occur
	OnError(ctx context.Context, operation string, err error, metadata map[string]any)

	// Called for key operations
	OnKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)
}

ObservabilityHook defines hooks for monitoring encryption operations

type PrometheusMetricsBackend

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

PrometheusMetricsBackend exports metrics in Prometheus format

func NewPrometheusMetricsBackend

func NewPrometheusMetricsBackend(endpoint string) *PrometheusMetricsBackend

NewPrometheusMetricsBackend creates a new Prometheus backend

func (*PrometheusMetricsBackend) Close

func (p *PrometheusMetricsBackend) Close() error

func (*PrometheusMetricsBackend) Export

func (p *PrometheusMetricsBackend) Export(ctx context.Context, metrics []Metric) error

func (*PrometheusMetricsBackend) Name

func (p *PrometheusMetricsBackend) Name() string

type StandardLogger

type StandardLogger struct{}

StandardLogger wraps the standard log package

func (*StandardLogger) Debug

func (s *StandardLogger) Debug(msg string, args ...any)

func (*StandardLogger) Error

func (s *StandardLogger) Error(msg string, args ...any)

func (*StandardLogger) Info

func (s *StandardLogger) Info(msg string, args ...any)

type StatsDMetricsBackend

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

StatsD backend for metrics

func NewStatsDMetricsBackend

func NewStatsDMetricsBackend(endpoint string) *StatsDMetricsBackend

func (*StatsDMetricsBackend) Close

func (s *StatsDMetricsBackend) Close() error

func (*StatsDMetricsBackend) Export

func (s *StatsDMetricsBackend) Export(ctx context.Context, metrics []Metric) error

func (*StatsDMetricsBackend) Name

func (s *StatsDMetricsBackend) Name() string

type StructuredLogger

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

StructuredLogger provides enhanced logging capabilities for production use

func NewDevelopmentLogger

func NewDevelopmentLogger(component string) *StructuredLogger

DevelopmentLogger creates a logger optimized for development

func NewProductionLogger

func NewProductionLogger(component string) *StructuredLogger

ProductionLogger creates a logger optimized for production use

func NewStructuredLogger

func NewStructuredLogger(config LoggerConfig) *StructuredLogger

NewStructuredLogger creates a new structured logger with the given configuration

func (*StructuredLogger) Debug

func (l *StructuredLogger) Debug(msg string, args ...any)

Debug logs a debug level message

func (*StructuredLogger) Error

func (l *StructuredLogger) Error(msg string, args ...any)

Error logs an error level message

func (*StructuredLogger) Fatal

func (l *StructuredLogger) Fatal(msg string, args ...any)

Fatal logs a fatal level message and exits

func (*StructuredLogger) Info

func (l *StructuredLogger) Info(msg string, args ...any)

Info logs an info level message

func (*StructuredLogger) LogCryptoOperation

func (l *StructuredLogger) LogCryptoOperation(ctx context.Context, operation string, duration time.Duration, err error, metadata map[string]any)

LogCryptoOperation logs a crypto operation with standard fields

func (*StructuredLogger) LogKeyOperation

func (l *StructuredLogger) LogKeyOperation(ctx context.Context, operation string, keyAlias string, keyVersion int, metadata map[string]any)

LogKeyOperation logs a key management operation

func (*StructuredLogger) LogSecurityEvent

func (l *StructuredLogger) LogSecurityEvent(ctx context.Context, event string, severity string, metadata map[string]any)

LogSecurityEvent logs a security-related event

func (*StructuredLogger) Warn

func (l *StructuredLogger) Warn(msg string, args ...any)

Warn logs a warning level message

func (*StructuredLogger) WithContext

func (l *StructuredLogger) WithContext(ctx context.Context) *StructuredLogger

WithContext returns a new logger with context information

func (*StructuredLogger) WithFields

func (l *StructuredLogger) WithFields(fields map[string]any) *StructuredLogger

WithFields returns a new logger with additional fields

Jump to

Keyboard shortcuts

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