Documentation
¶
Index ¶
- type Check
- type CheckResult
- type CheckSummary
- type Engine
- func (e *Engine) CreateCheck(check Check) error
- func (e *Engine) DeleteCheck(id string) error
- func (e *Engine) SetFailureCallback(cb FailureCallback)
- func (e *Engine) StartAll()
- func (e *Engine) Store() Store
- func (e *Engine) Summary() ([]CheckSummary, error)
- func (e *Engine) UpdateCheck(check Check) error
- type EngineConfig
- type FailureCallback
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Method string `json:"method"` // GET, POST, etc.
ExpectedStatus int `json:"expected_status"` // 200, 201, etc.
Interval time.Duration `json:"interval"` // check interval
Timeout time.Duration `json:"timeout"` // request timeout
Headers map[string]string `json:"headers"`
Enabled bool `json:"enabled"`
}
Check defines an endpoint to monitor.
type CheckResult ¶
type CheckResult struct {
CheckID string `json:"check_id"`
Timestamp time.Time `json:"timestamp"`
StatusCode int `json:"status_code"`
ResponseMs float64 `json:"response_ms"`
Success bool `json:"success"`
Error string `json:"error,omitempty"`
}
CheckResult records the outcome of a single check execution.
type CheckSummary ¶
type CheckSummary struct {
Check Check `json:"check"`
Uptime24h float64 `json:"uptime_24h"` // percentage
Uptime7d float64 `json:"uptime_7d"`
Uptime30d float64 `json:"uptime_30d"`
AvgResponseMs float64 `json:"avg_response_ms"`
LastResult *CheckResult `json:"last_result,omitempty"`
LastFailure *CheckResult `json:"last_failure,omitempty"`
}
CheckSummary provides an overview of a check's status and history.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs periodic uptime checks using a worker pool.
func NewEngine ¶
func NewEngine(store Store, pool *worker.Pool, cfg EngineConfig) *Engine
NewEngine creates an uptime engine.
func (*Engine) CreateCheck ¶
CreateCheck creates a new check and starts scheduling it if enabled.
func (*Engine) DeleteCheck ¶
DeleteCheck deletes a check and stops its schedule.
func (*Engine) SetFailureCallback ¶
func (e *Engine) SetFailureCallback(cb FailureCallback)
SetFailureCallback sets the callback for consecutive failures.
func (*Engine) StartAll ¶
func (e *Engine) StartAll()
StartAll schedules all enabled checks. Call this once at startup.
func (*Engine) Summary ¶
func (e *Engine) Summary() ([]CheckSummary, error)
Summary returns summaries for all checks.
func (*Engine) UpdateCheck ¶
UpdateCheck updates a check and reschedules it.
type EngineConfig ¶
type EngineConfig struct {
// ConsecutiveFailuresThreshold is the number of consecutive failures
// before the failure callback is triggered. Default 3.
ConsecutiveFailuresThreshold int
}
EngineConfig holds configuration for the uptime engine.
func DefaultEngineConfig ¶
func DefaultEngineConfig() EngineConfig
DefaultEngineConfig returns sensible defaults.
type FailureCallback ¶
type FailureCallback func(check Check, consecutiveFailures int, lastResult CheckResult)
FailureCallback is called when a check has N consecutive failures.
type Store ¶
type Store interface {
// CreateCheck persists a new check.
CreateCheck(check Check) error
// UpdateCheck updates an existing check.
UpdateCheck(check Check) error
// DeleteCheck removes a check and its results.
DeleteCheck(id string) error
// GetCheck returns a check by ID.
GetCheck(id string) (*Check, error)
// ListChecks returns all checks.
ListChecks() ([]Check, error)
// AddResult appends a check result (circular buffer per check).
AddResult(result CheckResult) error
// Results returns the result history for a check, newest first.
Results(checkID string) ([]CheckResult, error)
// LastResult returns the most recent result for a check.
LastResult(checkID string) (*CheckResult, error)
// LastFailure returns the most recent failed result for a check.
LastFailure(checkID string) (*CheckResult, error)
// ConsecutiveFailures returns the number of consecutive failures
// for a check (counting backwards from the most recent result).
ConsecutiveFailures(checkID string) int
}
Store defines the interface for persisting uptime checks and results.