Documentation
¶
Overview ¶
Package monitoring - Alert Management System Migrated from ClubPulse to gopherkit with improvements
Package monitoring - Dashboard Generation System Migrated from ClubPulse to gopherkit with improvements
Package monitoring - Metrics Collection System Migrated from ClubPulse to gopherkit with improvements
Package monitoring provides advanced real-time monitoring capabilities for ClubPulse Migrated from ClubPulse to gopherkit with improvements and standardization
Index ¶
- type Alert
- type AlertChannel
- type AlertConfig
- type AlertManager
- func (am *AlertManager) AddRule(rule *AlertRule)
- func (am *AlertManager) EvaluateRules(metrics map[string]interface{})
- func (am *AlertManager) FireAlert(service, title, message string, severity AlertSeverity, ...) string
- func (am *AlertManager) GetActiveAlerts() []*Alert
- func (am *AlertManager) GetAlertHistory() []*Alert
- func (am *AlertManager) GetAlertStats() *AlertStats
- func (am *AlertManager) GetRules() []*AlertRule
- func (am *AlertManager) RemoveRule(ruleID string) bool
- func (am *AlertManager) ResolveAlert(alertID string) bool
- func (am *AlertManager) Stop()
- type AlertRule
- type AlertSeverity
- type AlertStats
- type AlertThresholds
- type BusinessMetrics
- type DataPoint
- type DatabaseMetrics
- type DockerStats
- type DockerStatsCollector
- type InfrastructureMetrics
- type MetricsCollector
- func (mc *MetricsCollector) CollectBusinessMetrics() (BusinessMetrics, error)
- func (mc *MetricsCollector) CollectDatabaseMetrics() (DatabaseMetrics, error)
- func (mc *MetricsCollector) CollectDockerStats() (map[string]DockerStats, error)
- func (mc *MetricsCollector) CollectServiceHealth() (map[string]ServiceMetrics, error)
- func (mc *MetricsCollector) CollectSystemMetrics() (map[string]interface{}, error)
- func (mc *MetricsCollector) GetConfig() *MetricsCollectorConfig
- func (mc *MetricsCollector) GetLastCollectionTime() time.Time
- func (mc *MetricsCollector) GetServiceList() []string
- func (mc *MetricsCollector) StartPeriodicCollection(ctx context.Context)
- func (mc *MetricsCollector) UpdateConfig(config *MetricsCollectorConfig)
- type MetricsCollectorConfig
- type MetricsDataStore
- type MonitoringConfig
- type PrometheusConfig
- type PrometheusMetrics
- func (m *PrometheusMetrics) HTTPMiddleware() gin.HandlerFunc
- func (m *PrometheusMetrics) Handler() http.Handler
- func (m *PrometheusMetrics) IncrementRegistrations()
- func (m *PrometheusMetrics) MetricsHandler() gin.HandlerFunc
- func (m *PrometheusMetrics) RecordCacheOperation(operation, result string, duration time.Duration)
- func (m *PrometheusMetrics) RecordCircuitBreakerFailure(name string)
- func (m *PrometheusMetrics) RecordCircuitBreakerRequest(name, state, result string)
- func (m *PrometheusMetrics) RecordCircuitBreakerState(name, state string, stateValue float64)
- func (m *PrometheusMetrics) RecordDatabaseMetrics(operation, table, result string, duration time.Duration)
- func (m *PrometheusMetrics) RecordLoginAttempt(result, method string)
- func (m *PrometheusMetrics) SetActiveUsers(count float64)
- func (m *PrometheusMetrics) StartRuntimeMetricsCollector(ctx context.Context, interval time.Duration)
- func (m *PrometheusMetrics) UpdateCacheHitRatio(cacheName string, ratio float64)
- func (m *PrometheusMetrics) UpdateDatabaseConnections(database, host string, open, idle, inUse int)
- func (m *PrometheusMetrics) UpdateRuntimeMetrics(goroutines int, memoryBytes float64, cpuPercent float64)
- type RealTimeMonitor
- type ServiceMetrics
- type SystemMetrics
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alert ¶ added in v1.0.2
type Alert struct {
ID string `json:"id"`
Service string `json:"service"`
Title string `json:"title"`
Message string `json:"message"`
Severity AlertSeverity `json:"severity"`
Timestamp time.Time `json:"timestamp"`
Resolved bool `json:"resolved"`
ResolvedAt *time.Time `json:"resolved_at,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
RetryCount int `json:"retry_count"`
LastAttempt time.Time `json:"last_attempt"`
}
Alert representa una alerta del sistema
type AlertChannel ¶ added in v1.0.2
type AlertChannel string
AlertChannel define los tipos de canales de alerta disponibles
const ( AlertChannelWebhook AlertChannel = "webhook" AlertChannelSlack AlertChannel = "slack" AlertChannelEmail AlertChannel = "email" AlertChannelLog AlertChannel = "log" )
type AlertConfig ¶ added in v1.0.2
type AlertConfig struct {
WebhookURL string `json:"webhook_url"`
SlackToken string `json:"slack_token"`
SlackChannel string `json:"slack_channel"`
EmailSMTPServer string `json:"email_smtp_server"`
EmailFrom string `json:"email_from"`
EmailPassword string `json:"email_password"`
MaxRetries int `json:"max_retries"`
RetryInterval time.Duration `json:"retry_interval"`
AlertCooldown time.Duration `json:"alert_cooldown"`
EnabledChannels []AlertChannel `json:"enabled_channels"`
DefaultSeverity AlertSeverity `json:"default_severity"`
AlertHistoryLimit int `json:"alert_history_limit"`
}
AlertConfig configuración del sistema de alertas
func DefaultAlertConfig ¶ added in v1.0.2
func DefaultAlertConfig() *AlertConfig
DefaultAlertConfig retorna configuración por defecto
type AlertManager ¶ added in v1.0.2
type AlertManager struct {
// contains filtered or unexported fields
}
AlertManager gestiona el sistema completo de alertas
func NewAlertManager ¶ added in v1.0.2
func NewAlertManager(config *AlertConfig) *AlertManager
NewAlertManager crea una nueva instancia del AlertManager mejorado
func (*AlertManager) AddRule ¶ added in v1.0.2
func (am *AlertManager) AddRule(rule *AlertRule)
AddRule agrega una nueva regla de alerta
func (*AlertManager) EvaluateRules ¶ added in v1.0.2
func (am *AlertManager) EvaluateRules(metrics map[string]interface{})
EvaluateRules evalúa todas las reglas de alerta contra métricas actuales
func (*AlertManager) FireAlert ¶ added in v1.0.2
func (am *AlertManager) FireAlert(service, title, message string, severity AlertSeverity, metadata map[string]interface{}) string
FireAlert dispara una nueva alerta
func (*AlertManager) GetActiveAlerts ¶ added in v1.0.2
func (am *AlertManager) GetActiveAlerts() []*Alert
GetActiveAlerts retorna todas las alertas activas
func (*AlertManager) GetAlertHistory ¶ added in v1.0.2
func (am *AlertManager) GetAlertHistory() []*Alert
GetAlertHistory retorna el historial de alertas
func (*AlertManager) GetAlertStats ¶ added in v1.0.2
func (am *AlertManager) GetAlertStats() *AlertStats
GetAlertStats retorna estadísticas del sistema de alertas
func (*AlertManager) GetRules ¶ added in v1.0.2
func (am *AlertManager) GetRules() []*AlertRule
GetRules retorna todas las reglas de alerta
func (*AlertManager) RemoveRule ¶ added in v1.0.2
func (am *AlertManager) RemoveRule(ruleID string) bool
RemoveRule elimina una regla de alerta
func (*AlertManager) ResolveAlert ¶ added in v1.0.2
func (am *AlertManager) ResolveAlert(alertID string) bool
ResolveAlert marca una alerta como resuelta
func (*AlertManager) Stop ¶ added in v1.0.2
func (am *AlertManager) Stop()
Stop detiene el AlertManager
type AlertRule ¶ added in v1.0.2
type AlertRule struct {
ID string `json:"id"`
Name string `json:"name"`
Condition string `json:"condition"`
Threshold float64 `json:"threshold"`
Duration time.Duration `json:"duration"`
Severity AlertSeverity `json:"severity"`
Enabled bool `json:"enabled"`
Channels []AlertChannel `json:"channels"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
LastFired *time.Time `json:"last_fired,omitempty"`
FireCount int `json:"fire_count"`
}
AlertRule define reglas para activación automática de alertas
type AlertSeverity ¶ added in v1.0.2
type AlertSeverity string
AlertSeverity representa el nivel de severidad de una alerta
const ( AlertSeverityInfo AlertSeverity = "info" AlertSeverityWarning AlertSeverity = "warning" AlertSeverityCritical AlertSeverity = "critical" AlertSeverityFatal AlertSeverity = "fatal" )
type AlertStats ¶ added in v1.0.2
type AlertStats struct {
TotalAlerts int `json:"total_alerts"`
ActiveAlerts int `json:"active_alerts"`
ResolvedAlerts int `json:"resolved_alerts"`
AlertsBySeverity map[AlertSeverity]int `json:"alerts_by_severity"`
AlertsByService map[string]int `json:"alerts_by_service"`
AlertsByChannel map[AlertChannel]int `json:"alerts_by_channel"`
FailedAlerts int `json:"failed_alerts"`
LastAlert *time.Time `json:"last_alert,omitempty"`
}
AlertStats estadísticas del sistema de alertas
type AlertThresholds ¶ added in v1.0.2
type AlertThresholds struct {
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
DatabaseConnections int `json:"database_connections"`
ResponseTime time.Duration `json:"response_time"`
ErrorRate float64 `json:"error_rate"`
DiskUsage float64 `json:"disk_usage"`
}
AlertThresholds umbrales para alertas
type BusinessMetrics ¶ added in v1.0.2
type BusinessMetrics struct {
TotalUsers int `json:"total_users"`
ActiveUsers int `json:"active_users"`
ReservationsToday int `json:"reservations_today"`
PaymentsToday float64 `json:"payments_today"`
ChampionshipsActive int `json:"championships_active"`
MembershipsActive int `json:"memberships_active"`
AvgSessionDuration time.Duration `json:"avg_session_duration"`
ConversionRate float64 `json:"conversion_rate"`
}
BusinessMetrics métricas de negocio
type DatabaseMetrics ¶ added in v1.0.2
type DatabaseMetrics struct {
Mode string `json:"mode"`
ActiveConnections int `json:"active_connections"`
MaxConnections int `json:"max_connections"`
ConnectionPoolUsage float64 `json:"connection_pool_usage"`
QueryLatency time.Duration `json:"query_latency"`
QueriesPerSecond float64 `json:"queries_per_second"`
CacheHitRate float64 `json:"cache_hit_rate"`
SchemaHealth map[string]string `json:"schema_health"`
FallbackStatus string `json:"fallback_status"`
RLSStatus string `json:"rls_status"`
}
DatabaseMetrics métricas específicas de base de datos
type DockerStats ¶ added in v1.0.2
type DockerStats struct {
ContainerName string `json:"container_name"`
CPUPercent float64 `json:"cpu_percent"`
MemoryUsage int64 `json:"memory_usage"`
MemoryLimit int64 `json:"memory_limit"`
NetworkRX int64 `json:"network_rx"`
NetworkTX int64 `json:"network_tx"`
BlockRead int64 `json:"block_read"`
BlockWrite int64 `json:"block_write"`
RestartCount int `json:"restart_count"`
}
DockerStats estadísticas de contenedores Docker
type DockerStatsCollector ¶ added in v1.0.2
type DockerStatsCollector struct {
// contains filtered or unexported fields
}
DockerStatsCollector recolector de estadísticas de Docker mejorado
type InfrastructureMetrics ¶ added in v1.0.2
type InfrastructureMetrics struct {
ContainerCount int `json:"container_count"`
ContainerHealth map[string]string `json:"container_health"`
DockerStats map[string]DockerStats `json:"docker_stats"`
NetworkLatency time.Duration `json:"network_latency"`
DiskUsage float64 `json:"disk_usage"`
SystemLoad float64 `json:"system_load"`
}
InfrastructureMetrics métricas de infraestructura
type MetricsCollector ¶ added in v1.0.2
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector recolector de métricas del sistema mejorado
func NewMetricsCollector ¶ added in v1.0.2
func NewMetricsCollector() (*MetricsCollector, error)
NewMetricsCollector crea un nuevo recolector de métricas mejorado
func NewMetricsCollectorWithConfig ¶ added in v1.0.2
func NewMetricsCollectorWithConfig(config *MetricsCollectorConfig) (*MetricsCollector, error)
NewMetricsCollectorWithConfig crea un recolector con configuración personalizada
func (*MetricsCollector) CollectBusinessMetrics ¶ added in v1.0.2
func (mc *MetricsCollector) CollectBusinessMetrics() (BusinessMetrics, error)
CollectBusinessMetrics recolecta métricas de negocio (mock por ahora)
func (*MetricsCollector) CollectDatabaseMetrics ¶ added in v1.0.2
func (mc *MetricsCollector) CollectDatabaseMetrics() (DatabaseMetrics, error)
CollectDatabaseMetrics recolecta métricas de base de datos (mock por ahora)
func (*MetricsCollector) CollectDockerStats ¶ added in v1.0.2
func (mc *MetricsCollector) CollectDockerStats() (map[string]DockerStats, error)
CollectDockerStats recolecta estadísticas de contenedores Docker
func (*MetricsCollector) CollectServiceHealth ¶ added in v1.0.2
func (mc *MetricsCollector) CollectServiceHealth() (map[string]ServiceMetrics, error)
CollectServiceHealth recolecta el estado de salud de servicios
func (*MetricsCollector) CollectSystemMetrics ¶ added in v1.0.2
func (mc *MetricsCollector) CollectSystemMetrics() (map[string]interface{}, error)
CollectSystemMetrics recolecta métricas generales del sistema
func (*MetricsCollector) GetConfig ¶ added in v1.0.2
func (mc *MetricsCollector) GetConfig() *MetricsCollectorConfig
GetConfig retorna la configuración actual
func (*MetricsCollector) GetLastCollectionTime ¶ added in v1.0.2
func (mc *MetricsCollector) GetLastCollectionTime() time.Time
GetLastCollectionTime retorna el tiempo de la última recolección
func (*MetricsCollector) GetServiceList ¶ added in v1.0.2
func (mc *MetricsCollector) GetServiceList() []string
GetServiceList retorna la lista de servicios monitoreados
func (*MetricsCollector) StartPeriodicCollection ¶ added in v1.0.2
func (mc *MetricsCollector) StartPeriodicCollection(ctx context.Context)
StartPeriodicCollection inicia la recolección periódica de métricas
func (*MetricsCollector) UpdateConfig ¶ added in v1.0.2
func (mc *MetricsCollector) UpdateConfig(config *MetricsCollectorConfig)
UpdateConfig actualiza la configuración del recolector
type MetricsCollectorConfig ¶ added in v1.0.2
type MetricsCollectorConfig struct {
ServicePorts map[string]int `json:"service_ports"`
HealthEndpoint string `json:"health_endpoint"`
CollectInterval time.Duration `json:"collect_interval"`
RequestTimeout time.Duration `json:"request_timeout"`
EnableDocker bool `json:"enable_docker"`
EnableSystemInfo bool `json:"enable_system_info"`
TenantID string `json:"tenant_id"`
}
MetricsCollectorConfig configuración del recolector de métricas
func DefaultMetricsCollectorConfig ¶ added in v1.0.2
func DefaultMetricsCollectorConfig() *MetricsCollectorConfig
DefaultMetricsCollectorConfig retorna configuración por defecto
type MetricsDataStore ¶ added in v1.0.2
type MetricsDataStore struct {
// contains filtered or unexported fields
}
MetricsDataStore almacén de datos de métricas
type MonitoringConfig ¶ added in v1.0.2
type MonitoringConfig struct {
Port int `json:"port"`
MetricsPort int `json:"metrics_port"`
UpdateInterval time.Duration `json:"update_interval"`
AlertThresholds AlertThresholds `json:"alert_thresholds"`
RetentionPeriod time.Duration `json:"retention_period"`
EnableWebSocket bool `json:"enable_websocket"`
EnableDashboard bool `json:"enable_dashboard"`
PrometheusURL string `json:"prometheus_url"`
EnableAlerts bool `json:"enable_alerts"`
}
MonitoringConfig configuración del sistema de monitoreo
type PrometheusConfig ¶
type PrometheusConfig struct {
ServiceName string
Namespace string
Subsystem string
HistogramBuckets []float64
// Custom labels
DefaultLabels prometheus.Labels
// Exclusions
ExcludePaths []string
ExcludeStatusCodes []int
}
PrometheusConfig configuración para métricas Prometheus
func DefaultPrometheusConfig ¶
func DefaultPrometheusConfig(serviceName string) *PrometheusConfig
DefaultPrometheusConfig retorna configuración por defecto
type PrometheusMetrics ¶
type PrometheusMetrics struct {
// contains filtered or unexported fields
}
PrometheusMetrics contiene todas las métricas Prometheus
func NewPrometheusMetrics ¶
func NewPrometheusMetrics(config *PrometheusConfig) *PrometheusMetrics
NewPrometheusMetrics crea métricas Prometheus
func (*PrometheusMetrics) HTTPMiddleware ¶
func (m *PrometheusMetrics) HTTPMiddleware() gin.HandlerFunc
HTTPMiddleware retorna middleware Gin para métricas HTTP
func (*PrometheusMetrics) Handler ¶
func (m *PrometheusMetrics) Handler() http.Handler
Handler retorna el handler HTTP para métricas Prometheus
func (*PrometheusMetrics) IncrementRegistrations ¶
func (m *PrometheusMetrics) IncrementRegistrations()
func (*PrometheusMetrics) MetricsHandler ¶
func (m *PrometheusMetrics) MetricsHandler() gin.HandlerFunc
MetricsHandler crea handler Gin para endpoint de métricas
func (*PrometheusMetrics) RecordCacheOperation ¶
func (m *PrometheusMetrics) RecordCacheOperation(operation, result string, duration time.Duration)
RecordCacheOperation registra operaciones de cache
func (*PrometheusMetrics) RecordCircuitBreakerFailure ¶
func (m *PrometheusMetrics) RecordCircuitBreakerFailure(name string)
RecordCircuitBreakerFailure registra fallo de circuit breaker
func (*PrometheusMetrics) RecordCircuitBreakerRequest ¶
func (m *PrometheusMetrics) RecordCircuitBreakerRequest(name, state, result string)
RecordCircuitBreakerRequest registra request de circuit breaker
func (*PrometheusMetrics) RecordCircuitBreakerState ¶
func (m *PrometheusMetrics) RecordCircuitBreakerState(name, state string, stateValue float64)
RecordCircuitBreakerState registra estado de circuit breaker
func (*PrometheusMetrics) RecordDatabaseMetrics ¶
func (m *PrometheusMetrics) RecordDatabaseMetrics(operation, table, result string, duration time.Duration)
RecordDatabaseMetrics registra métricas de base de datos
func (*PrometheusMetrics) RecordLoginAttempt ¶
func (m *PrometheusMetrics) RecordLoginAttempt(result, method string)
func (*PrometheusMetrics) SetActiveUsers ¶
func (m *PrometheusMetrics) SetActiveUsers(count float64)
Business metrics methods
func (*PrometheusMetrics) StartRuntimeMetricsCollector ¶
func (m *PrometheusMetrics) StartRuntimeMetricsCollector(ctx context.Context, interval time.Duration)
StartRuntimeMetricsCollector inicia recolección de métricas de runtime
func (*PrometheusMetrics) UpdateCacheHitRatio ¶
func (m *PrometheusMetrics) UpdateCacheHitRatio(cacheName string, ratio float64)
UpdateCacheHitRatio actualiza ratio de cache hits
func (*PrometheusMetrics) UpdateDatabaseConnections ¶
func (m *PrometheusMetrics) UpdateDatabaseConnections(database, host string, open, idle, inUse int)
UpdateDatabaseConnections actualiza métricas de conexiones de BD
func (*PrometheusMetrics) UpdateRuntimeMetrics ¶
func (m *PrometheusMetrics) UpdateRuntimeMetrics(goroutines int, memoryBytes float64, cpuPercent float64)
Infrastructure metrics methods
type RealTimeMonitor ¶ added in v1.0.2
type RealTimeMonitor struct {
// contains filtered or unexported fields
}
RealTimeMonitor sistema de monitoreo en tiempo real mejorado
func NewRealTimeMonitor ¶ added in v1.0.2
func NewRealTimeMonitor(config MonitoringConfig, alertManager *AlertManager) (*RealTimeMonitor, error)
NewRealTimeMonitor crea un nuevo monitor en tiempo real mejorado
func (*RealTimeMonitor) Start ¶ added in v1.0.2
func (rtm *RealTimeMonitor) Start() error
Start inicia el sistema de monitoreo en tiempo real
type ServiceMetrics ¶ added in v1.0.2
type ServiceMetrics struct {
Name string `json:"name"`
Status string `json:"status"`
ResponseTime time.Duration `json:"response_time"`
RequestsPerSec float64 `json:"requests_per_sec"`
ErrorRate float64 `json:"error_rate"`
CPUUsage float64 `json:"cpu_usage"`
MemoryUsage float64 `json:"memory_usage"`
ActiveUsers int `json:"active_users"`
LastHealthCheck time.Time `json:"last_health_check"`
}
ServiceMetrics métricas por servicio
type SystemMetrics ¶ added in v1.0.2
type SystemMetrics struct {
Timestamp time.Time `json:"timestamp"`
DatabaseMetrics DatabaseMetrics `json:"database"`
ServiceMetrics map[string]ServiceMetrics `json:"services"`
InfrastructureMetrics InfrastructureMetrics `json:"infrastructure"`
BusinessMetrics BusinessMetrics `json:"business"`
AlertsActive []Alert `json:"active_alerts"`
SystemHealth string `json:"system_health"`
PerformanceScore float64 `json:"performance_score"`
}
SystemMetrics métricas del sistema en tiempo real