analytics

package
v1.0.63 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregateQuery

type AggregateQuery struct {
	AggregateType AggregateType `json:"aggregate_type"`
	GroupBy       []string      `json:"group_by"`
	MetricQuery
	Interval time.Duration `json:"interval"`
}

type AggregateType

type AggregateType string

Enums and constants

const (
	AggregateTypeSum   AggregateType = "sum"
	AggregateTypeAvg   AggregateType = "avg"
	AggregateTypeMin   AggregateType = "min"
	AggregateTypeMax   AggregateType = "max"
	AggregateTypeCount AggregateType = "count"
	AggregateTypeP50   AggregateType = "p50"
	AggregateTypeP90   AggregateType = "p90"
	AggregateTypeP95   AggregateType = "p95"
	AggregateTypeP99   AggregateType = "p99"
)

type AggregatedMetric

type AggregatedMetric struct {
	Timestamp time.Time         `json:"timestamp"`
	Tags      map[string]string `json:"tags"`
	Name      string            `json:"name"`
	Value     float64           `json:"value"`
}

type AlertAction

type AlertAction struct {
	Parameters  map[string]any `json:"parameters"`
	Type        string         `json:"type"`
	Description string         `json:"description"`
	Target      string         `json:"target"`
	Automated   bool           `json:"automated"`
}

type AlertContext

type AlertContext struct {
	SystemContext   map[string]any `json:"system_context"`
	UserContext     map[string]any `json:"user_context"`
	BusinessContext map[string]any `json:"business_context"`
	TriggerMetric   string         `json:"trigger_metric"`
	RelatedMetrics  []string       `json:"related_metrics"`
}

type AlertManager

type AlertManager interface {
	SendAlert(ctx context.Context, alert PerformanceAlert) error
	GetActiveAlerts() []PerformanceAlert
	AcknowledgeAlert(alertID string) error
	SuppressAlert(alertID string, duration time.Duration) error
}

type AlertPriority

type AlertPriority string
const (
	AlertPriorityLow    AlertPriority = "low"
	AlertPriorityMedium AlertPriority = "medium"
	AlertPriorityHigh   AlertPriority = "high"
	AlertPriorityUrgent AlertPriority = "urgent"
)

type AlertSeverity

type AlertSeverity string
const (
	AlertSeverityInfo     AlertSeverity = "info"
	AlertSeverityWarning  AlertSeverity = "warning"
	AlertSeverityError    AlertSeverity = "error"
	AlertSeverityCritical AlertSeverity = "critical"
)

type AlertTriggerType

type AlertTriggerType string
const (
	AlertTriggerThreshold AlertTriggerType = "threshold"
	AlertTriggerAnomaly   AlertTriggerType = "anomaly"
	AlertTriggerTrend     AlertTriggerType = "trend"
	AlertTriggerForecast  AlertTriggerType = "forecast"
)

type AnalyticsDataStore

type AnalyticsDataStore interface {
	StoreMetric(ctx context.Context, metric *PerformanceMetric) error
	GetMetrics(ctx context.Context, query MetricQuery) ([]PerformanceMetric, error)
	GetAggregatedMetrics(ctx context.Context, query AggregateQuery) ([]AggregatedMetric, error)
	DeleteOldMetrics(ctx context.Context, before time.Time) error
	GetMetricNames() []string
}

Supporting types and interfaces

type AnomalyContext

type AnomalyContext struct {
	SystemState      map[string]any    `json:"system_state"`
	PrecedingTrend   string            `json:"preceding_trend"`
	ConcurrentEvents []ConcurrentEvent `json:"concurrent_events"`
	RelatedMetrics   []RelatedMetric   `json:"related_metrics"`
}

type AnomalyDetector

type AnomalyDetector interface {
	DetectAnomalies(ctx context.Context, metrics []PerformanceMetric) ([]PerformanceAnomaly, error)
	TrainModel(ctx context.Context, historicalData []PerformanceMetric) error
	UpdateBaseline(ctx context.Context, metrics []PerformanceMetric) error
	GetDetectionSensitivity() float64
	SetDetectionSensitivity(sensitivity float64)
}

type AnomalyImpact

type AnomalyImpact struct {
	UserExperience  ImpactLevel `json:"user_experience"`
	SystemStability ImpactLevel `json:"system_stability"`
	BusinessMetrics ImpactLevel `json:"business_metrics"`
	OperationalCost ImpactLevel `json:"operational_cost"`
	SecurityRisk    ImpactLevel `json:"security_risk"`
	ComplianceRisk  ImpactLevel `json:"compliance_risk"`
}

type AnomalySeverity

type AnomalySeverity string
const (
	AnomalySeverityLow      AnomalySeverity = "low"
	AnomalySeverityMedium   AnomalySeverity = "medium"
	AnomalySeverityHigh     AnomalySeverity = "high"
	AnomalySeverityCritical AnomalySeverity = "critical"
)

type AnomalyType

type AnomalyType string
const (
	AnomalyTypeSpike    AnomalyType = "spike"
	AnomalyTypeDip      AnomalyType = "dip"
	AnomalyTypeLevel    AnomalyType = "level_shift"
	AnomalyTypeTrend    AnomalyType = "trend_change"
	AnomalyTypeVariance AnomalyType = "variance_change"
	AnomalyTypeSeasonal AnomalyType = "seasonal_anomaly"
)

type ConcurrentEvent

type ConcurrentEvent struct {
	Timestamp   time.Time `json:"timestamp"`
	Type        string    `json:"type"`
	Description string    `json:"description"`
	Correlation float64   `json:"correlation"`
}

type CorrelationMatrix

type CorrelationMatrix struct {
	CalculatedAt time.Time   `json:"calculated_at"`
	Metrics      []string    `json:"metrics"`
	Correlations [][]float64 `json:"correlations"`
	Significance [][]float64 `json:"significance"`
}

type CostEstimate

type CostEstimate struct {
	Currency  string  `json:"currency"`
	Period    string  `json:"period"`
	Initial   float64 `json:"initial"`
	Recurring float64 `json:"recurring"`
}

type DistributionAnalysis

type DistributionAnalysis struct {
	Type       string  `json:"type"`
	Skewness   float64 `json:"skewness"`
	Kurtosis   float64 `json:"kurtosis"`
	IsNormal   bool    `json:"is_normal"`
	Confidence float64 `json:"confidence"`
}

type EffortLevel

type EffortLevel string
const (
	EffortLevelLow    EffortLevel = "low"
	EffortLevelMedium EffortLevel = "medium"
	EffortLevelHigh   EffortLevel = "high"
)

type ForecastPoint

type ForecastPoint struct {
	Timestamp time.Time `json:"timestamp"`
	Value     float64   `json:"value"`
	Lower     float64   `json:"lower"`
	Upper     float64   `json:"upper"`
}

type ImpactLevel

type ImpactLevel string
const (
	ImpactLevelLow    ImpactLevel = "low"
	ImpactLevelMedium ImpactLevel = "medium"
	ImpactLevelHigh   ImpactLevel = "high"
)

type MetricQuery

type MetricQuery struct {
	TimeRange   TimeRange         `json:"time_range"`
	Tags        map[string]string `json:"tags"`
	MetricNames []string          `json:"metric_names"`
	Limit       int               `json:"limit"`
	Offset      int               `json:"offset"`
}

type OutlierPoint

type OutlierPoint struct {
	Timestamp time.Time `json:"timestamp"`
	Severity  string    `json:"severity"`
	Value     float64   `json:"value"`
	ZScore    float64   `json:"z_score"`
}

type Pattern

type Pattern struct {
	StartTime  time.Time `json:"start_time"`
	EndTime    time.Time `json:"end_time"`
	Name       string    `json:"name"`
	Amplitude  float64   `json:"amplitude"`
	Frequency  float64   `json:"frequency"`
	Confidence float64   `json:"confidence"`
}

type PerformanceAlert

type PerformanceAlert struct {
	Context      AlertContext     `json:"context"`
	Timestamp    time.Time        `json:"timestamp"`
	MetricName   string           `json:"metric_name"`
	Severity     AlertSeverity    `json:"severity"`
	Priority     AlertPriority    `json:"priority"`
	Description  string           `json:"description"`
	ID           string           `json:"id"`
	TriggerType  AlertTriggerType `json:"trigger_type"`
	Title        string           `json:"title"`
	Actions      []AlertAction    `json:"actions"`
	Threshold    Threshold        `json:"threshold"`
	ActualValue  float64          `json:"actual_value"`
	Suppressed   bool             `json:"suppressed"`
	Acknowledged bool             `json:"acknowledged"`
}

PerformanceAlert represents a performance-related alert

type PerformanceAnalysis

type PerformanceAnalysis struct {
	TimeRange       TimeRange                   `json:"time_range"`
	GeneratedAt     time.Time                   `json:"generated_at"`
	ID              string                      `json:"id"`
	Metrics         []PerformanceMetric         `json:"metrics"`
	Trends          []PerformanceTrend          `json:"trends"`
	Anomalies       []PerformanceAnomaly        `json:"anomalies"`
	Predictions     []PerformancePrediction     `json:"predictions"`
	Recommendations []PerformanceRecommendation `json:"recommendations"`
	Alerts          []PerformanceAlert          `json:"alerts"`
	Statistics      PerformanceStatistics       `json:"statistics"`
	Duration        time.Duration               `json:"duration"`
	HealthScore     float64                     `json:"health_score"`
}

PerformanceAnalysis represents the result of performance analysis Memory optimized: 376 → 272 bytes (104 bytes saved)

type PerformanceAnalyticsConfig

type PerformanceAnalyticsConfig struct {
	DataRetentionDays      int           `json:"data_retention_days"`
	AnalysisInterval       time.Duration `json:"analysis_interval"`
	AnomalyDetectionWindow time.Duration `json:"anomaly_detection_window"`
	TrendAnalysisWindow    time.Duration `json:"trend_analysis_window"`
	MetricSamplingRate     float64       `json:"metric_sampling_rate"`
	MaxConcurrentAnalysis  int           `json:"max_concurrent_analysis"`
	Enabled                bool          `json:"enabled"`
	AlertingEnabled        bool          `json:"alerting_enabled"`
	EnablePredictive       bool          `json:"enable_predictive"`
	EnableMachineLearning  bool          `json:"enable_machine_learning"`
}

PerformanceAnalyticsConfig configures the performance analytics engine

type PerformanceAnalyticsEngine

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

PerformanceAnalyticsEngine provides advanced performance analytics

func NewPerformanceAnalyticsEngine

func NewPerformanceAnalyticsEngine(config PerformanceAnalyticsConfig) *PerformanceAnalyticsEngine

NewPerformanceAnalyticsEngine creates a new performance analytics engine

func (*PerformanceAnalyticsEngine) AnalyzePerformance

func (pae *PerformanceAnalyticsEngine) AnalyzePerformance(ctx context.Context, timeRange TimeRange) (*PerformanceAnalysis, error)

AnalyzePerformance performs comprehensive performance analysis

func (*PerformanceAnalyticsEngine) SetAlertManager

func (pae *PerformanceAnalyticsEngine) SetAlertManager(alertMgr AlertManager)

SetAlertManager sets the alert manager

func (*PerformanceAnalyticsEngine) SetAnomalyDetector

func (pae *PerformanceAnalyticsEngine) SetAnomalyDetector(detector AnomalyDetector)

SetAnomalyDetector sets the anomaly detector

func (*PerformanceAnalyticsEngine) SetDataStore

func (pae *PerformanceAnalyticsEngine) SetDataStore(dataStore AnalyticsDataStore)

SetDataStore sets the analytics data store

func (*PerformanceAnalyticsEngine) SetThresholdManager

func (pae *PerformanceAnalyticsEngine) SetThresholdManager(thresholdMgr ThresholdManager)

SetThresholdManager sets the threshold manager

func (*PerformanceAnalyticsEngine) SetTrendAnalyzer

func (pae *PerformanceAnalyticsEngine) SetTrendAnalyzer(analyzer TrendAnalyzer)

SetTrendAnalyzer sets the trend analyzer

func (*PerformanceAnalyticsEngine) Start

Start starts the performance analytics engine

func (*PerformanceAnalyticsEngine) Stop

func (pae *PerformanceAnalyticsEngine) Stop() error

Stop stops the performance analytics engine

type PerformanceAnomaly

type PerformanceAnomaly struct {
	Context         AnomalyContext  `json:"context"`
	Timestamp       time.Time       `json:"timestamp"`
	Impact          AnomalyImpact   `json:"impact"`
	Severity        AnomalySeverity `json:"severity"`
	ID              string          `json:"id"`
	Type            AnomalyType     `json:"type"`
	MetricName      string          `json:"metric_name"`
	Explanation     string          `json:"explanation"`
	Recommendations []string        `json:"recommendations"`
	RelatedMetrics  []string        `json:"related_metrics"`
	ExpectedValue   float64         `json:"expected_value"`
	Deviation       float64         `json:"deviation"`
	Confidence      float64         `json:"confidence"`
	Value           float64         `json:"value"`
}

PerformanceAnomaly represents an anomaly in performance metrics

type PerformanceMetric

type PerformanceMetric struct {
	Timestamp     time.Time         `json:"timestamp"`
	Tags          map[string]string `json:"tags"`
	Dimensions    map[string]string `json:"dimensions"`
	Metadata      map[string]any    `json:"metadata"`
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Unit          string            `json:"unit"`
	Source        string            `json:"source"`
	AggregateType AggregateType     `json:"aggregate_type"`
	Value         float64           `json:"value"`
}

PerformanceMetric represents a performance metric data point

type PerformancePrediction

type PerformancePrediction struct {
	GeneratedAt     time.Time            `json:"generated_at"`
	ID              string               `json:"id"`
	MetricName      string               `json:"metric_name"`
	PredictionType  PredictionType       `json:"prediction_type"`
	Methodology     string               `json:"methodology"`
	Assumptions     []string             `json:"assumptions"`
	RiskFactors     []RiskFactor         `json:"risk_factors"`
	Scenarios       []PredictionScenario `json:"scenarios"`
	PredictionBands PredictionBands      `json:"prediction_bands"`
	TimeHorizon     time.Duration        `json:"time_horizon"`
	PredictedValue  float64              `json:"predicted_value"`
	ConfidenceLevel float64              `json:"confidence_level"`
}

PerformancePrediction represents a prediction of future performance

type PerformanceRecommendation

type PerformanceRecommendation struct {
	Effort      EffortLevel            `json:"effort"`
	Description string                 `json:"description"`
	ID          string                 `json:"id"`
	Title       string                 `json:"title"`
	Priority    Priority               `json:"priority"`
	Category    RecommendationCategory `json:"category"`
	Impact      ImpactLevel            `json:"impact"`
	Benefits    []string               `json:"benefits"`
	Risks       []string               `json:"risks"`
	Metrics     []string               `json:"metrics"`
	Actions     []RecommendedAction    `json:"actions"`
	Cost        CostEstimate           `json:"cost"`
	Timeline    time.Duration          `json:"timeline"`
}

PerformanceRecommendation represents an actionable recommendation Memory optimized: 256 → 232 bytes (24 bytes saved)

type PerformanceStatistics

type PerformanceStatistics struct {
	Percentiles  map[string]float64   `json:"percentiles"`
	Outliers     []OutlierPoint       `json:"outliers"`
	Distribution DistributionAnalysis `json:"distribution"`
	Count        int64                `json:"count"`
	Mean         float64              `json:"mean"`
	Median       float64              `json:"median"`
	Mode         float64              `json:"mode"`
	StdDev       float64              `json:"std_dev"`
	Variance     float64              `json:"variance"`
	Min          float64              `json:"min"`
	Max          float64              `json:"max"`
	Range        float64              `json:"range"`
}

PerformanceStatistics provides statistical analysis of metrics

type PerformanceTrend

type PerformanceTrend struct {
	Forecast    TrendForecast      `json:"forecast"`
	ID          string             `json:"id"`
	MetricName  string             `json:"metric_name"`
	Direction   TrendDirection     `json:"direction"`
	Seasonality SeasonalityPattern `json:"seasonality"`
	Strength    float64            `json:"strength"`
	Confidence  float64            `json:"confidence"`
	Duration    time.Duration      `json:"duration"`
	Slope       float64            `json:"slope"`
	StartValue  float64            `json:"start_value"`
	EndValue    float64            `json:"end_value"`
	ChangeRate  float64            `json:"change_rate"`
}

PerformanceTrend represents a trend in performance metrics

type PredictionBands

type PredictionBands struct {
	Upper95 float64 `json:"upper_95"`
	Upper80 float64 `json:"upper_80"`
	Lower80 float64 `json:"lower_80"`
	Lower95 float64 `json:"lower_95"`
}

type PredictionScenario

type PredictionScenario struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Conditions  []string `json:"conditions"`
	Probability float64  `json:"probability"`
	Value       float64  `json:"value"`
}

type PredictionType

type PredictionType string
const (
	PredictionTypeValue     PredictionType = "value"
	PredictionTypeTrend     PredictionType = "trend"
	PredictionTypeThreshold PredictionType = "threshold"
	PredictionTypeCapacity  PredictionType = "capacity"
)

type Priority

type Priority string
const (
	PriorityLow      Priority = "low"
	PriorityMedium   Priority = "medium"
	PriorityHigh     Priority = "high"
	PriorityCritical Priority = "critical"
)

type RecommendationCategory

type RecommendationCategory string
const (
	RecommendationCategoryPerformance    RecommendationCategory = "performance"
	RecommendationCategoryScaling        RecommendationCategory = "scaling"
	RecommendationCategoryOptimization   RecommendationCategory = "optimization"
	RecommendationCategoryConfiguration  RecommendationCategory = "configuration"
	RecommendationCategoryInfrastructure RecommendationCategory = "infrastructure"
	RecommendationCategorySecurity       RecommendationCategory = "security"
)

type RecommendedAction

type RecommendedAction struct {
	Type        string         `json:"type"`
	Description string         `json:"description"`
	Command     string         `json:"command,omitempty"`
	Parameters  map[string]any `json:"parameters,omitempty"`
	Validation  string         `json:"validation,omitempty"`
	Rollback    string         `json:"rollback,omitempty"`
}

type RelatedMetric

type RelatedMetric struct {
	Name        string  `json:"name"`
	Impact      string  `json:"impact"`
	Value       float64 `json:"value"`
	Correlation float64 `json:"correlation"`
}

type RiskFactor

type RiskFactor struct {
	Name        string  `json:"name"`
	Impact      string  `json:"impact"`
	Mitigation  string  `json:"mitigation"`
	Probability float64 `json:"probability"`
}

type SeasonalityPattern

type SeasonalityPattern struct {
	Patterns   []Pattern     `json:"patterns"`
	Cycle      time.Duration `json:"cycle"`
	Strength   float64       `json:"strength"`
	Confidence float64       `json:"confidence"`
	Detected   bool          `json:"detected"`
}

type Threshold

type Threshold struct {
	Name     string            `json:"name"`
	Operator ThresholdOperator `json:"operator"`
	Severity AlertSeverity     `json:"severity"`
	Value    float64           `json:"value"`
	Duration time.Duration     `json:"duration"`
	Dynamic  bool              `json:"dynamic"`
}

type ThresholdManager

type ThresholdManager interface {
	GetThresholds(metricName string) []Threshold
	SetThreshold(metricName string, threshold Threshold) error
	UpdateDynamicThresholds(ctx context.Context, metrics []PerformanceMetric) error
	EvaluateThresholds(metric PerformanceMetric) []ThresholdViolation
}

type ThresholdOperator

type ThresholdOperator string
const (
	ThresholdOperatorGT  ThresholdOperator = "gt"
	ThresholdOperatorGTE ThresholdOperator = "gte"
	ThresholdOperatorLT  ThresholdOperator = "lt"
	ThresholdOperatorLTE ThresholdOperator = "lte"
	ThresholdOperatorEQ  ThresholdOperator = "eq"
	ThresholdOperatorNE  ThresholdOperator = "ne"
)

type ThresholdViolation

type ThresholdViolation struct {
	Timestamp   time.Time     `json:"timestamp"`
	Threshold   Threshold     `json:"threshold"`
	ActualValue float64       `json:"actual_value"`
	Duration    time.Duration `json:"duration"`
}

type TimeRange

type TimeRange struct {
	Start time.Time `json:"start"`
	End   time.Time `json:"end"`
}

Complex types

type TrendAnalyzer

type TrendAnalyzer interface {
	AnalyzeTrends(ctx context.Context, metrics []PerformanceMetric) ([]PerformanceTrend, error)
	PredictTrends(ctx context.Context, metrics []PerformanceMetric, horizon time.Duration) ([]PerformancePrediction, error)
	DetectSeasonality(ctx context.Context, metrics []PerformanceMetric) (SeasonalityPattern, error)
	CalculateCorrelations(ctx context.Context, metrics map[string][]PerformanceMetric) (CorrelationMatrix, error)
}

type TrendDirection

type TrendDirection string
const (
	TrendDirectionUp       TrendDirection = "up"
	TrendDirectionDown     TrendDirection = "down"
	TrendDirectionStable   TrendDirection = "stable"
	TrendDirectionVolatile TrendDirection = "volatile"
)

type TrendForecast

type TrendForecast struct {
	Methodology string          `json:"methodology"`
	Points      []ForecastPoint `json:"points"`
	Confidence  float64         `json:"confidence"`
}

Jump to

Keyboard shortcuts

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