Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsoleAlertHandler ¶
func ConsoleAlertHandler(alert *Alert)
ConsoleAlertHandler prints alerts to console
Types ¶
type Alert ¶
type Alert struct {
Level AlertLevel
Type string
Message string
Query *ProcessedQuery
Timestamp time.Time
Metadata map[string]interface{}
}
Alert represents a monitoring alert
type AlertHandler ¶
type AlertHandler func(*Alert)
AlertHandler handles alerts when they are triggered
type AlertLevel ¶
type AlertLevel int
AlertLevel represents the severity of an alert
const ( AlertInfo AlertLevel = iota AlertWarning AlertError AlertCritical )
func (AlertLevel) String ¶
func (a AlertLevel) String() string
type AlertManager ¶
type AlertManager struct {
// contains filtered or unexported fields
}
AlertManager manages alert rules and notifications
func NewAlertManager ¶
func NewAlertManager() *AlertManager
NewAlertManager creates a new alert manager
func (*AlertManager) AddHandler ¶
func (am *AlertManager) AddHandler(handler AlertHandler)
AddHandler adds an alert handler
func (*AlertManager) AddRule ¶
func (am *AlertManager) AddRule(rule AlertRule)
AddRule adds an alert rule
func (*AlertManager) Check ¶
func (am *AlertManager) Check(pq *ProcessedQuery)
Check checks all rules against a processed query
func (*AlertManager) GetAlertCounts ¶
func (am *AlertManager) GetAlertCounts() map[AlertLevel]int64
GetAlertCounts returns the count of alerts by level
type AlertRule ¶
type AlertRule interface {
Check(pq *ProcessedQuery) *Alert
Name() string
}
AlertRule defines conditions for triggering alerts
type FullTableScanRule ¶
type FullTableScanRule struct{}
FullTableScanRule alerts on queries doing full table scans
func (*FullTableScanRule) Check ¶
func (r *FullTableScanRule) Check(pq *ProcessedQuery) *Alert
func (*FullTableScanRule) Name ¶
func (r *FullTableScanRule) Name() string
type LogProcessor ¶
type LogProcessor struct {
// contains filtered or unexported fields
}
LogProcessor processes log lines in real-time
func NewLogProcessor ¶
func NewLogProcessor(dialectName string) *LogProcessor
NewLogProcessor creates a new log processor
func (*LogProcessor) GetStatistics ¶
func (p *LogProcessor) GetStatistics() *Statistics
GetStatistics returns current processing statistics
func (*LogProcessor) SetQueryHandler ¶
func (p *LogProcessor) SetQueryHandler(handler func(*ProcessedQuery))
SetQueryHandler sets the callback for processed queries
type LogWatcher ¶
type LogWatcher struct {
// contains filtered or unexported fields
}
LogWatcher watches a log file for new entries and streams them
func NewLogWatcher ¶
func NewLogWatcher(filePath string) *LogWatcher
NewLogWatcher creates a new log file watcher
func (*LogWatcher) SetPollInterval ¶
func (w *LogWatcher) SetPollInterval(interval time.Duration)
SetPollInterval sets how often to check for new lines
func (*LogWatcher) Start ¶
func (w *LogWatcher) Start(ctx context.Context, lines chan<- string) error
Start begins watching the log file and sends new lines to the channel
func (*LogWatcher) StartWithTail ¶
TailMode starts watching from the last N lines instead of end of file
func (*LogWatcher) Stop ¶
func (w *LogWatcher) Stop()
Stop is a no-op: the watcher closes the file when its context is cancelled. Cancel the context passed to Start or StartWithTail to stop watching.
type OptimizationRule ¶
type OptimizationRule struct {
MinSeverity string // "low", "medium", "high"
}
OptimizationRule alerts on queries with optimization opportunities
func (*OptimizationRule) Check ¶
func (r *OptimizationRule) Check(pq *ProcessedQuery) *Alert
func (*OptimizationRule) Name ¶
func (r *OptimizationRule) Name() string
type ParseErrorRule ¶
type ParseErrorRule struct{}
ParseErrorRule alerts on query parse failures
func (*ParseErrorRule) Check ¶
func (r *ParseErrorRule) Check(pq *ProcessedQuery) *Alert
func (*ParseErrorRule) Name ¶
func (r *ParseErrorRule) Name() string
type ProcessedQuery ¶
type ProcessedQuery struct {
Timestamp time.Time
Query string
Duration float64
RowsAffected int64
Database string
User string
// Parsed information
Statement parser.Statement
Analysis *analyzer.QueryAnalysis
// Log metadata
LogFormat string
Severity string
}
ProcessedQuery represents a parsed query from a log
type SlowQueryRule ¶
type SlowQueryRule struct {
Threshold float64 // in seconds
}
SlowQueryRule alerts on queries exceeding a duration threshold
func (*SlowQueryRule) Check ¶
func (r *SlowQueryRule) Check(pq *ProcessedQuery) *Alert
func (*SlowQueryRule) Name ¶
func (r *SlowQueryRule) Name() string
type StatSnapshot ¶
type StatSnapshot struct {
TotalLines int64
ParsedQueries int64
FailedParses int64
SkippedLines int64
TotalDuration float64
SlowQueries int64
SlowThreshold float64
SelectCount int64
InsertCount int64
UpdateCount int64
DeleteCount int64
OtherCount int64
StartTime time.Time
LastQueryTime time.Time
Uptime time.Duration
}
StatSnapshot is a point-in-time snapshot of statistics
func (StatSnapshot) String ¶
func (s StatSnapshot) String() string
String returns a formatted string of the statistics
type Statistics ¶
type Statistics struct {
TotalLines int64
ParsedQueries int64
FailedParses int64
SkippedLines int64
// Query performance
TotalDuration float64
SlowQueries int64
SlowThreshold float64
// By query type
SelectCount int64
InsertCount int64
UpdateCount int64
DeleteCount int64
OtherCount int64
// Timing
StartTime time.Time
LastQueryTime time.Time
// contains filtered or unexported fields
}
Statistics tracks processing statistics
func NewStatistics ¶
func NewStatistics() *Statistics
NewStatistics creates a new statistics tracker
func (*Statistics) GetSnapshot ¶
func (s *Statistics) GetSnapshot() StatSnapshot
GetSnapshot returns a snapshot of current statistics
func (*Statistics) IncrementParseFailed ¶
func (s *Statistics) IncrementParseFailed()
IncrementParseFailed increments the failed parse counter
func (*Statistics) IncrementParsed ¶
func (s *Statistics) IncrementParsed()
IncrementParsed increments the parsed queries counter
func (*Statistics) IncrementSkipped ¶
func (s *Statistics) IncrementSkipped()
IncrementSkipped increments the skipped lines counter
func (*Statistics) RecordQuery ¶
func (s *Statistics) RecordQuery(pq *ProcessedQuery)
RecordQuery records statistics for a processed query
func (*Statistics) SetSlowThreshold ¶
func (s *Statistics) SetSlowThreshold(threshold float64)
SetSlowThreshold sets the threshold for slow queries in seconds