Documentation
¶
Overview ¶
Package monitor keeps an eye on the things Mediarium depends on (Usenet servers, indexers) by checking each one on a schedule, remembering the last result, and raising a notification only when something changes state, so a server that stays down is reported once, not every cycle.
The package knows nothing about how a check is made: callers hand it a function that lists the current checks (internal/api wires in the real Usenet login and indexer probes), a clock and an interval, all injectable so the logic is testable without waiting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
Title string
Message string
Failing bool // false means "recovered"
Kind Kind // what sort of thing it is, and its name
Name string
Error string // what the failed check said, with credentials masked (empty when recovered)
}
Event is what the monitor asks to have announced: a check that started failing, or one that recovered.
type Monitor ¶
type Monitor struct {
// Checks lists what to test right now (the enabled servers and indexers).
Checks func(ctx context.Context) ([]Check, error)
// Interval is read before every wait, so a settings change takes effect on
// the next cycle. Zero or less means the monitor is off.
Interval func() time.Duration
// Notify announces a state change. May be nil.
Notify func(Event)
// Now is the clock (default time.Now).
Now func() time.Time
// After returns a channel that fires after d (default time.After); tests
// replace it to drive the loop without sleeping.
After func(d time.Duration) <-chan time.Time
// InitialDelay is how long the loop waits before its first pass, giving the
// network time to come up after a restart. Default one minute.
InitialDelay time.Duration
// OffPoll is how often an "off" monitor re-reads Interval to notice it was
// switched on. Default one minute.
OffPoll time.Duration
// contains filtered or unexported fields
}
Monitor runs checks and tracks their state. Fill in the function fields, then call Run (background loop) or RunOnce (a single pass).
func (*Monitor) Run ¶
Run loops until ctx is done: wait, run a pass, repeat. With the interval at zero it runs nothing, just keeps watching for the setting to change.