status

package module
v0.0.0-...-aca2af5 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 12 Imported by: 0

README

status

Run Tests Go Report Card GoDoc

A Go package for health checking and status page generation. It provides a simple way to monitor the health of various dependencies and services in your application, with a status page dashboard.

Usage

import (
    "time"

    "github.com/alarmistdev/status/check"
    dockercheck "github.com/alarmistdev/status/check/system/docker"
)

dockerCheck, err := dockercheck.Check(
    map[string]string{"app": "status", "env": "prod"},
    30*time.Second,           // background refresh interval
    check.Config{Timeout: 5 * time.Second},
)
if err != nil {
    log.Fatalf("docker check init failed: %v", err)
}
defer dockerCheck.Close()

healthChecker.WithTarget("Status containers", dockerCheck)

See example/main.go.

Documentation

Overview

Package status provides functionality for health checking and status page generation in Go applications. It allows monitoring of various dependencies and services with different importance levels.

Index

Constants

View Source
const (
	// TargetImportanceLow indicates that the target is not critical for the application.
	TargetImportanceLow = TargetImportance("low")
	// TargetImportanceHigh indicates that the target is critical for the application.
	TargetImportanceHigh = TargetImportance("high")
)
View Source
const (
	// HealthTargetStatusOk indicates that the target is healthy.
	HealthTargetStatusOk = HealthTargetStatus("ok")
	// HealthTargetStatusFail indicates that the target is unhealthy.
	HealthTargetStatusFail = HealthTargetStatus("fail")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conclusion

type Conclusion string
const (
	ConclusionOk      Conclusion = "Ok"
	ConclusionWarning Conclusion = "Warning"
	ConclusionFail    Conclusion = "Fail"
)

type HealthCheckResult

type HealthCheckResult struct {
	Target       HealthTarget       `json:"target"`
	Status       HealthTargetStatus `json:"status"`
	ErrorMessage string             `json:"error,omitempty"`
	Duration     time.Duration      `json:"duration,omitempty"`
	// contains filtered or unexported fields
}

HealthCheckResult contains the result of a health check for a target.

type HealthChecker

type HealthChecker struct {
	// contains filtered or unexported fields
}

HealthChecker manages a collection of health check targets and provides functionality to check their health status.

func NewHealthChecker

func NewHealthChecker() *HealthChecker

NewHealthChecker creates a new HealthChecker instance.

func (*HealthChecker) Check

Check performs health checks for all registered targets concurrently.

func (*HealthChecker) Handler

func (c *HealthChecker) Handler() http.HandlerFunc

func (*HealthChecker) WithTarget

func (c *HealthChecker) WithTarget(name string, check check.Check, opts ...TargetOption) *HealthChecker

WithTarget adds a new health check target to the checker.

type HealthGroup

type HealthGroup struct {
	Name    string
	Results []HealthCheckResult
}

HealthGroup represents a group of health check results.

type HealthTarget

type HealthTarget struct {
	Name       string           `json:"name"`
	Importance TargetImportance `json:"importance"`
	Icon       string           `json:"icon,omitempty"`
	Group      string           `json:"group,omitempty"`
	// contains filtered or unexported fields
}

HealthTarget represents a single health check target.

type HealthTargetStatus

type HealthTargetStatus string

HealthTargetStatus represents the status of a health check target.

type Link struct {
	Name string
	URL  string
}

Link represents a navigation link in the status page.

type Page

type Page struct {
	// contains filtered or unexported fields
}

Page represents a status page that can be served via HTTP.

func NewPage

func NewPage(opts ...PageOption) *Page

NewPage creates a new status page with the given options.

func (*Page) Handler

func (p *Page) Handler() http.HandlerFunc

Handler returns an HTTP handler that serves the status page.

type PageData

type PageData struct {
	Title         string
	Version       string
	Conclusion    Conclusion
	HealthResults []HealthCheckResult
	HealthGroups  []HealthGroup
	Links         []Link
}

PageData contains the data that will be rendered in the status page template.

type PageOption

type PageOption func(*Page)

PageOption is a function that configures a Page.

func WithHealthChecker

func WithHealthChecker(hc *HealthChecker) PageOption

WithHealthChecker sets the health checker for the status page.

func WithLink(name, url string) PageOption

WithLink adds a navigation link to the status page.

func WithTemplate

func WithTemplate(tmpl *template.Template) PageOption

WithTemplate sets a custom HTML template for the status page.

func WithTitle

func WithTitle(title string) PageOption

WithTitle sets the title of the status page.

func WithVersion

func WithVersion(show bool) PageOption

WithVersion configures whether to show version information on the status page.

type TargetImportance

type TargetImportance string

TargetImportance defines the importance level of a health check target.

type TargetOption

type TargetOption func(*HealthTarget)

TargetOption is a function that configures a HealthTarget.

func WithGroup

func WithGroup(group string) TargetOption

WithGroup sets the group name for a health check target. Targets with the same group name will be displayed together.

func WithIcon

func WithIcon(icon string) TargetOption

WithIcon sets the icon CSS class name for a health check target.

func WithImportance

func WithImportance(importance TargetImportance) TargetOption

WithImportance sets the importance level of a health check target.

Jump to

Keyboard shortcuts

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