monitors

package
v0.4.149 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package monitors watches the addresses the owner names: each is asked every minute by the box, dashboard open or not, and the owner hears when one stops answering and when it answers again.

An address answers when its status is 2xx or 3xx: a redirect to a sign-in page is an app that lives. It is down after three failed reads in a row. The state is kept in memory: a restart of the core starts every address anew.

Index

Constants

View Source
const (
	Pending = "pending" // not read yet, or never answered and not down yet
	Up      = "up"
	Down    = "down"
)

The states of an address.

View Source
const ConfigFile = "/var/lib/casaos/monitors.json"

ConfigFile holds the addresses (root, 0600: a query may carry a key).

Variables

View Source
var (
	ErrNotFound = errors.New("no such address")
	// ErrInvalid is a change the box refuses; its text says what.
	ErrInvalid = errors.New("the address is refused")
	// ErrFile is a monitors.json that cannot be read: nothing is written over it.
	ErrFile = errors.New("the file of the addresses cannot be read: nothing was written")
)
View Source
var Default = New("/")

Default is the box's own.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	Root string
	Now  func() time.Time
	// Changed is told when an address goes down (with why) and when it answers again; since is the first failed
	// read of that outage, the same in both calls. Set before Run.
	Changed func(id, name, reason string, since time.Time, down bool)
	// Paused says whether the reads are to be skipped now: an update of Docker stops every app. Set before Run.
	Paused func() bool
	// contains filtered or unexported fields
}

Hub is the watched addresses of one box.

func New

func New(root string) *Hub

New keeps monitors.json under root and reads through the guarded client.

func (*Hub) Create

func (h *Hub) Create(m Monitor) (View, error)

Create adds an address, twenty at most, and reads it at once.

func (*Hub) Delete

func (h *Hub) Delete(id string) error

Delete removes an address and what was known of it.

func (*Hub) List

func (h *Hub) List() ([]View, error)

List is the addresses, in the order they were added, each with its state.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run reads every address each minute, the first time five minutes after the start.

func (*Hub) Update

func (h *Hub) Update(id string, m Monitor) (View, error)

Update replaces an address. When what is read changes, its state starts anew and it is read at once.

type Monitor

type Monitor struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	URL         string `json:"url"`
	InsecureTLS bool   `json:"insecure_tls"`
}

Monitor is one address to watch.

type View

type View struct {
	Monitor
	Status string `json:"status"`
	// Code and Millis are the status and the time to the answer of the last read; Error is why it failed.
	Code   int    `json:"code,omitempty"`
	Millis int64  `json:"ms,omitempty"`
	Error  string `json:"error,omitempty"`
	// Since is when the address went up, or the first failed read of the outage.
	Since   *time.Time `json:"since,omitempty"`
	Checked *time.Time `json:"checked,omitempty"`
}

View is an address and what its last read said.

Jump to

Keyboard shortcuts

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