Documentation
¶
Overview ¶
Package caddymonitor provides enterprise-grade observability for Caddy deployments.
Index ¶
- Variables
- type APIKey
- type Alert
- type AlertCorrelator
- type AlertDeduplicator
- type AlertEscalation
- type AlertManager
- func (am *AlertManager) DeduplicateAlert(alert *Alert) bool
- func (am *AlertManager) EvaluateWithAnomalyDetection(rule *AlertRule, value float64, detector *AnomalyDetector) (bool, error)
- func (am *AlertManager) FireAlert(alert *Alert) error
- func (am *AlertManager) GetActiveAlerts() []*Alert
- func (am *AlertManager) Provision(ctx caddy.Context, logger *zap.Logger) error
- func (am *AlertManager) Run(ctx context.Context, provider MetricProvider, slo *SLOManager) error
- func (am *AlertManager) SilenceAlert(ruleName string, duration time.Duration) error
- type AlertRule
- type AlertSilence
- type AnomalyDetector
- type AuditEntry
- type AuditLog
- type BurnRate
- type CaddyMonitor
- type ComplianceManager
- func (cm *ComplianceManager) DecryptData(data []byte) ([]byte, error)
- func (cm *ComplianceManager) EncryptData(data []byte) ([]byte, error)
- func (cm *ComplianceManager) GenerateComplianceReport(reportType string) (*ComplianceReport, error)
- func (cm *ComplianceManager) MaskPII(text string) string
- func (cm *ComplianceManager) Provision(logger *zap.Logger) error
- type ComplianceReport
- type DataRetentionManager
- type DataStore
- type DistributedTracer
- func (dt *DistributedTracer) ExtractHTTPHeaders(r *http.Request) context.Context
- func (dt *DistributedTracer) InjectHTTPHeaders(ctx context.Context, r *http.Request)
- func (dt *DistributedTracer) Provision(ctx caddy.Context, logger *zap.Logger) error
- func (dt *DistributedTracer) RecordHTTPRequest(ctx context.Context, r *http.Request, statusCode int)
- func (dt *DistributedTracer) Shutdown(ctx context.Context) error
- func (dt *DistributedTracer) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)
- type EncryptionConfig
- type Encryptor
- type ErrorBudget
- type EscalationPolicy
- type ExporterConfig
- type InfluxDBBackend
- type MetricProvider
- type MetricsCollector
- func (mc *MetricsCollector) MetricValue(name string) (float64, error)
- func (mc *MetricsCollector) Provision(ctx caddy.Context, logger *zap.Logger) error
- func (mc *MetricsCollector) RecordHTTPRequest(r *http.Request, statusCode int, duration time.Duration, tenantID string) error
- func (mc *MetricsCollector) RecordRequest(labels prometheus.Labels, duration time.Duration) error
- type MonitorAPI
- type MonitorMiddleware
- type MultiTenancy
- func (mt *MultiTenancy) AuthorizeTenant(tenantID string) error
- func (mt *MultiTenancy) GetTenant(tenantID string) (*Tenant, error)
- func (mt *MultiTenancy) GetTenantStats(tenantID string) (map[string]int64, error)
- func (mt *MultiTenancy) ListTenants() []*Tenant
- func (mt *MultiTenancy) Provision(ctx caddy.Context, logger *zap.Logger) error
- func (mt *MultiTenancy) RecordRequest(tenantID string, statusCode int)
- func (mt *MultiTenancy) RegisterTenant(tenant *Tenant) error
- func (mt *MultiTenancy) ResolveTenantID(r *http.Request) string
- type PIIMasker
- type PIIMaskingConfig
- type Permission
- type PrometheusBackend
- type RBACManager
- func (rbac *RBACManager) CreateAPIKey(name, tenantID string, role Role, expiresIn *time.Duration) (*APIKey, error)
- func (rbac *RBACManager) HasPermission(apiKey *APIKey, permission Permission) bool
- func (rbac *RBACManager) ListAPIKeys(tenantID string) []*APIKey
- func (rbac *RBACManager) Provision(logger *zap.Logger) error
- func (rbac *RBACManager) RevokeAPIKey(keyID string) error
- func (rbac *RBACManager) ValidateAPIKey(key string) (*APIKey, error)
- type ReportingConfig
- type RetentionConfig
- type Role
- type SLO
- type SLOManager
- type SamplerConfig
- type StorageBackend
- type Tenant
- type TenantQuota
- type VictoriaMetricsBackend
- type WebhookConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotProvisioned = errors.New("component not provisioned") ErrInvalidConfig = errors.New("invalid configuration") ErrMetricsDisabled = errors.New("metrics collection is disabled") ErrAlertingDisabled = errors.New("alerting is disabled") ErrExceededCardinality = errors.New("exceeded cardinality limit") )
Common errors
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey struct {
ID string `json:"id"`
Key string `json:"key,omitempty"` // Only shown once on creation
Hash string `json:"-"`
Name string `json:"name"`
TenantID string `json:"tenant_id"`
Role Role `json:"role"`
Permissions []Permission `json:"permissions"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
Active bool `json:"active"`
}
type Alert ¶
type Alert struct {
ID string `json:"id"`
RuleName string `json:"rule_name"`
Severity string `json:"severity"`
StartsAt time.Time `json:"starts_at"`
Value float64 `json:"value"`
}
Alert represents an active alert.
type AlertCorrelator ¶
type AlertCorrelator struct {
// contains filtered or unexported fields
}
func NewAlertCorrelator ¶
func NewAlertCorrelator() *AlertCorrelator
func (*AlertCorrelator) AddCorrelation ¶
func (ac *AlertCorrelator) AddCorrelation(parent string, children []string)
func (*AlertCorrelator) ShouldSuppress ¶
func (ac *AlertCorrelator) ShouldSuppress(alertName string, activeAlerts map[string]*Alert) bool
type AlertDeduplicator ¶
type AlertDeduplicator struct {
// contains filtered or unexported fields
}
func NewAlertDeduplicator ¶
func NewAlertDeduplicator(window time.Duration) *AlertDeduplicator
func (*AlertDeduplicator) Cleanup ¶
func (ad *AlertDeduplicator) Cleanup()
func (*AlertDeduplicator) IsDuplicate ¶
func (ad *AlertDeduplicator) IsDuplicate(alertKey string) bool
type AlertEscalation ¶
type AlertManager ¶
type AlertManager struct {
Enabled bool `json:"enabled,omitempty"`
Rules []*AlertRule `json:"rules,omitempty"`
Webhook *WebhookConfig `json:"webhook,omitempty"`
EvalInterval string `json:"eval_interval,omitempty"`
// contains filtered or unexported fields
}
AlertManager handles intelligent alerting.
func (*AlertManager) DeduplicateAlert ¶
func (am *AlertManager) DeduplicateAlert(alert *Alert) bool
func (*AlertManager) EvaluateWithAnomalyDetection ¶
func (am *AlertManager) EvaluateWithAnomalyDetection(rule *AlertRule, value float64, detector *AnomalyDetector) (bool, error)
func (*AlertManager) FireAlert ¶
func (am *AlertManager) FireAlert(alert *Alert) error
FireAlert fires an alert with retry logic.
func (*AlertManager) GetActiveAlerts ¶
func (am *AlertManager) GetActiveAlerts() []*Alert
func (*AlertManager) Run ¶
func (am *AlertManager) Run(ctx context.Context, provider MetricProvider, slo *SLOManager) error
func (*AlertManager) SilenceAlert ¶
func (am *AlertManager) SilenceAlert(ruleName string, duration time.Duration) error
type AlertRule ¶
type AlertRule struct {
Name string `json:"name"`
Metric string `json:"metric"`
Threshold float64 `json:"threshold"`
Window string `json:"window"`
Severity string `json:"severity"`
BurnRates []*BurnRate `json:"burn_rates,omitempty"`
}
AlertRule defines an alerting rule.
type AlertSilence ¶
type AnomalyDetector ¶
type AnomalyDetector struct {
Enabled bool `json:"enabled,omitempty"`
Threshold float64 `json:"threshold,omitempty"` // z-score threshold
WindowSize int `json:"window_size,omitempty"`
// contains filtered or unexported fields
}
func (*AnomalyDetector) IsAnomaly ¶
func (ad *AnomalyDetector) IsAnomaly(value float64) bool
func (*AnomalyDetector) RecordValue ¶
func (ad *AnomalyDetector) RecordValue(value float64)
type AuditEntry ¶
type AuditEntry struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
TenantID string `json:"tenant_id"`
UserID string `json:"user_id,omitempty"`
APIKeyID string `json:"api_key_id,omitempty"`
Action string `json:"action"`
Resource string `json:"resource"`
Result string `json:"result"` // success, failure
Details map[string]interface{} `json:"details,omitempty"`
IPAddress string `json:"ip_address,omitempty"`
}
type AuditLog ¶
type AuditLog struct {
Enabled bool `json:"enabled,omitempty"`
RetentionDays int `json:"retention_days,omitempty"`
// contains filtered or unexported fields
}
func (*AuditLog) Log ¶
func (al *AuditLog) Log(entry AuditEntry)
type BurnRate ¶
type BurnRate struct {
Threshold float64 `json:"threshold"` // e.g., 0.02 for 2% error rate
Window string `json:"window"` // e.g., "1h", "6h"
Severity string `json:"severity"` // critical, warning
}
BurnRate defines multi-burn-rate alerting thresholds.
func (*BurnRate) ValidateBurnRate ¶
ValidateBurnRate checks if a burn rate threshold is exceeded.
type CaddyMonitor ¶
type CaddyMonitor struct {
MetricsConfig *MetricsCollector `json:"metrics,omitempty"`
AlertingConfig *AlertManager `json:"alerting,omitempty"`
TenantsConfig *MultiTenancy `json:"tenants,omitempty"`
SLOConfig *SLOManager `json:"slos,omitempty"`
TracingConfig *DistributedTracer `json:"tracing,omitempty"`
StorageConfig *DataStore `json:"storage,omitempty"`
RBACConfig *RBACManager `json:"rbac,omitempty"`
AuditConfig *AuditLog `json:"audit,omitempty"`
ComplianceConfig *ComplianceManager `json:"compliance,omitempty"`
// contains filtered or unexported fields
}
CaddyMonitor is the main plugin module for enterprise monitoring.
func (*CaddyMonitor) CaddyModule ¶
func (*CaddyMonitor) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*CaddyMonitor) Provision ¶
func (m *CaddyMonitor) Provision(ctx caddy.Context) error
Provision sets up the module.
func (*CaddyMonitor) Start ¶
func (m *CaddyMonitor) Start() error
Start starts the monitoring services.
func (*CaddyMonitor) UnmarshalCaddyfile ¶
func (m *CaddyMonitor) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile implements caddyfile.Unmarshaler.
type ComplianceManager ¶
type ComplianceManager struct {
Enabled bool `json:"enabled,omitempty"`
Encryption *EncryptionConfig `json:"encryption,omitempty"`
PIIMasking *PIIMaskingConfig `json:"pii_masking,omitempty"`
Retention *RetentionConfig `json:"retention,omitempty"`
Reporting *ReportingConfig `json:"reporting,omitempty"`
// contains filtered or unexported fields
}
func (*ComplianceManager) DecryptData ¶
func (cm *ComplianceManager) DecryptData(data []byte) ([]byte, error)
func (*ComplianceManager) EncryptData ¶
func (cm *ComplianceManager) EncryptData(data []byte) ([]byte, error)
func (*ComplianceManager) GenerateComplianceReport ¶
func (cm *ComplianceManager) GenerateComplianceReport(reportType string) (*ComplianceReport, error)
func (*ComplianceManager) MaskPII ¶
func (cm *ComplianceManager) MaskPII(text string) string
type ComplianceReport ¶
type ComplianceReport struct {
GeneratedAt time.Time `json:"generated_at"`
ReportType string `json:"report_type"`
ComplianceMode string `json:"compliance_mode"`
Summary map[string]interface{} `json:"summary"`
Violations []string `json:"violations,omitempty"`
Recommendations []string `json:"recommendations,omitempty"`
}
type DataRetentionManager ¶
type DataRetentionManager struct {
// contains filtered or unexported fields
}
func NewDataRetentionManager ¶
func NewDataRetentionManager(config *RetentionConfig, logger *zap.Logger) *DataRetentionManager
func (*DataRetentionManager) CleanupExpiredData ¶
func (drm *DataRetentionManager) CleanupExpiredData() error
func (*DataRetentionManager) GetRetentionPolicy ¶
func (drm *DataRetentionManager) GetRetentionPolicy() map[string]interface{}
type DataStore ¶
type DataStore struct {
Backend string `json:"backend"` // prometheus, victoriametrics, influxdb
URL string `json:"url"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Database string `json:"database,omitempty"`
Retention string `json:"retention,omitempty"`
// contains filtered or unexported fields
}
func (*DataStore) WriteMetrics ¶
type DistributedTracer ¶
type DistributedTracer struct {
Enabled bool `json:"enabled,omitempty"`
Sampler *SamplerConfig `json:"sampler,omitempty"`
Exporter *ExporterConfig `json:"exporter,omitempty"`
// contains filtered or unexported fields
}
func (*DistributedTracer) ExtractHTTPHeaders ¶
func (dt *DistributedTracer) ExtractHTTPHeaders(r *http.Request) context.Context
func (*DistributedTracer) InjectHTTPHeaders ¶
func (dt *DistributedTracer) InjectHTTPHeaders(ctx context.Context, r *http.Request)
func (*DistributedTracer) RecordHTTPRequest ¶
type EncryptionConfig ¶
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
func NewEncryptor ¶
type ErrorBudget ¶
type ErrorBudget struct {
Total float64 `json:"total"` // Total error budget for window
Consumed float64 `json:"consumed"` // Amount consumed so far
Remaining float64 `json:"remaining"` // Remaining budget
UpdatedAt time.Time `json:"updated_at"`
}
ErrorBudget tracks remaining error budget.
type EscalationPolicy ¶
type EscalationPolicy struct {
RuleName string `json:"rule_name"`
Escalations []*AlertEscalation `json:"escalations"`
// contains filtered or unexported fields
}
func (*EscalationPolicy) CheckEscalation ¶
func (ep *EscalationPolicy) CheckEscalation(alert *Alert) *AlertEscalation
func (*EscalationPolicy) Reset ¶
func (ep *EscalationPolicy) Reset()
type ExporterConfig ¶
type InfluxDBBackend ¶
type InfluxDBBackend struct {
// contains filtered or unexported fields
}
func (*InfluxDBBackend) Close ¶
func (ib *InfluxDBBackend) Close() error
type MetricProvider ¶
type MetricsCollector ¶
type MetricsCollector struct {
Enabled bool `json:"enabled,omitempty"`
PerHost bool `json:"per_host,omitempty"`
PerRoute bool `json:"per_route,omitempty"`
Retention string `json:"retention,omitempty"`
CardinalityLimit int `json:"cardinality_limit,omitempty"`
// contains filtered or unexported fields
}
MetricsCollector handles metrics collection.
func (*MetricsCollector) MetricValue ¶
func (mc *MetricsCollector) MetricValue(name string) (float64, error)
func (*MetricsCollector) RecordHTTPRequest ¶
func (*MetricsCollector) RecordRequest ¶
func (mc *MetricsCollector) RecordRequest(labels prometheus.Labels, duration time.Duration) error
RecordRequest records an HTTP request metric.
type MonitorAPI ¶
type MonitorAPI struct {
BasePath string `json:"base_path,omitempty"`
// contains filtered or unexported fields
}
func (MonitorAPI) CaddyModule ¶
func (MonitorAPI) CaddyModule() caddy.ModuleInfo
func (*MonitorAPI) ServeHTTP ¶
func (api *MonitorAPI) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
type MonitorMiddleware ¶
type MonitorMiddleware struct {
TenantID string `json:"tenant_id,omitempty"`
// contains filtered or unexported fields
}
func (MonitorMiddleware) CaddyModule ¶
func (MonitorMiddleware) CaddyModule() caddy.ModuleInfo
func (*MonitorMiddleware) Provision ¶
func (m *MonitorMiddleware) Provision(ctx caddy.Context) error
func (*MonitorMiddleware) ServeHTTP ¶
func (m *MonitorMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
type MultiTenancy ¶
type MultiTenancy struct {
Enabled bool `json:"enabled,omitempty"`
AutoDetectFrom string `json:"auto_detect_from,omitempty"` // header, subdomain, path
HeaderName string `json:"header_name,omitempty"` // e.g., X-Tenant-ID
Tenants []Tenant `json:"tenants,omitempty"`
// contains filtered or unexported fields
}
MultiTenancy handles tenant isolation and RBAC.
func (*MultiTenancy) AuthorizeTenant ¶
func (mt *MultiTenancy) AuthorizeTenant(tenantID string) error
func (*MultiTenancy) GetTenant ¶
func (mt *MultiTenancy) GetTenant(tenantID string) (*Tenant, error)
GetTenant retrieves a tenant by ID.
func (*MultiTenancy) GetTenantStats ¶
func (mt *MultiTenancy) GetTenantStats(tenantID string) (map[string]int64, error)
func (*MultiTenancy) ListTenants ¶
func (mt *MultiTenancy) ListTenants() []*Tenant
ListTenants returns all registered tenants.
func (*MultiTenancy) RecordRequest ¶
func (mt *MultiTenancy) RecordRequest(tenantID string, statusCode int)
func (*MultiTenancy) RegisterTenant ¶
func (mt *MultiTenancy) RegisterTenant(tenant *Tenant) error
RegisterTenant adds a new tenant.
func (*MultiTenancy) ResolveTenantID ¶
func (mt *MultiTenancy) ResolveTenantID(r *http.Request) string
type PIIMasker ¶
type PIIMasker struct {
// contains filtered or unexported fields
}
func NewPIIMasker ¶
func NewPIIMasker(config *PIIMaskingConfig) *PIIMasker
type PIIMaskingConfig ¶
type PIIMaskingConfig struct {
Enabled bool `json:"enabled,omitempty"`
MaskFields []string `json:"mask_fields,omitempty"`
MaskEmail bool `json:"mask_email,omitempty"`
MaskPhone bool `json:"mask_phone,omitempty"`
MaskIP bool `json:"mask_ip,omitempty"`
MaskCreditCard bool `json:"mask_credit_card,omitempty"`
}
type Permission ¶
type Permission string
const ( PermissionMetricsRead Permission = "metrics:read" PermissionMetricsWrite Permission = "metrics:write" PermissionAlertsRead Permission = "alerts:read" PermissionAlertsWrite Permission = "alerts:write" PermissionTenantsRead Permission = "tenants:read" PermissionTenantsWrite Permission = "tenants:write" PermissionSLORead Permission = "slo:read" PermissionSLOWrite Permission = "slo:write" PermissionAuditRead Permission = "audit:read" )
type PrometheusBackend ¶
type PrometheusBackend struct {
// contains filtered or unexported fields
}
func (*PrometheusBackend) Close ¶
func (pb *PrometheusBackend) Close() error
type RBACManager ¶
type RBACManager struct {
Enabled bool `json:"enabled,omitempty"`
// contains filtered or unexported fields
}
func (*RBACManager) CreateAPIKey ¶
func (*RBACManager) HasPermission ¶
func (rbac *RBACManager) HasPermission(apiKey *APIKey, permission Permission) bool
func (*RBACManager) ListAPIKeys ¶
func (rbac *RBACManager) ListAPIKeys(tenantID string) []*APIKey
func (*RBACManager) RevokeAPIKey ¶
func (rbac *RBACManager) RevokeAPIKey(keyID string) error
func (*RBACManager) ValidateAPIKey ¶
func (rbac *RBACManager) ValidateAPIKey(key string) (*APIKey, error)
type ReportingConfig ¶
type RetentionConfig ¶
type RetentionConfig struct {
MetricsRetentionDays int `json:"metrics_retention_days,omitempty"`
TracesRetentionDays int `json:"traces_retention_days,omitempty"`
LogsRetentionDays int `json:"logs_retention_days,omitempty"`
AuditRetentionDays int `json:"audit_retention_days,omitempty"`
AutoCleanup bool `json:"auto_cleanup,omitempty"`
ComplianceMode string `json:"compliance_mode,omitempty"` // sox, gdpr, hipaa, iso27001
}
type SLO ¶
type SLO struct {
Name string `json:"name"`
Target float64 `json:"target"` // e.g., 99.9 for 99.9%
Window string `json:"window"` // e.g., "30d"
BurnRates []*BurnRate `json:"burn_rates,omitempty"`
ErrorBudget *ErrorBudget `json:"error_budget,omitempty"`
}
SLO defines a Service Level Objective.
func (*SLO) CalculateErrorBudget ¶
func (s *SLO) CalculateErrorBudget(totalRequests, failedRequests int64) *ErrorBudget
CalculateErrorBudget calculates error budget for an SLO.
type SLOManager ¶
type SLOManager struct {
SLOs []*SLO `json:"slos,omitempty"`
// contains filtered or unexported fields
}
SLOManager handles Service Level Objective monitoring.
func (*SLOManager) CheckBurnRate ¶
func (sm *SLOManager) CheckBurnRate(br *BurnRate) bool
CheckBurnRate checks if a burn rate threshold is exceeded.
func (*SLOManager) Provision ¶
func (sm *SLOManager) Provision(logger *zap.Logger) error
Provision sets up the SLO manager.
func (*SLOManager) RecordResult ¶
func (sm *SLOManager) RecordResult(statusCode int, duration time.Duration)
RecordResult records the result of a request.
type SamplerConfig ¶
type StorageBackend ¶
type Tenant ¶
type Tenant struct {
ID string `json:"id"`
Name string `json:"name"`
Quota *TenantQuota `json:"quota,omitempty"`
Roles []string `json:"roles,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
// contains filtered or unexported fields
}
Tenant represents a single tenant configuration.
type TenantQuota ¶
type TenantQuota struct {
MaxRequests int64 `json:"max_requests,omitempty"`
MaxMetrics int64 `json:"max_metrics,omitempty"`
MaxAlerts int `json:"max_alerts,omitempty"`
RateLimitRPS int `json:"rate_limit_rps,omitempty"`
}
TenantQuota defines resource limits for a tenant.
type VictoriaMetricsBackend ¶
type VictoriaMetricsBackend struct {
// contains filtered or unexported fields
}
func (*VictoriaMetricsBackend) Close ¶
func (vm *VictoriaMetricsBackend) Close() error
type WebhookConfig ¶
WebhookConfig configures webhook notifications.