monitor

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package monitor implements dead man's switches.

Index

Constants

View Source
const (
	// HealthchecksDefaultTimeout is the default timeout for a Healthchecks ping.
	HealthchecksDefaultTimeout = 10 * time.Second
)
View Source
const (
	// UptimeKumaDefaultTimeout is the default timeout for a UptimeKuma ping.
	UptimeKumaDefaultTimeout = 10 * time.Second
)

Variables

This section is empty.

Functions

func DescribeAll added in v1.9.3

func DescribeAll(callback func(service, params string), ms []Monitor)

DescribeAll calls [Monitor.Describe] for each monitor in the group with the callback.

func ExitStatusAll

func ExitStatusAll(ctx context.Context, ppfmt pp.PP, code int, message string, ms []Monitor) bool

ExitStatusAll calls [Monitor.ExitStatus] for each monitor in ms.

func FailureAll

func FailureAll(ctx context.Context, ppfmt pp.PP, message string, ms []Monitor) bool

FailureAll calls [Monitor.Failure] for each monitor in ms.

func LogAll added in v1.9.3

func LogAll(ctx context.Context, ppfmt pp.PP, message string, ms []Monitor) bool

LogAll calls [Monitor.Log] for each monitor in ms.

func StartAll

func StartAll(ctx context.Context, ppfmt pp.PP, message string, ms []Monitor) bool

StartAll calls [Monitor.Start] for each monitor in ms.

func SuccessAll

func SuccessAll(ctx context.Context, ppfmt pp.PP, message string, ms []Monitor) bool

SuccessAll calls [Monitor.Success] for each monitor in the group.

Types

type Healthchecks added in v1.8.0

type Healthchecks struct {
	// The success endpoint that can be used to derive all other endpoints.
	BaseURL *url.URL

	// Timeout for each ping.
	Timeout time.Duration
}

Healthchecks represents a Healthchecks access point. See https://healthchecks.io/docs/http_api/ for more information.

func (*Healthchecks) Describe added in v1.8.0

func (h *Healthchecks) Describe(callback func(service, params string))

Describe calls the callback with the service name "Healthchecks".

func (*Healthchecks) ExitStatus added in v1.8.0

func (h *Healthchecks) ExitStatus(ctx context.Context, ppfmt pp.PP, code int, message string) bool

ExitStatus pings the /number endpoint where number is the exit status.

func (*Healthchecks) Failure added in v1.8.0

func (h *Healthchecks) Failure(ctx context.Context, ppfmt pp.PP, message string) bool

Failure pings the /fail endpoint.

func (*Healthchecks) Log added in v1.8.0

func (h *Healthchecks) Log(ctx context.Context, ppfmt pp.PP, message string) bool

Log pings the /log endpoint.

func (*Healthchecks) Start added in v1.8.0

func (h *Healthchecks) Start(ctx context.Context, ppfmt pp.PP, message string) bool

Start pings the /start endpoint.

func (*Healthchecks) Success added in v1.8.0

func (h *Healthchecks) Success(ctx context.Context, ppfmt pp.PP, message string) bool

Success pings the root endpoint.

type Monitor

type Monitor interface {
	// Describe a monitor in a human-readable format by calling callback with service names and params.
	Describe(callback func(service, params string))

	// Success pings the monitor to prevent notifications.
	Success(ctx context.Context, ppfmt pp.PP, message string) bool

	// Start pings the monitor with the start signal.
	Start(ctx context.Context, ppfmt pp.PP, message string) bool

	// Failure immediately signals the monitor to notify the user.
	Failure(ctx context.Context, ppfmt pp.PP, message string) bool

	// Log provides additional inforamion without changing the state.
	Log(ctx context.Context, ppfmt pp.PP, message string) bool

	// ExitStatus records the exit status (as an integer in the POSIX style).
	ExitStatus(ctx context.Context, ppfmt pp.PP, code int, message string) bool
}

Monitor is a dead man's switch, meaning that the user will be notified when the updater fails to detect and update the public IP address. No notifications for IP changes.

func NewHealthchecks added in v1.8.0

func NewHealthchecks(ppfmt pp.PP, rawURL string) (Monitor, bool)

NewHealthchecks creates a new Healthchecks monitor. See https://healthchecks.io/docs/http_api/ for more information.

func NewUptimeKuma added in v1.11.0

func NewUptimeKuma(ppfmt pp.PP, rawURL string) (Monitor, bool)

NewUptimeKuma creates a new UptimeKuma monitor.

type UptimeKuma added in v1.11.0

type UptimeKuma struct {
	// The endpoint
	BaseURL *url.URL

	// Timeout for each ping
	Timeout time.Duration
}

UptimeKuma provides basic support of Uptime Kuma.

  • ExitStatus, Start, and Log will be no-op.
  • Success/Fail will be translated to status=up/down
  • Messages will be sent along with Success/Fail, but it seems Uptime Kuma will only display the first one.
  • ping will always be empty

func (*UptimeKuma) Describe added in v1.11.0

func (h *UptimeKuma) Describe(callback func(service, params string))

Describe calls the callback with the service name "Uptime Kuma".

func (*UptimeKuma) ExitStatus added in v1.11.0

func (h *UptimeKuma) ExitStatus(ctx context.Context, ppfmt pp.PP, code int, message string) bool

ExitStatus with non-zero triggers [Failure]. Otherwise, it does nothing.

func (*UptimeKuma) Failure added in v1.11.0

func (h *UptimeKuma) Failure(ctx context.Context, ppfmt pp.PP, message string) bool

Failure pings the server with status=down.

func (*UptimeKuma) Log added in v1.11.0

func (h *UptimeKuma) Log(ctx context.Context, ppfmt pp.PP, message string) bool

Log does nothing.

func (*UptimeKuma) Start added in v1.11.0

func (h *UptimeKuma) Start(ctx context.Context, ppfmt pp.PP, message string) bool

Start does nothing.

func (*UptimeKuma) Success added in v1.11.0

func (h *UptimeKuma) Success(ctx context.Context, ppfmt pp.PP, _message string) bool

Success pings the server with status=up. Messages are ignored and "OK" is used instead. The reason is that Uptime Kuma seems to show only the first success message and it could be misleading if an outdated message stays in the UI.

type UptimeKumaRequest added in v1.11.0

type UptimeKumaRequest struct {
	Status string `url:"status"`
	Msg    string `url:"msg"`
	Ping   string `url:"ping"`
}

UptimeKumaRequest is for assembling the request to Uptime Kuma.

type UptimeKumaResponse added in v1.11.0

type UptimeKumaResponse struct {
	Ok  bool   `json:"ok"`
	Msg string `json:"msg"`
}

UptimeKumaResponse is for parsing the response from Uptime Kuma.

Jump to

Keyboard shortcuts

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