uptime

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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

func (e *Engine) CreateCheck(check Check) error

CreateCheck creates a new check and starts scheduling it if enabled.

func (*Engine) DeleteCheck

func (e *Engine) DeleteCheck(id string) error

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) Store

func (e *Engine) Store() Store

Store returns the underlying uptime store.

func (*Engine) Summary

func (e *Engine) Summary() ([]CheckSummary, error)

Summary returns summaries for all checks.

func (*Engine) UpdateCheck

func (e *Engine) UpdateCheck(check Check) error

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.

Directories

Path Synopsis
Package filestore implements uptime.Store backed by JSON files on disk.
Package filestore implements uptime.Store backed by JSON files on disk.

Jump to

Keyboard shortcuts

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