Documentation
¶
Overview ¶
Package metrics provides comprehensive metrics collection and instrumentation for the observability plugin itself. It tracks internal performance metrics, request patterns, cache efficiency, and operational statistics to enable self-monitoring and performance optimization of the plugin components.
Package metrics provides internal monitoring capabilities for the observability plugin itself
Index ¶
- type Collector
- type ComponentError
- type ComponentState
- type ConnectionFailure
- type InstrumentedClient
- func (ic *InstrumentedClient) BatchQuery(ctx context.Context, queries map[string]string, queryTime time.Time) (map[string]*prometheus.QueryResult, error)
- func (ic *InstrumentedClient) Labels(ctx context.Context) ([]string, error)
- func (ic *InstrumentedClient) Query(ctx context.Context, query string, queryTime time.Time) (*prometheus.QueryResult, error)
- func (ic *InstrumentedClient) QueryRange(ctx context.Context, query string, startTime, endTime time.Time, ...) (*prometheus.QueryResult, error)
- func (ic *InstrumentedClient) Series(ctx context.Context, matches []string, startTime, endTime time.Time) ([]map[string]string, error)
- func (ic *InstrumentedClient) TestConnection(ctx context.Context) error
- type LatencyTracker
- type MetricsExporter
- type PluginMetrics
- func (pm *PluginMetrics) GetAllStats() map[string]interface{}
- func (pm *PluginMetrics) GetComponentStats() map[string]interface{}
- func (pm *PluginMetrics) GetConnectionStats() map[string]interface{}
- func (pm *PluginMetrics) GetHealthStats() map[string]interface{}
- func (pm *PluginMetrics) GetPerformanceStats() map[string]interface{}
- func (pm *PluginMetrics) GetQueryStats() map[string]interface{}
- func (pm *PluginMetrics) GetResourceStats() map[string]interface{}
- func (pm *PluginMetrics) GetUptime() time.Duration
- func (pm *PluginMetrics) RecordAlert()
- func (pm *PluginMetrics) RecordBatchQuery()
- func (pm *PluginMetrics) RecordComponentError(component string, err error, severity string)
- func (pm *PluginMetrics) RecordComponentRestart(component string)
- func (pm *PluginMetrics) RecordConnection(latency time.Duration)
- func (pm *PluginMetrics) RecordConnectionFailure(err error, duration time.Duration)
- func (pm *PluginMetrics) RecordDataCollectionCycle()
- func (pm *PluginMetrics) RecordEvent()
- func (pm *PluginMetrics) RecordNotification()
- func (pm *PluginMetrics) RecordQuery(latency time.Duration, success bool)
- func (pm *PluginMetrics) RecordStreamingQuery()
- func (pm *PluginMetrics) Stop()
- func (pm *PluginMetrics) UpdateCacheHitRate(hitRate float64)
- func (pm *PluginMetrics) UpdateComponentStatus(component string, status string, details string)
- func (pm *PluginMetrics) UpdateHealthScore(score float64)
- func (pm *PluginMetrics) UpdateOverlayCount(count int32)
- func (pm *PluginMetrics) UpdateResourceUsage(memoryBytes int64, cpuPercent float64, goroutines int32)
- func (pm *PluginMetrics) UpdateSubscriptionCount(count int32)
- type RateTracker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector integrates plugin metrics with the Prometheus client
func NewCollector ¶
func NewCollector(ctx context.Context, client prometheus.PrometheusClientInterface) *Collector
NewCollector creates a new metrics collector
func (*Collector) GetMetrics ¶
func (c *Collector) GetMetrics() *PluginMetrics
GetMetrics returns the plugin metrics instance
func (*Collector) WrapClient ¶
func (c *Collector) WrapClient(client prometheus.PrometheusClientInterface) prometheus.PrometheusClientInterface
WrapClient wraps a Prometheus client to automatically collect metrics
type ComponentError ¶
type ComponentError struct {
Error string
Timestamp time.Time
Severity string // low, medium, high, critical
}
ComponentError represents an error in a component
type ComponentState ¶
type ComponentState struct {
Status string // running, stopped, error, initializing
LastUpdated time.Time
Details string // Additional status details
}
ComponentState represents the state of a plugin component
type ConnectionFailure ¶
ConnectionFailure represents a failed connection attempt
type InstrumentedClient ¶
type InstrumentedClient struct {
// contains filtered or unexported fields
}
InstrumentedClient wraps a Prometheus client with metrics collection
func (*InstrumentedClient) BatchQuery ¶
func (ic *InstrumentedClient) BatchQuery(ctx context.Context, queries map[string]string, queryTime time.Time) (map[string]*prometheus.QueryResult, error)
BatchQuery implements PrometheusClientInterface
func (*InstrumentedClient) Labels ¶
func (ic *InstrumentedClient) Labels(ctx context.Context) ([]string, error)
Labels implements PrometheusClientInterface
func (*InstrumentedClient) Query ¶
func (ic *InstrumentedClient) Query(ctx context.Context, query string, queryTime time.Time) (*prometheus.QueryResult, error)
Query implements PrometheusClientInterface
func (*InstrumentedClient) QueryRange ¶
func (ic *InstrumentedClient) QueryRange(ctx context.Context, query string, startTime, endTime time.Time, step time.Duration) (*prometheus.QueryResult, error)
QueryRange implements PrometheusClientInterface
func (*InstrumentedClient) Series ¶
func (ic *InstrumentedClient) Series(ctx context.Context, matches []string, startTime, endTime time.Time) ([]map[string]string, error)
Series implements PrometheusClientInterface
func (*InstrumentedClient) TestConnection ¶
func (ic *InstrumentedClient) TestConnection(ctx context.Context) error
TestConnection implements PrometheusClientInterface
type LatencyTracker ¶
type LatencyTracker struct {
// contains filtered or unexported fields
}
LatencyTracker tracks latency statistics
func NewLatencyTracker ¶
func NewLatencyTracker(maxSamples int) *LatencyTracker
NewLatencyTracker creates a new latency tracker
func (*LatencyTracker) Average ¶
func (lt *LatencyTracker) Average() time.Duration
Average returns the average latency
func (*LatencyTracker) Percentile ¶
func (lt *LatencyTracker) Percentile(percentile float64) time.Duration
Percentile returns the specified percentile
func (*LatencyTracker) Record ¶
func (lt *LatencyTracker) Record(duration time.Duration)
Record records a latency sample
type MetricsExporter ¶
type MetricsExporter struct {
// contains filtered or unexported fields
}
MetricsExporter provides methods to export metrics in various formats
func NewMetricsExporter ¶
func NewMetricsExporter(metrics *PluginMetrics) *MetricsExporter
NewMetricsExporter creates a new metrics exporter
func (*MetricsExporter) ExportPrometheusFormat ¶
func (me *MetricsExporter) ExportPrometheusFormat() string
ExportPrometheusFormat exports metrics in Prometheus exposition format
type PluginMetrics ¶
type PluginMetrics struct {
// Connection metrics
PrometheusConnections int64 // Total Prometheus connections made
FailedConnections int64 // Failed Prometheus connections
ConnectionLatency *LatencyTracker // Connection latency tracking
LastConnectionTime time.Time // Last successful connection time
ConnectionFailures []ConnectionFailure // Recent connection failures
// Query metrics
QueryCount int64 // Total queries executed
QueryFailures int64 // Failed queries
QueryLatency *LatencyTracker // Query latency tracking
CacheHitRate float64 // Cache hit rate percentage
BatchQueryCount int64 // Batch queries executed
StreamingQueryCount int64 // Streaming queries executed
// Component metrics
ComponentStatus map[string]ComponentState // Status of each component
ComponentRestarts map[string]int64 // Restart count per component
ComponentLastError map[string]ComponentError // Last error per component
// Resource metrics
MemoryUsage int64 // Current memory usage in bytes
CPUUsage float64 // Current CPU usage percentage
GoroutineCount int32 // Active goroutines
SubscriptionCount int32 // Active subscriptions
OverlayCount int32 // Active overlays
// Performance metrics
EventProcessingRate *RateTracker // Events processed per second
NotificationsSent int64 // Total notifications sent
AlertsTriggered int64 // Alerts triggered
DataCollectionCycles int64 // Data collection cycles completed
// Health metrics
UptimeStart time.Time // Plugin start time
LastHealthCheck time.Time // Last health check time
HealthScore float64 // Overall health score (0-100)
// contains filtered or unexported fields
}
PluginMetrics tracks internal metrics for the observability plugin
func NewPluginMetrics ¶
func NewPluginMetrics(ctx context.Context) *PluginMetrics
NewPluginMetrics creates a new plugin metrics instance
func (*PluginMetrics) GetAllStats ¶
func (pm *PluginMetrics) GetAllStats() map[string]interface{}
GetAllStats returns all statistics
func (*PluginMetrics) GetComponentStats ¶
func (pm *PluginMetrics) GetComponentStats() map[string]interface{}
GetComponentStats returns component statistics
func (*PluginMetrics) GetConnectionStats ¶
func (pm *PluginMetrics) GetConnectionStats() map[string]interface{}
GetConnectionStats returns connection statistics
func (*PluginMetrics) GetHealthStats ¶
func (pm *PluginMetrics) GetHealthStats() map[string]interface{}
GetHealthStats returns health statistics
func (*PluginMetrics) GetPerformanceStats ¶
func (pm *PluginMetrics) GetPerformanceStats() map[string]interface{}
GetPerformanceStats returns performance statistics
func (*PluginMetrics) GetQueryStats ¶
func (pm *PluginMetrics) GetQueryStats() map[string]interface{}
GetQueryStats returns query statistics
func (*PluginMetrics) GetResourceStats ¶
func (pm *PluginMetrics) GetResourceStats() map[string]interface{}
GetResourceStats returns resource statistics
func (*PluginMetrics) GetUptime ¶
func (pm *PluginMetrics) GetUptime() time.Duration
GetUptime returns the plugin uptime
func (*PluginMetrics) RecordAlert ¶
func (pm *PluginMetrics) RecordAlert()
RecordAlert records a triggered alert
func (*PluginMetrics) RecordBatchQuery ¶
func (pm *PluginMetrics) RecordBatchQuery()
RecordBatchQuery records a batch query execution
func (*PluginMetrics) RecordComponentError ¶
func (pm *PluginMetrics) RecordComponentError(component string, err error, severity string)
RecordComponentError records a component error
func (*PluginMetrics) RecordComponentRestart ¶
func (pm *PluginMetrics) RecordComponentRestart(component string)
RecordComponentRestart records a component restart
func (*PluginMetrics) RecordConnection ¶
func (pm *PluginMetrics) RecordConnection(latency time.Duration)
RecordConnection records a successful connection
func (*PluginMetrics) RecordConnectionFailure ¶
func (pm *PluginMetrics) RecordConnectionFailure(err error, duration time.Duration)
RecordConnectionFailure records a failed connection
func (*PluginMetrics) RecordDataCollectionCycle ¶
func (pm *PluginMetrics) RecordDataCollectionCycle()
RecordDataCollectionCycle records a completed data collection cycle
func (*PluginMetrics) RecordEvent ¶
func (pm *PluginMetrics) RecordEvent()
RecordEvent records an event for rate tracking
func (*PluginMetrics) RecordNotification ¶
func (pm *PluginMetrics) RecordNotification()
RecordNotification records a sent notification
func (*PluginMetrics) RecordQuery ¶
func (pm *PluginMetrics) RecordQuery(latency time.Duration, success bool)
RecordQuery records a query execution
func (*PluginMetrics) RecordStreamingQuery ¶
func (pm *PluginMetrics) RecordStreamingQuery()
RecordStreamingQuery records a streaming query execution
func (*PluginMetrics) UpdateCacheHitRate ¶
func (pm *PluginMetrics) UpdateCacheHitRate(hitRate float64)
UpdateCacheHitRate updates the cache hit rate
func (*PluginMetrics) UpdateComponentStatus ¶
func (pm *PluginMetrics) UpdateComponentStatus(component string, status string, details string)
UpdateComponentStatus updates the status of a component
func (*PluginMetrics) UpdateHealthScore ¶
func (pm *PluginMetrics) UpdateHealthScore(score float64)
UpdateHealthScore updates the overall health score
func (*PluginMetrics) UpdateOverlayCount ¶
func (pm *PluginMetrics) UpdateOverlayCount(count int32)
UpdateOverlayCount updates the active overlay count
func (*PluginMetrics) UpdateResourceUsage ¶
func (pm *PluginMetrics) UpdateResourceUsage(memoryBytes int64, cpuPercent float64, goroutines int32)
UpdateResourceUsage updates resource usage metrics
func (*PluginMetrics) UpdateSubscriptionCount ¶
func (pm *PluginMetrics) UpdateSubscriptionCount(count int32)
UpdateSubscriptionCount updates the active subscription count
type RateTracker ¶
type RateTracker struct {
// contains filtered or unexported fields
}
RateTracker tracks rate statistics (events per second)
func NewRateTracker ¶
func NewRateTracker(windowSize time.Duration) *RateTracker
NewRateTracker creates a new rate tracker
func (*RateTracker) Rate ¶
func (rt *RateTracker) Rate() float64
Rate returns the current rate (events per second)
func (*RateTracker) Record ¶
func (rt *RateTracker) Record(timestamp time.Time)
Record records an event