Documentation
¶
Index ¶
- Constants
- Variables
- type AlertConfig
- type AlertDecision
- type AlertEvent
- type AlertHook
- type AlertState
- type AlertStateStore
- type Background
- type CleanupOptions
- type Config
- type DailyStatus
- type DayStatus
- type Heartbeat
- type IDGenerator
- type Instance
- type Language
- type Logger
- type QueryDailyOptions
- type QueryTodaySamplesOptions
- type RollupOptions
- type Service
- type ServiceStatus
- type Snapshot
- type SnapshotConfig
- type StatusResponse
- type StorageResponse
- type Store
- type Theme
- type TodaySampleStatus
- type UIConfig
- type Uptime
- func (u *Uptime) CachedSnapshot(ctx context.Context) (Snapshot, error)
- func (u *Uptime) Close() error
- func (u *Uptime) Handler() http.Handler
- func (u *Uptime) LastError() (error, time.Time)
- func (u *Uptime) Middleware(next http.Handler) http.Handler
- func (u *Uptime) Snapshot(ctx context.Context) (Snapshot, error)
Constants ¶
const ( AlertStatusUp = "up" AlertStatusDown = "down" )
Variables ¶
var ( ErrMissingServiceID = errors.New("uptime: service id is required") ErrMissingStore = errors.New("uptime: store is required") )
Functions ¶
This section is empty.
Types ¶
type AlertConfig ¶
AlertConfig controls optional status-transition notifications.
type AlertDecision ¶
type AlertEvent ¶
type AlertEvent struct {
ServiceID string `json:"service_id"`
ServiceName string `json:"service_name"`
Description string `json:"description,omitempty"`
PreviousStatus string `json:"previous_status"`
CurrentStatus string `json:"current_status"`
LastSeenAt time.Time `json:"last_seen_at"`
DetectedAt time.Time `json:"detected_at"`
SampleInterval time.Duration `json:"sample_interval"`
DownFor time.Duration `json:"down_for"`
}
AlertEvent describes one service status transition.
type AlertHook ¶
type AlertHook func(context.Context, AlertEvent) error
AlertHook receives deduplicated service status transitions.
Hooks are optional. They are called after the shared store has claimed the transition, so built-in stores avoid duplicate notifications across multiple processes using the same SQLite or PostgreSQL storage.
type AlertState ¶
type AlertStateStore ¶
type AlertStateStore interface {
ClaimAlertEvent(ctx context.Context, state AlertState) (AlertDecision, error)
}
AlertStateStore persists alert state for cross-instance de-duplication.
type Background ¶
type Background string
Background controls the dashboard page background.
const ( BackgroundSolid Background = "solid" BackgroundGrid Background = "grid" )
type CleanupOptions ¶
type Config ¶
type Config struct {
ServiceID string
ServiceName string
ServiceDescription string
SampleInterval time.Duration
RetentionDays int
DaysToShow int
Timezone *time.Location
NodeID int64
InstanceID int64
IDGenerator IDGenerator
Store Store
Alert AlertConfig
Snapshot SnapshotConfig
UI UIConfig
Logger Logger
}
Config controls an uptime recorder.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the runtime defaults. ServiceID and Store must still be set.
type DailyStatus ¶
type DailyStatus struct {
ServiceID string
Day string
UpSlots int
ExpectedSlots int
UptimeRate float64
Finalized bool
}
DailyStatus is a finalized service-level day snapshot.
type DayStatus ¶
type DayStatus struct {
Day string `json:"day"`
UptimeRate float64 `json:"uptime_rate"`
UpSlots int `json:"up_slots"`
ExpectedSlots int `json:"expected_slots"`
EstimatedDowntimeSeconds int64 `json:"estimated_downtime_seconds"`
Finalized bool `json:"finalized"`
HasData bool `json:"has_data"`
Status string `json:"status"`
}
type IDGenerator ¶
type IDGenerator interface {
NextID() int64
}
IDGenerator generates instance IDs.
type Instance ¶
type Instance struct {
ID int64
ServiceID string
Hostname string
PID int
StartedAt time.Time
LastSeenAt time.Time
}
Instance describes one process lifetime of a service.
type QueryDailyOptions ¶
type QueryTodaySamplesOptions ¶
type QueryTodaySamplesOptions struct {
Day string
}
type RollupOptions ¶
type Service ¶
type Service struct {
ID string
Name string
Description string
CreatedAt time.Time
LastSeenAt time.Time
SampleInterval time.Duration
}
Service is the logical service identity shown on the dashboard.
type ServiceStatus ¶
type ServiceStatus struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
LastSeenAt time.Time `json:"last_seen_at"`
CurrentStatus string `json:"current_status"`
SampleIntervalSeconds int64 `json:"sample_interval_seconds"`
Daily []DayStatus `json:"daily"`
}
type Snapshot ¶
type Snapshot = StatusResponse
Snapshot is the current uptime status payload used by the JSON API.
type SnapshotConfig ¶
type SnapshotConfig struct {
// CacheTTL controls how long a cached snapshot is reused. It defaults to
// SampleInterval. Set DisableCache to true for a direct store query on every
// CachedSnapshot call.
CacheTTL time.Duration
// DisableCache makes CachedSnapshot behave like Snapshot.
DisableCache bool
// DisableStaleIfError returns store errors instead of a stale snapshot when
// a refresh fails and a previous snapshot is available.
DisableStaleIfError bool
}
SnapshotConfig controls the in-memory snapshot cache used by CachedSnapshot and the built-in dashboard/API handlers.
type StatusResponse ¶
type StatusResponse struct {
GeneratedAt time.Time `json:"generated_at"`
SampleIntervalSeconds int64 `json:"sample_interval_seconds"`
Days int `json:"days"`
Storage StorageResponse `json:"storage"`
Services []ServiceStatus `json:"services"`
}
type StorageResponse ¶
type Store ¶
type Store interface {
Init(ctx context.Context) error
UpsertService(ctx context.Context, service Service) error
UpsertInstance(ctx context.Context, instance Instance) error
WriteHeartbeat(ctx context.Context, heartbeat Heartbeat) error
RollupDaily(ctx context.Context, options RollupOptions) error
Cleanup(ctx context.Context, options CleanupOptions) error
ListServices(ctx context.Context) ([]Service, error)
QueryDaily(ctx context.Context, options QueryDailyOptions) ([]DailyStatus, error)
QueryTodaySamples(ctx context.Context, options QueryTodaySamplesOptions) ([]TodaySampleStatus, error)
Close() error
}
Store persists uptime state. Implementations must be safe for concurrent use.
type TodaySampleStatus ¶
TodaySampleStatus is the current raw service-level summary for one day.
type UIConfig ¶
type UIConfig struct {
Title string
Path string
Description string
DefaultTheme Theme
DefaultLanguage Language
Background Background
GreenThreshold float64
YellowThreshold float64
ShowInstanceDetails bool
}
UIConfig controls the built-in status page.
type Uptime ¶
type Uptime struct {
// contains filtered or unexported fields
}
Uptime records service heartbeats and serves uptime history.
func (*Uptime) CachedSnapshot ¶
CachedSnapshot returns a status snapshot through Uptime's in-memory cache.
It is intended for dashboards, custom pages, and user-managed cache layers that should not hit the store for every request. When a refresh fails and a previous snapshot exists, CachedSnapshot returns the stale snapshot with degraded storage status unless Snapshot.DisableStaleIfError is enabled.
func (*Uptime) Middleware ¶
Middleware is a no-op net/http middleware in v0.1.0.
Heartbeats are written by the background recorder, so uptime works even when the middleware is not installed on the business handler.