Documentation
¶
Index ¶
- Constants
- type AggregatedMetrics
- type Collector
- func (c *Collector) CircuitBreakerTripped(extensionName string)
- func (c *Collector) CleanupOldMetrics(maxAge time.Duration) error
- func (c *Collector) EventPublished(extensionName string, eventType string)
- func (c *Collector) EventReceived(extensionName string, eventType string)
- func (c *Collector) ExtensionInitialized(name string, duration time.Duration, err error)
- func (c *Collector) ExtensionLoaded(name string, duration time.Duration)
- func (c *Collector) ExtensionUnloaded(name string)
- func (c *Collector) GetAllExtensionMetrics() map[string]*ExtensionMetrics
- func (c *Collector) GetExtensionMetrics(name string) *ExtensionMetrics
- func (c *Collector) GetLatest(extensionName string, limit int) ([]*Snapshot, error)
- func (c *Collector) GetStorageStats() map[string]any
- func (c *Collector) GetSystemMetrics() SystemMetrics
- func (c *Collector) IsEnabled() bool
- func (c *Collector) Query(opts *QueryOptions) ([]*AggregatedMetrics, error)
- func (c *Collector) ServiceCall(extensionName string, success bool)
- func (c *Collector) SetEnabled(enabled bool)
- func (c *Collector) Stop()
- func (c *Collector) UpdateServiceDiscoveryMetrics(registered int, hits, misses int64)
- func (c *Collector) UpdateSystemMetrics()
- func (c *Collector) UpgradeToRedisStorage(client any, keyPrefix string, retention time.Duration) error
- type ExtensionMetrics
- type HealthStatus
- type MemoryStorage
- func (m *MemoryStorage) Cleanup(before time.Time) error
- func (m *MemoryStorage) GetLatest(extensionName string, limit int) ([]*Snapshot, error)
- func (m *MemoryStorage) GetStats() map[string]any
- func (m *MemoryStorage) Query(opts *QueryOptions) ([]*AggregatedMetrics, error)
- func (m *MemoryStorage) Store(snapshot *Snapshot) error
- func (m *MemoryStorage) StoreBatch(snapshots []*Snapshot) error
- type MetricError
- type QueryOptions
- type RedisStorage
- func (r *RedisStorage) Cleanup(before time.Time) error
- func (r *RedisStorage) GetLatest(extensionName string, limit int) ([]*Snapshot, error)
- func (r *RedisStorage) GetStats() map[string]any
- func (r *RedisStorage) Query(opts *QueryOptions) ([]*AggregatedMetrics, error)
- func (r *RedisStorage) Store(snapshot *Snapshot) error
- func (r *RedisStorage) StoreBatch(snapshots []*Snapshot) error
- type Snapshot
- type Storage
- type StorageStats
- type SystemMetrics
- type TimeSeriesPoint
Constants ¶
const ( AggregationRaw = "raw" AggregationSum = "sum" AggregationAvg = "avg" AggregationMax = "max" AggregationMin = "min" AggregationCount = "count" )
Constants for aggregation types
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregatedMetrics ¶ added in v0.1.5
type AggregatedMetrics struct { ExtensionName string `json:"extension_name"` MetricType string `json:"metric_type"` Values []TimeSeriesPoint `json:"values"` Aggregation string `json:"aggregation"` // "sum", "avg", "max", "min", "count", "raw" }
AggregatedMetrics represents query results with aggregation
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector manages extension metrics collection with storage
func NewCollector ¶
func NewCollector(cfg *config.MetricsConfig) *Collector
NewCollector creates a new metrics collector from extension config
func (*Collector) CircuitBreakerTripped ¶ added in v0.1.5
func (*Collector) CleanupOldMetrics ¶ added in v0.1.5
CleanupOldMetrics removes metrics older than the specified duration
func (*Collector) EventPublished ¶ added in v0.1.5
func (*Collector) EventReceived ¶ added in v0.1.5
func (*Collector) ExtensionInitialized ¶ added in v0.1.5
func (*Collector) ExtensionLoaded ¶ added in v0.1.5
func (*Collector) ExtensionUnloaded ¶ added in v0.1.5
func (*Collector) GetAllExtensionMetrics ¶ added in v0.1.5
func (c *Collector) GetAllExtensionMetrics() map[string]*ExtensionMetrics
func (*Collector) GetExtensionMetrics ¶ added in v0.1.5
func (c *Collector) GetExtensionMetrics(name string) *ExtensionMetrics
func (*Collector) GetStorageStats ¶ added in v0.1.5
func (*Collector) GetSystemMetrics ¶ added in v0.1.5
func (c *Collector) GetSystemMetrics() SystemMetrics
func (*Collector) IsEnabled ¶ added in v0.1.5
IsEnabled returns whether metrics collection is enabled
func (*Collector) Query ¶
func (c *Collector) Query(opts *QueryOptions) ([]*AggregatedMetrics, error)
func (*Collector) ServiceCall ¶ added in v0.1.5
func (*Collector) SetEnabled ¶
SetEnabled enables or disables metrics collection
func (*Collector) Stop ¶ added in v0.1.5
func (c *Collector) Stop()
Stop gracefully stops the collector
func (*Collector) UpdateServiceDiscoveryMetrics ¶ added in v0.1.5
func (*Collector) UpdateSystemMetrics ¶ added in v0.1.5
func (c *Collector) UpdateSystemMetrics()
type ExtensionMetrics ¶ added in v0.1.5
type ExtensionMetrics struct { Name string `json:"name"` LoadTime int64 `json:"load_time_ms"` // Load time in milliseconds InitTime int64 `json:"init_time_ms"` // Init time in milliseconds LoadedAt time.Time `json:"loaded_at"` // When extension was loaded InitializedAt time.Time `json:"initialized_at"` // When extension was initialized Status string `json:"status"` // "loading", "active", "failed", "stopped" // Atomic counters for concurrent access (use atomic.Int64 internally but convert for JSON) ServiceCalls int64 `json:"service_calls"` ServiceErrors int64 `json:"service_errors"` EventsPublished int64 `json:"events_published"` EventsReceived int64 `json:"events_received"` CircuitBreakerTrips int64 `json:"circuit_breaker_trips"` // contains filtered or unexported fields }
ExtensionMetrics tracks real-time metrics for a single extension
type HealthStatus ¶ added in v0.1.5
type HealthStatus struct { Enabled bool `json:"enabled"` StorageType string `json:"storage_type"` StorageHealth string `json:"storage_health"` // "healthy", "degraded", "unhealthy" LastError *MetricError `json:"last_error,omitempty"` Stats map[string]any `json:"stats"` Extensions map[string]string `json:"extensions"` // extension_name -> status }
HealthStatus represents the health status of the metrics system
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage stores metrics in memory with thread safety
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage creates a new memory storage
func (*MemoryStorage) Cleanup ¶
func (m *MemoryStorage) Cleanup(before time.Time) error
Cleanup removes old metrics before the specified time
func (*MemoryStorage) GetLatest ¶ added in v0.1.5
func (m *MemoryStorage) GetLatest(extensionName string, limit int) ([]*Snapshot, error)
GetLatest retrieves latest metrics for an extension
func (*MemoryStorage) GetStats ¶
func (m *MemoryStorage) GetStats() map[string]any
GetStats returns storage statistics
func (*MemoryStorage) Query ¶
func (m *MemoryStorage) Query(opts *QueryOptions) ([]*AggregatedMetrics, error)
Query historical metrics with proper filtering and aggregation
func (*MemoryStorage) Store ¶
func (m *MemoryStorage) Store(snapshot *Snapshot) error
Store single metric snapshot
func (*MemoryStorage) StoreBatch ¶ added in v0.1.5
func (m *MemoryStorage) StoreBatch(snapshots []*Snapshot) error
StoreBatch stores multiple snapshots efficiently
type MetricError ¶ added in v0.1.5
type MetricError struct { Operation string `json:"operation"` // "store", "query", "cleanup", etc. Message string `json:"message"` Timestamp time.Time `json:"timestamp"` Err error `json:"-"` // Original error (not serialized) }
MetricError represents an error that occurred during metric operations
func NewMetricError ¶ added in v0.1.5
func NewMetricError(operation, message string, err error) *MetricError
NewMetricError creates a new metric error
func (*MetricError) Error ¶ added in v0.1.5
func (e *MetricError) Error() string
func (*MetricError) Unwrap ¶ added in v0.1.5
func (e *MetricError) Unwrap() error
type QueryOptions ¶ added in v0.1.5
type QueryOptions struct { ExtensionName string `json:"extension_name,omitempty"` MetricType string `json:"metric_type,omitempty"` Labels map[string]string `json:"labels,omitempty"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` Aggregation string `json:"aggregation"` // "sum", "avg", "max", "min", "count", "raw" Interval time.Duration `json:"interval"` // aggregation interval (0 = no interval aggregation) Limit int `json:"limit"` // maximum number of results }
QueryOptions specifies parameters for historical metric queries
func (*QueryOptions) Validate ¶ added in v0.1.5
func (q *QueryOptions) Validate() error
Validate checks if QueryOptions are valid
type RedisStorage ¶
type RedisStorage struct {
// contains filtered or unexported fields
}
RedisStorage stores metrics in Redis with time series support
func NewRedisStorage ¶
func NewRedisStorage(client *redis.Client, keyPrefix string, retention time.Duration) *RedisStorage
NewRedisStorage creates a new Redis storage
func (*RedisStorage) Cleanup ¶
func (r *RedisStorage) Cleanup(before time.Time) error
Cleanup removes old metrics
func (*RedisStorage) GetLatest ¶ added in v0.1.5
func (r *RedisStorage) GetLatest(extensionName string, limit int) ([]*Snapshot, error)
GetLatest retrieves latest metrics for an extension with proper sorting
func (*RedisStorage) GetStats ¶
func (r *RedisStorage) GetStats() map[string]any
GetStats retrieves comprehensive storage statistics
func (*RedisStorage) Query ¶
func (r *RedisStorage) Query(opts *QueryOptions) ([]*AggregatedMetrics, error)
Query historical metrics with proper filtering and aggregation
func (*RedisStorage) Store ¶
func (r *RedisStorage) Store(snapshot *Snapshot) error
Store single metric snapshot
func (*RedisStorage) StoreBatch ¶ added in v0.1.5
func (r *RedisStorage) StoreBatch(snapshots []*Snapshot) error
StoreBatch stores multiple snapshots efficiently
type Snapshot ¶ added in v0.1.5
type Snapshot struct { ExtensionName string `json:"extension_name"` MetricType string `json:"metric_type"` Value int64 `json:"value"` Labels map[string]string `json:"labels,omitempty"` Timestamp time.Time `json:"timestamp"` }
Snapshot represents a point-in-time metric measurement
type Storage ¶
type Storage interface { // Store single metric snapshot Store(snapshot *Snapshot) error // StoreBatch stores multiple snapshots efficiently StoreBatch(snapshots []*Snapshot) error // Query historical metrics with aggregation and filtering Query(opts *QueryOptions) ([]*AggregatedMetrics, error) // GetLatest retrieves latest metrics for an extension GetLatest(extensionName string, limit int) ([]*Snapshot, error) // Cleanup removes old metrics before the specified time Cleanup(before time.Time) error // GetStats returns storage statistics and health information GetStats() map[string]any }
Storage interface for metrics persistence
type StorageStats ¶ added in v0.1.5
type StorageStats struct { Type string `json:"type"` // "memory", "redis", etc. Total int64 `json:"total"` // Total number of stored snapshots Keys int `json:"keys"` // Number of storage keys MemoryMB float64 `json:"memory_mb"` // Memory usage in MB Retention string `json:"retention"` // Retention policy LastCleanup *time.Time `json:"last_cleanup,omitempty"` // Last cleanup time Errors int64 `json:"errors"` // Number of storage errors }
StorageStats represents common storage statistics
type SystemMetrics ¶ added in v0.1.5
type SystemMetrics struct { StartTime time.Time `json:"start_time"` MemoryUsageMB int64 `json:"memory_usage_mb"` GoroutineCount int `json:"goroutine_count"` GCCycles uint32 `json:"gc_cycles"` ServicesRegistered int `json:"services_registered"` ServiceCacheHits int64 `json:"service_cache_hits"` ServiceCacheMisses int64 `json:"service_cache_misses"` }
SystemMetrics tracks system-wide metrics
type TimeSeriesPoint ¶ added in v0.1.5
TimeSeriesPoint represents a single point in time series