monitor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveAlert

type ActiveAlert struct {
	Alert        *AlertConfig `json:"alert" yaml:"alert"`
	Triggered    time.Time    `json:"triggered" yaml:"triggered"`
	Status       string       `json:"status" yaml:"status"`
	Message      string       `json:"message" yaml:"message"`
	Acknowledged bool         `json:"acknowledged" yaml:"acknowledged"`
}

ActiveAlert represents an active alert

type Alert

type Alert struct {
	RuleName  string      `json:"rule_name"`
	Severity  string      `json:"severity"`
	Message   string      `json:"message"`
	Timestamp time.Time   `json:"timestamp"`
	Value     interface{} `json:"value"`
}

type AlertConfig

type AlertConfig struct {
	Name      string    `json:"name" yaml:"name"`
	Condition string    `json:"condition" yaml:"condition"`
	Action    string    `json:"action" yaml:"action"`
	Severity  string    `json:"severity" yaml:"severity"`
	Enabled   bool      `json:"enabled" yaml:"enabled"`
	CreatedAt time.Time `json:"created_at" yaml:"created_at"`
	UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
}

AlertConfig represents a monitoring alert configuration

type AlertManager

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

AlertManager manages alerts

func NewAlertManager

func NewAlertManager() *AlertManager

NewAlertManager creates a new alert manager

func (*AlertManager) AddRule

func (m *AlertManager) AddRule(rule *AlertRule) error

AddRule adds an alert rule

func (*AlertManager) EvaluateRules

func (m *AlertManager) EvaluateRules(ctx context.Context, metrics []*Metric) ([]*Alert, error)

EvaluateRules evaluates all alert rules against the given metrics

func (*AlertManager) GetRule

func (m *AlertManager) GetRule(name string) (*AlertRule, error)

GetRule retrieves an alert rule by name

type AlertRule

type AlertRule struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Condition   string   `json:"condition"`
	Severity    string   `json:"severity"`
	Actions     []string `json:"actions"`
	Enabled     bool     `json:"enabled"`
}

type CPUUsage

type CPUUsage struct {
	Usage       float64 `json:"usage" yaml:"usage"`
	LoadAverage float64 `json:"load_average" yaml:"load_average"`
	Cores       int     `json:"cores" yaml:"cores"`
}

CPUUsage represents CPU usage metrics

type Dashboard

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

Dashboard manages monitoring dashboard

func NewDashboard

func NewDashboard() *Dashboard

NewDashboard creates a new dashboard

func (*Dashboard) AddWidget

func (d *Dashboard) AddWidget(widget *Widget) error

AddWidget adds a widget to the dashboard

func (*Dashboard) GenerateData

func (d *Dashboard) GenerateData(ctx context.Context) (*DashboardData, error)

GenerateData generates dashboard data

func (*Dashboard) GetWidget

func (d *Dashboard) GetWidget(id string) (*Widget, error)

GetWidget retrieves a widget by ID

func (*Dashboard) ListWidgets

func (d *Dashboard) ListWidgets() []*Widget

ListWidgets returns a list of all widgets

type DashboardData

type DashboardData struct {
	Widgets []*WidgetData `json:"widgets"`
}

type DataPoint

type DataPoint struct {
	Timestamp time.Time         `json:"timestamp" yaml:"timestamp"`
	Value     float64           `json:"value" yaml:"value"`
	Labels    map[string]string `json:"labels" yaml:"labels"`
}

DataPoint represents a single data point for Prometheus integration

type DiskUsage

type DiskUsage struct {
	Used      int64   `json:"used" yaml:"used"`
	Available int64   `json:"available" yaml:"available"`
	Total     int64   `json:"total" yaml:"total"`
	Usage     float64 `json:"usage" yaml:"usage"`
}

DiskUsage represents disk usage metrics

type EndpointStatus

type EndpointStatus struct {
	URL          string        `json:"url" yaml:"url"`
	Status       string        `json:"status" yaml:"status"`
	ResponseTime time.Duration `json:"response_time" yaml:"response_time"`
	StatusCode   int           `json:"status_code" yaml:"status_code"`
	LastCheck    time.Time     `json:"last_check" yaml:"last_check"`
}

EndpointStatus represents the status of a service endpoint

type GrafanaConfig

type GrafanaConfig struct {
	URL     string `json:"url"`
	APIKey  string `json:"api_key"`
	Timeout int    `json:"timeout"`
}

GrafanaConfig contains Grafana-specific settings

type GrafanaMonitor

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

GrafanaMonitor implements monitoring with Grafana

func (*GrafanaMonitor) CollectMetrics

func (m *GrafanaMonitor) CollectMetrics(ctx context.Context) ([]*Metric, error)

CollectMetrics collects metrics from Grafana

func (*GrafanaMonitor) Connect

func (m *GrafanaMonitor) Connect(ctx context.Context) error

Connect establishes connection to Grafana

func (*GrafanaMonitor) CreateAlert

func (m *GrafanaMonitor) CreateAlert(alert AlertConfig) error

CreateAlert creates an alert rule in Grafana

func (*GrafanaMonitor) DeleteAlert

func (m *GrafanaMonitor) DeleteAlert(name string) error

DeleteAlert deletes an alert

func (*GrafanaMonitor) Disconnect

func (m *GrafanaMonitor) Disconnect(ctx context.Context) error

Disconnect closes the connection

func (*GrafanaMonitor) GetAlerts

func (m *GrafanaMonitor) GetAlerts(ctx context.Context) ([]*Alert, error)

GetAlerts gets active alerts from Grafana

func (*GrafanaMonitor) GetCategory

func (m *GrafanaMonitor) GetCategory() string

GetCategory returns the monitor category

func (*GrafanaMonitor) GetConfiguration

func (m *GrafanaMonitor) GetConfiguration() *MonitorConfig

GetConfiguration returns the monitor configuration

func (*GrafanaMonitor) GetInterval

func (m *GrafanaMonitor) GetInterval() time.Duration

GetInterval returns the monitor interval

func (*GrafanaMonitor) GetMetrics

func (m *GrafanaMonitor) GetMetrics(metric, duration string) (*MetricsData, error)

GetMetrics gets metrics from Grafana

func (*GrafanaMonitor) GetName

func (m *GrafanaMonitor) GetName() string

GetName returns the monitor name

func (*GrafanaMonitor) GetServiceStatus

func (m *GrafanaMonitor) GetServiceStatus(serviceName string, detailed bool) (*ServiceStatus, error)

GetServiceStatus returns the service status

func (*GrafanaMonitor) GetStatus

func (m *GrafanaMonitor) GetStatus() string

GetStatus returns the monitor status

func (*GrafanaMonitor) GetSystemStatus

func (m *GrafanaMonitor) GetSystemStatus() (*SystemStatus, error)

GetSystemStatus returns the system status

func (*GrafanaMonitor) GetType

func (m *GrafanaMonitor) GetType() string

GetType returns the monitor type

func (*GrafanaMonitor) IsConnected

func (m *GrafanaMonitor) IsConnected() bool

IsConnected returns connection status

func (*GrafanaMonitor) IsHealthy

func (m *GrafanaMonitor) IsHealthy() bool

IsHealthy returns the health status

func (*GrafanaMonitor) ListAlerts

func (m *GrafanaMonitor) ListAlerts() ([]*Alert, error)

ListAlerts returns the list of alerts

func (*GrafanaMonitor) ListServices

func (m *GrafanaMonitor) ListServices() ([]*ServiceInfo, error)

ListServices returns the list of services

func (*GrafanaMonitor) Start

func (m *GrafanaMonitor) Start() error

Start starts the monitor

func (*GrafanaMonitor) StartDashboard

func (m *GrafanaMonitor) StartDashboard(host string, port int) error

StartDashboard starts a dashboard

func (*GrafanaMonitor) Stop

func (m *GrafanaMonitor) Stop() error

Stop stops the monitor

func (*GrafanaMonitor) UpdateConfiguration

func (m *GrafanaMonitor) UpdateConfiguration(config *MonitorConfig) error

UpdateConfiguration updates the monitor configuration

type HealthCheck

type HealthCheck struct {
	Name        string        `json:"name"`
	Description string        `json:"description"`
	Type        string        `json:"type"`
	Target      string        `json:"target"`
	Interval    time.Duration `json:"interval"`
	Timeout     time.Duration `json:"timeout"`
	Enabled     bool          `json:"enabled"`
}

type HealthCheckResult

type HealthCheckResult struct {
	CheckName string        `json:"check_name"`
	Status    string        `json:"status"`
	Timestamp time.Time     `json:"timestamp"`
	Duration  time.Duration `json:"duration"`
	Message   string        `json:"message"`
}

type HealthChecker

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

HealthChecker manages health checks

func NewHealthChecker

func NewHealthChecker() *HealthChecker

NewHealthChecker creates a new health checker

func (*HealthChecker) AddCheck

func (h *HealthChecker) AddCheck(check *HealthCheck) error

AddCheck adds a health check

func (*HealthChecker) GetHistory

func (h *HealthChecker) GetHistory(name string, limit int) ([]*HealthCheckResult, error)

GetHistory returns health check history

func (*HealthChecker) RunCheck

func (h *HealthChecker) RunCheck(ctx context.Context, name string) (*HealthCheckResult, error)

RunCheck runs a specific health check

type MemoryUsage

type MemoryUsage struct {
	Used      int64   `json:"used" yaml:"used"`
	Available int64   `json:"available" yaml:"available"`
	Total     int64   `json:"total" yaml:"total"`
	Usage     float64 `json:"usage" yaml:"usage"`
}

MemoryUsage represents memory usage metrics

type Metric

type Metric struct {
	Name      string            `json:"name"`
	Value     interface{}       `json:"value"`
	Unit      string            `json:"unit"`
	Timestamp time.Time         `json:"timestamp"`
	Labels    map[string]string `json:"labels"`
}

Additional type definitions for the test interfaces

type MetricPoint

type MetricPoint struct {
	Timestamp time.Time         `json:"timestamp" yaml:"timestamp"`
	Value     float64           `json:"value" yaml:"value"`
	Labels    map[string]string `json:"labels" yaml:"labels"`
}

MetricPoint represents a single metric data point

type MetricSummary

type MetricSummary struct {
	Average float64 `json:"average" yaml:"average"`
	Min     float64 `json:"min" yaml:"min"`
	Max     float64 `json:"max" yaml:"max"`
	Count   int64   `json:"count" yaml:"count"`
}

MetricSummary represents a summary of metrics

type MetricsData

type MetricsData struct {
	Metric    string            `json:"metric" yaml:"metric"`
	TimeRange string            `json:"time_range" yaml:"time_range"`
	Data      []MetricPoint     `json:"data" yaml:"data"`
	Points    []*DataPoint      `json:"points" yaml:"points"`
	Summary   *MetricSummary    `json:"summary" yaml:"summary"`
	Metadata  map[string]string `json:"metadata" yaml:"metadata"`
	StartTime time.Time         `json:"start_time" yaml:"start_time"`
	EndTime   time.Time         `json:"end_time" yaml:"end_time"`
}

MetricsData represents metrics data

type Monitor

type Monitor interface {
	GetName() string
	GetCategory() string
	GetInterval() time.Duration
	GetStatus() string
	Start() error
	Stop() error
	CollectMetrics(ctx context.Context) ([]*Metric, error)
	GetConfiguration() *MonitorConfig
	UpdateConfiguration(config *MonitorConfig) error
	IsHealthy() bool
	GetSystemStatus() (*SystemStatus, error)
	GetServiceStatus(serviceName string, detailed bool) (*ServiceStatus, error)
	ListServices() ([]*ServiceInfo, error)
	GetMetrics(metric, duration string) (*MetricsData, error)
	CreateAlert(alert AlertConfig) error
	ListAlerts() ([]*Alert, error)
	DeleteAlert(name string) error
	StartDashboard(host string, port int) error
}

Monitor interface defines monitoring operations

func New

func New() (Monitor, error)

New creates a new monitor instance

func NewGrafanaMonitor

func NewGrafanaMonitor(cfg *MonitorConfig) (Monitor, error)

NewGrafanaMonitor creates a new Grafana monitor

type MonitorConfig

type MonitorConfig struct {
	Name     string        `json:"name"`
	Category string        `json:"category"`
	Interval time.Duration `json:"interval"`
	Enabled  bool          `json:"enabled"`
	Endpoint string        `json:"endpoint"`
	Username string        `json:"username"`
	Password string        `json:"password"`
	Timeout  int           `json:"timeout"`

	// Prometheus configuration
	Prometheus PrometheusConfig `json:"prometheus"`

	// Grafana configuration
	Grafana GrafanaConfig `json:"grafana"`
}

type MonitorImpl

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

MonitorImpl implements the Monitor interface

func (*MonitorImpl) CollectMetrics

func (m *MonitorImpl) CollectMetrics(ctx context.Context) ([]*Metric, error)

CollectMetrics collects metrics

func (*MonitorImpl) CreateAlert

func (m *MonitorImpl) CreateAlert(alert AlertConfig) error

CreateAlert creates a new alert

func (*MonitorImpl) DeleteAlert

func (m *MonitorImpl) DeleteAlert(name string) error

DeleteAlert deletes an alert by name

func (*MonitorImpl) GetCategory

func (m *MonitorImpl) GetCategory() string

GetCategory returns the monitor category

func (*MonitorImpl) GetConfiguration

func (m *MonitorImpl) GetConfiguration() *MonitorConfig

GetConfiguration returns the monitor configuration

func (*MonitorImpl) GetInterval

func (m *MonitorImpl) GetInterval() time.Duration

GetInterval returns the monitor interval

func (*MonitorImpl) GetMetrics

func (m *MonitorImpl) GetMetrics(metric, duration string) (*MetricsData, error)

GetMetrics returns metrics data

func (*MonitorImpl) GetName

func (m *MonitorImpl) GetName() string

GetName returns the monitor name

func (*MonitorImpl) GetServiceStatus

func (m *MonitorImpl) GetServiceStatus(serviceName string, detailed bool) (*ServiceStatus, error)

GetServiceStatus returns the status of a specific service

func (*MonitorImpl) GetStatus

func (m *MonitorImpl) GetStatus() string

GetStatus returns the monitor status

func (*MonitorImpl) GetSystemStatus

func (m *MonitorImpl) GetSystemStatus() (*SystemStatus, error)

GetSystemStatus returns overall system status

func (*MonitorImpl) IsHealthy

func (m *MonitorImpl) IsHealthy() bool

IsHealthy returns whether the monitor is healthy

func (*MonitorImpl) ListAlerts

func (m *MonitorImpl) ListAlerts() ([]*Alert, error)

ListAlerts returns all configured alerts

func (*MonitorImpl) ListServices

func (m *MonitorImpl) ListServices() ([]*ServiceInfo, error)

ListServices returns a list of all services

func (*MonitorImpl) Start

func (m *MonitorImpl) Start() error

Start starts the monitor

func (*MonitorImpl) StartDashboard

func (m *MonitorImpl) StartDashboard(host string, port int) error

StartDashboard starts the monitoring dashboard web server

func (*MonitorImpl) Stop

func (m *MonitorImpl) Stop() error

Stop stops the monitor

func (*MonitorImpl) UpdateConfiguration

func (m *MonitorImpl) UpdateConfiguration(config *MonitorConfig) error

UpdateConfiguration updates the monitor configuration

type MonitoringManager

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

MonitoringManager manages multiple monitors

func NewMonitoringManager

func NewMonitoringManager() *MonitoringManager

NewMonitoringManager creates a new monitoring manager

func NewMonitoringService

func NewMonitoringService(cfg *config.Config) *MonitoringManager

NewMonitoringService creates a new monitoring service with real integrations

func (*MonitoringManager) AddMonitor

func (m *MonitoringManager) AddMonitor(monitor Monitor) error

AddMonitor adds a monitor to the manager

func (*MonitoringManager) GetMonitor

func (m *MonitoringManager) GetMonitor(name string) (Monitor, error)

GetMonitor retrieves a monitor by name

func (*MonitoringManager) ListMonitors

func (m *MonitoringManager) ListMonitors() []Monitor

ListMonitors returns a list of all monitors

func (*MonitoringManager) StartMonitoring

func (m *MonitoringManager) StartMonitoring(name string) error

StartMonitoring starts monitoring for a specific monitor

func (*MonitoringManager) StopMonitoring

func (m *MonitoringManager) StopMonitoring(name string) error

StopMonitoring stops monitoring for a specific monitor

type NetworkMetrics

type NetworkMetrics struct {
	Connections int64   `json:"connections" yaml:"connections"`
	Latency     float64 `json:"latency" yaml:"latency"`
	Throughput  float64 `json:"throughput" yaml:"throughput"`
}

NetworkMetrics represents network metrics for a service

type NetworkUsage

type NetworkUsage struct {
	BytesIn    int64 `json:"bytes_in" yaml:"bytes_in"`
	BytesOut   int64 `json:"bytes_out" yaml:"bytes_out"`
	PacketsIn  int64 `json:"packets_in" yaml:"packets_in"`
	PacketsOut int64 `json:"packets_out" yaml:"packets_out"`
}

NetworkUsage represents network usage metrics

type Position

type Position struct {
	X int `json:"x"`
	Y int `json:"y"`
}

type PrometheusConfig

type PrometheusConfig struct {
	URL         string `json:"url"`
	Username    string `json:"username"`
	Password    string `json:"password"`
	Timeout     int    `json:"timeout"`
	MetricsPort int    `json:"metrics_port"`
}

PrometheusConfig contains Prometheus-specific settings

type PrometheusMonitor

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

PrometheusMonitor implements Monitor interface for Prometheus

func NewPrometheusMonitor

func NewPrometheusMonitor(endpoint string, config *MonitorConfig) (*PrometheusMonitor, error)

NewPrometheusMonitor creates a new Prometheus monitor

func (*PrometheusMonitor) CollectMetrics

func (m *PrometheusMonitor) CollectMetrics(ctx context.Context) ([]*Metric, error)

CollectMetrics collects metrics from Prometheus

func (*PrometheusMonitor) CreateAlert

func (m *PrometheusMonitor) CreateAlert(alert AlertConfig) error

CreateAlert creates a new alert

func (*PrometheusMonitor) DeleteAlert

func (m *PrometheusMonitor) DeleteAlert(name string) error

DeleteAlert deletes an alert

func (*PrometheusMonitor) GetCategory

func (m *PrometheusMonitor) GetCategory() string

GetCategory returns the monitor category

func (*PrometheusMonitor) GetConfiguration

func (m *PrometheusMonitor) GetConfiguration() *MonitorConfig

GetConfiguration returns the monitor configuration

func (*PrometheusMonitor) GetInterval

func (m *PrometheusMonitor) GetInterval() time.Duration

GetInterval returns the monitoring interval

func (*PrometheusMonitor) GetMetrics

func (m *PrometheusMonitor) GetMetrics(metric, duration string) (*MetricsData, error)

GetMetrics returns historical metrics

func (*PrometheusMonitor) GetName

func (m *PrometheusMonitor) GetName() string

GetName returns the monitor name

func (*PrometheusMonitor) GetServiceStatus

func (m *PrometheusMonitor) GetServiceStatus(serviceName string, detailed bool) (*ServiceStatus, error)

GetServiceStatus returns service status

func (*PrometheusMonitor) GetStatus

func (m *PrometheusMonitor) GetStatus() string

GetStatus returns the monitor status

func (*PrometheusMonitor) GetSystemStatus

func (m *PrometheusMonitor) GetSystemStatus() (*SystemStatus, error)

GetSystemStatus returns overall system status

func (*PrometheusMonitor) IsHealthy

func (m *PrometheusMonitor) IsHealthy() bool

IsHealthy returns the health status

func (*PrometheusMonitor) ListAlerts

func (m *PrometheusMonitor) ListAlerts() ([]*Alert, error)

ListAlerts lists active alerts

func (*PrometheusMonitor) ListServices

func (m *PrometheusMonitor) ListServices() ([]*ServiceInfo, error)

ListServices lists monitored services

func (*PrometheusMonitor) Start

func (m *PrometheusMonitor) Start() error

Start starts the monitor

func (*PrometheusMonitor) StartDashboard

func (m *PrometheusMonitor) StartDashboard(host string, port int) error

StartDashboard starts a monitoring dashboard

func (*PrometheusMonitor) Stop

func (m *PrometheusMonitor) Stop() error

Stop stops the monitor

func (*PrometheusMonitor) UpdateConfiguration

func (m *PrometheusMonitor) UpdateConfiguration(config *MonitorConfig) error

UpdateConfiguration updates the monitor configuration

type ResourceUsage

type ResourceUsage struct {
	CPU     *CPUUsage     `json:"cpu" yaml:"cpu"`
	Memory  *MemoryUsage  `json:"memory" yaml:"memory"`
	Disk    *DiskUsage    `json:"disk" yaml:"disk"`
	Network *NetworkUsage `json:"network" yaml:"network"`
}

ResourceUsage represents system resource usage

type ServiceInfo

type ServiceInfo struct {
	Name        string `json:"name" yaml:"name"`
	Type        string `json:"type" yaml:"type"`
	Status      string `json:"status" yaml:"status"`
	Description string `json:"description" yaml:"description"`
}

ServiceInfo represents basic service information

type ServiceStatus

type ServiceStatus struct {
	Name      string            `json:"name" yaml:"name"`
	Status    string            `json:"status" yaml:"status"`
	Health    string            `json:"health" yaml:"health"`
	Uptime    time.Duration     `json:"uptime" yaml:"uptime"`
	CPU       float64           `json:"cpu" yaml:"cpu"`
	Memory    float64           `json:"memory" yaml:"memory"`
	Disk      float64           `json:"disk" yaml:"disk"`
	Network   *NetworkMetrics   `json:"network" yaml:"network"`
	Endpoints []*EndpointStatus `json:"endpoints" yaml:"endpoints"`
	LastCheck time.Time         `json:"last_check" yaml:"last_check"`
	Metadata  map[string]string `json:"metadata" yaml:"metadata"`
}

ServiceStatus represents the status of a specific service

type Size

type Size struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type SystemStatus

type SystemStatus struct {
	Overall   string            `json:"overall" yaml:"overall"`
	Timestamp time.Time         `json:"timestamp" yaml:"timestamp"`
	Services  []*ServiceStatus  `json:"services" yaml:"services"`
	Resources *ResourceUsage    `json:"resources" yaml:"resources"`
	Alerts    []*ActiveAlert    `json:"alerts" yaml:"alerts"`
	Uptime    time.Duration     `json:"uptime" yaml:"uptime"`
	Metadata  map[string]string `json:"metadata" yaml:"metadata"`
}

SystemStatus represents overall system status

type Widget

type Widget struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Type        string   `json:"type"`
	MetricQuery string   `json:"metric_query"`
	Position    Position `json:"position"`
	Size        Size     `json:"size"`
}

type WidgetData

type WidgetData struct {
	ID    string                 `json:"id"`
	Title string                 `json:"title"`
	Type  string                 `json:"type"`
	Data  map[string]interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

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