monitoring

package
v0.0.0-...-0b35af4 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	ID            string                 `json:"id"`
	Type          AlertType              `json:"type"`
	Severity      AlertSeverity          `json:"severity"`
	Status        AlertStatus            `json:"status"`
	Title         string                 `json:"title"`
	Description   string                 `json:"description"`
	EntityID      string                 `json:"entity_id"`
	EntityType    string                 `json:"entity_type"`
	Timestamp     time.Time              `json:"timestamp"`
	Labels        map[string]string      `json:"labels"`
	Annotations   map[string]interface{} `json:"annotations"`
	Threshold     *Threshold             `json:"threshold,omitempty"`
	Current       float64                `json:"current_value"`
	ResolvedAt    *time.Time             `json:"resolved_at,omitempty"`
	SilencedUntil *time.Time             `json:"silenced_until,omitempty"`
}

Alert represents a monitoring alert

type AlertManager

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

AlertManager manages alerts and notifications

func NewAlertManager

func NewAlertManager(logger *log.Logger) *AlertManager

NewAlertManager creates a new alert manager

func (*AlertManager) AddChannel

func (am *AlertManager) AddChannel(channel *NotificationChannel)

AddChannel adds a new notification channel

func (*AlertManager) AddRule

func (am *AlertManager) AddRule(rule *AlertRule)

AddRule adds a new alert rule

func (*AlertManager) EvaluateRules

func (am *AlertManager) EvaluateRules(ctx context.Context) error

EvaluateRules evaluates all alert rules

func (*AlertManager) GetActiveAlerts

func (am *AlertManager) GetActiveAlerts() []*Alert

GetActiveAlerts returns only active alerts

func (*AlertManager) GetAlerts

func (am *AlertManager) GetAlerts() []*Alert

GetAlerts returns all alerts

func (*AlertManager) RemoveRule

func (am *AlertManager) RemoveRule(ruleID string)

RemoveRule removes an alert rule

func (*AlertManager) SilenceAlert

func (am *AlertManager) SilenceAlert(alertID string, duration time.Duration) error

SilenceAlert silences an alert

type AlertMetrics

type AlertMetrics struct {
	AlertsTotal      prometheus.Counter
	AlertsActive     prometheus.Gauge
	AlertsResolved   prometheus.Counter
	AlertsByType     *prometheus.CounterVec
	AlertsBySeverity *prometheus.CounterVec
}

AlertMetrics tracks alert-related metrics

func NewAlertMetrics

func NewAlertMetrics() *AlertMetrics

NewAlertMetrics creates new alert metrics

type AlertRule

type AlertRule struct {
	ID        string            `json:"id"`
	Name      string            `json:"name"`
	Type      AlertType         `json:"type"`
	Severity  AlertSeverity     `json:"severity"`
	Threshold Threshold         `json:"threshold"`
	Query     string            `json:"query"`
	Labels    map[string]string `json:"labels"`
	Enabled   bool              `json:"enabled"`
	Interval  time.Duration     `json:"interval"`
	LastEval  time.Time         `json:"last_eval"`
}

AlertRule defines when to trigger alerts

func DefaultAlertRules

func DefaultAlertRules() []*AlertRule

DefaultAlertRules returns a set of default alert rules

type AlertSeverity

type AlertSeverity string

AlertSeverity represents the severity level of an alert

const (
	SeverityInfo     AlertSeverity = "info"
	SeverityWarning  AlertSeverity = "warning"
	SeverityError    AlertSeverity = "error"
	SeverityCritical AlertSeverity = "critical"
)

type AlertStatus

type AlertStatus string

AlertStatus represents the current status of an alert

const (
	StatusActive   AlertStatus = "active"
	StatusResolved AlertStatus = "resolved"
	StatusSilenced AlertStatus = "silenced"
)

type AlertType

type AlertType string

AlertType represents different types of alerts

const (
	AlertTypePerformance  AlertType = "performance"
	AlertTypeAvailability AlertType = "availability"
	AlertTypeSecurity     AlertType = "security"
	AlertTypeCost         AlertType = "cost"
	AlertTypeCapacity     AlertType = "capacity"
	AlertTypeOptimization AlertType = "optimization"
	AlertTypeSystem       AlertType = "system"
)

type HealthCheck

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

HealthCheck provides health check functionality

func NewHealthCheck

func NewHealthCheck(logger *zap.Logger) *HealthCheck

NewHealthCheck creates a new health check instance

func (*HealthCheck) AddCheck

func (hc *HealthCheck) AddCheck(name string, check HealthCheckFunc)

AddCheck adds a health check

func (*HealthCheck) CheckHealth

func (hc *HealthCheck) CheckHealth(ctx context.Context) map[string]string

CheckHealth performs all health checks

func (*HealthCheck) GetHealthHandler

func (hc *HealthCheck) GetHealthHandler() http.HandlerFunc

GetHealthHandler returns an HTTP handler for health checks

func (*HealthCheck) RunChecks

func (hc *HealthCheck) RunChecks(ctx context.Context) map[string]string

RunChecks performs all health checks (alias for CheckHealth)

type HealthCheckFunc

type HealthCheckFunc func(ctx context.Context) error

HealthCheckFunc is a function that performs a health check

type Metrics

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

Metrics holds all application metrics

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates a new metrics instance

func (*Metrics) Register

func (m *Metrics) Register() error

Register registers all metrics with Prometheus

type MonitoringService

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

MonitoringService provides monitoring capabilities

func NewMonitoringService

func NewMonitoringService() (*MonitoringService, error)

NewMonitoringService creates a new monitoring service

func (*MonitoringService) GetMetrics

func (ms *MonitoringService) GetMetrics() map[string]interface{}

GetMetrics returns current metrics as a map

func (*MonitoringService) GetMetricsHandler

func (ms *MonitoringService) GetMetricsHandler() http.Handler

GetMetricsHandler returns the Prometheus metrics handler

func (*MonitoringService) RecordAIRequest

func (ms *MonitoringService) RecordAIRequest(service, model, status string, duration time.Duration, tokens int)

RecordAIRequest records an AI request

func (*MonitoringService) RecordCloudOperation

func (ms *MonitoringService) RecordCloudOperation(provider, operation, status string, duration time.Duration)

RecordCloudOperation records a cloud operation

func (*MonitoringService) RecordCloudResources

func (ms *MonitoringService) RecordCloudResources(provider, resourceType, region string, count float64)

RecordCloudResources records discovered cloud resources

func (*MonitoringService) RecordCostSavings

func (ms *MonitoringService) RecordCostSavings(provider, optimizationType string, savings float64)

RecordCostSavings records cost savings

func (*MonitoringService) RecordError

func (ms *MonitoringService) RecordError(component, errorType string)

RecordError records a system error

func (*MonitoringService) RecordHTTPRequest

func (ms *MonitoringService) RecordHTTPRequest(method, endpoint, status string, duration time.Duration)

RecordHTTPRequest records an HTTP request

func (*MonitoringService) RecordOptimizationAction

func (ms *MonitoringService) RecordOptimizationAction(provider, action, status string)

RecordOptimizationAction records an optimization action

func (*MonitoringService) SetActiveWorkers

func (ms *MonitoringService) SetActiveWorkers(count int)

SetActiveWorkers sets the number of active workers

type NotificationChannel

type NotificationChannel struct {
	ID       string                 `json:"id"`
	Name     string                 `json:"name"`
	Type     string                 `json:"type"` // email, slack, webhook, pagerduty
	Config   map[string]interface{} `json:"config"`
	Enabled  bool                   `json:"enabled"`
	LastSent time.Time              `json:"last_sent"`
}

NotificationChannel defines how alerts are sent

func DefaultNotificationChannels

func DefaultNotificationChannels() []*NotificationChannel

DefaultNotificationChannels returns default notification channels

type Notifier

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

Notifier handles sending alert notifications

func NewNotifier

func NewNotifier(logger *log.Logger) *Notifier

NewNotifier creates a new notifier

func (*Notifier) SendNotifications

func (n *Notifier) SendNotifications(ctx context.Context, alert *Alert, channels map[string]*NotificationChannel)

SendNotifications sends alert notifications through all channels

func (*Notifier) SendResolutionNotifications

func (n *Notifier) SendResolutionNotifications(ctx context.Context, alert *Alert, channels map[string]*NotificationChannel)

SendResolutionNotifications sends resolution notifications

type Threshold

type Threshold struct {
	Metric   string  `json:"metric"`
	Operator string  `json:"operator"` // >, <, >=, <=, ==, !=
	Value    float64 `json:"value"`
	Duration string  `json:"duration"` // e.g., "5m", "1h"
}

Threshold defines alerting thresholds

Jump to

Keyboard shortcuts

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