health

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareThreshold

func CompareThreshold[T comparable](value, threshold T, compareFn func(T, T) bool) bool

CompareThreshold is a generic helper for threshold comparisons

func GreaterThan

func GreaterThan[T ~int | ~int64 | ~float64](a, b T) bool

GreaterThan returns true if a > b

func GreaterThanOrEqual

func GreaterThanOrEqual[T ~int | ~int64 | ~float64](a, b T) bool

GreaterThanOrEqual returns true if a >= b

func LessThan

func LessThan[T ~int | ~int64 | ~float64](a, b T) bool

LessThan returns true if a < b

func LessThanOrEqual

func LessThanOrEqual[T ~int | ~int64 | ~float64](a, b T) bool

LessThanOrEqual returns true if a <= b

func PerformHealthCheck

func PerformHealthCheck(checker CheckerWithBase, checkFunc func() (interface{}, bool, error)) (map[string]interface{}, error)

PerformHealthCheck is a helper function that performs a health check using the base functionality

Types

type BackupHealthChecker

type BackupHealthChecker struct {
	BackupLocation string
	MaxAge         time.Duration
}

BackupHealthChecker monitors backup status

func NewBackupHealthChecker

func NewBackupHealthChecker(backupLocation string, maxAge time.Duration) *BackupHealthChecker

NewBackupHealthChecker creates a new backup health checker

func (*BackupHealthChecker) Status

func (c *BackupHealthChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type BaseHealthChecker

type BaseHealthChecker struct {
	Name        string
	Description string
	Threshold   interface{}
	Interval    time.Duration
}

BaseHealthChecker provides common functionality for all health checkers

func (*BaseHealthChecker) CreateStatusMap

func (b *BaseHealthChecker) CreateStatusMap(healthy bool, value interface{}, details map[string]interface{}) map[string]interface{}

CreateStatusMap creates a base status map with common fields

type CPUUsageChecker

type CPUUsageChecker struct {
	Threshold float64 // Percentage threshold
	// contains filtered or unexported fields
}

CPUUsageChecker monitors CPU usage

func NewCPUUsageChecker

func NewCPUUsageChecker(threshold float64) *CPUUsageChecker

NewCPUUsageChecker creates a new CPU usage health checker

func (*CPUUsageChecker) Status

func (c *CPUUsageChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type CheckerWithBase

type CheckerWithBase interface {
	GetBase() *BaseHealthChecker
}

CheckerWithBase is an interface for health checkers with base functionality

type Config

type Config struct {
	// Service instances
	PostgresService  Postgres
	PgBouncerService PgBouncer
	WalgService      WalG

	// PostgREST configuration
	PostgRESTURL   string
	JWTGenerator   *jwt.JWTGenerator
	PostgRESTAdmin string

	// File system paths to monitor
	DataDir        string
	WALDir         string
	BackupLocation string

	// Supervisor configuration
	SupervisorEnabled bool     // Whether to monitor supervisor
	EnabledServices   []string // Services that should be running

	// Thresholds
	DiskSpaceThreshold   float64 // Percentage (e.g., 90.0 for 90%)
	WALSizeThreshold     int64   // Bytes
	MemoryUsageThreshold float64 // Percentage
	CPUUsageThreshold    float64 // Percentage
}

Config contains configuration for health checks

type DiskSpaceChecker

type DiskSpaceChecker struct {
	Path      string
	Threshold float64 // Percentage threshold (e.g., 90.0 for 90%)
}

DiskSpaceChecker monitors disk space usage

func NewDiskSpaceChecker

func NewDiskSpaceChecker(path string, threshold float64) *DiskSpaceChecker

NewDiskSpaceChecker creates a new disk space health checker

func (*DiskSpaceChecker) Status

func (c *DiskSpaceChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type HealthChecker

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

HealthChecker provides comprehensive health checks for PostgreSQL and related services

func NewHealthChecker

func NewHealthChecker(config *Config) (*HealthChecker, error)

NewHealthChecker creates a new health checker with comprehensive checks

func (*HealthChecker) GetStatus

func (hc *HealthChecker) GetStatus() map[string]interface{}

GetStatus returns current health status

func (*HealthChecker) Handler

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

Handler returns an HTTP handler for health checks (simple status)

func (*HealthChecker) IsHealthy

func (hc *HealthChecker) IsHealthy() bool

IsHealthy returns true if all fatal checks are passing

func (*HealthChecker) Start

func (hc *HealthChecker) Start() error

Start begins health monitoring

func (*HealthChecker) StatusHandler

func (hc *HealthChecker) StatusHandler() http.HandlerFunc

StatusHandler returns an HTTP handler that provides detailed health status This returns the complete go-health state as per the user's requirement

func (*HealthChecker) Stop

func (hc *HealthChecker) Stop() error

Stop stops health monitoring

type MemoryUsageChecker

type MemoryUsageChecker struct {
	Threshold float64 // Percentage threshold
}

MemoryUsageChecker monitors system memory usage

func NewMemoryUsageChecker

func NewMemoryUsageChecker(threshold float64) *MemoryUsageChecker

NewMemoryUsageChecker creates a new memory usage health checker

func (*MemoryUsageChecker) Status

func (c *MemoryUsageChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type PgBouncer

type PgBouncer interface {
	Health() error
}

PgBouncer interface defines the methods needed for PgBouncer health checking

type PgBouncerChecker

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

PgBouncerChecker implements health check for PgBouncer using the service's Health method

func NewPgBouncerChecker

func NewPgBouncerChecker(pgbouncer PgBouncer) *PgBouncerChecker

NewPgBouncerChecker creates a new PgBouncer health checker

func (*PgBouncerChecker) Status

func (p *PgBouncerChecker) Status() (interface{}, error)

Status performs a PgBouncer health check

type PostgRESTChecker

type PostgRESTChecker struct {
	URL          string
	JWTGenerator *jwt.JWTGenerator
	AdminRole    string
	Timeout      time.Duration
}

PostgRESTChecker checks PostgREST API health using JWT authentication

func NewPostgRESTChecker

func NewPostgRESTChecker(url string, jwtGenerator *jwt.JWTGenerator, adminRole string, timeout time.Duration) *PostgRESTChecker

NewPostgRESTChecker creates a new PostgREST health checker

func (*PostgRESTChecker) Status

func (c *PostgRESTChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type PostgreSQLChecker

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

PostgreSQLChecker implements health check for PostgreSQL using the service's SQL method

func NewPostgreSQLChecker

func NewPostgreSQLChecker(postgres Postgres) *PostgreSQLChecker

NewPostgreSQLChecker creates a new PostgreSQL health checker

func (*PostgreSQLChecker) Status

func (p *PostgreSQLChecker) Status() (interface{}, error)

Status performs a PostgreSQL health check

type Postgres

type Postgres interface {
	SQL(query string, args ...any) ([]map[string]interface{}, error)
}

Postgres interface defines the methods needed for PostgreSQL health checking

type SecurityChecker

type SecurityChecker struct {
	DataDir string
}

SecurityChecker validates security configuration

func NewSecurityChecker

func NewSecurityChecker(dataDir string) *SecurityChecker

NewSecurityChecker creates a new security health checker

func (*SecurityChecker) Status

func (c *SecurityChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type SupervisorChecker

type SupervisorChecker struct {
	EnabledServices []string // Services that should be running (based on configuration)
}

SupervisorChecker monitors supervisord managed processes

func NewSupervisorChecker

func NewSupervisorChecker(enabledServices []string) *SupervisorChecker

NewSupervisorChecker creates a new supervisor health checker

func (*SupervisorChecker) Status

func (c *SupervisorChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type WALSizeChecker

type WALSizeChecker struct {
	WALDir    string
	Threshold int64 // Size threshold in bytes
}

WALSizeChecker monitors WAL directory size

func NewWALSizeChecker

func NewWALSizeChecker(walDir string, threshold int64) *WALSizeChecker

NewWALSizeChecker creates a new WAL size health checker

func (*WALSizeChecker) Status

func (c *WALSizeChecker) Status() (interface{}, error)

Status implements the health.ICheckable interface

type WalG

type WalG interface {
	Health() error
}

WalG interface defines the methods needed for WAL-G health checking

type WalgChecker

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

WalgChecker implements health check for WAL-G backup service

func NewWalgChecker

func NewWalgChecker(walg WalG) *WalgChecker

NewWalgChecker creates a new WAL-G health checker

func (*WalgChecker) Status

func (w *WalgChecker) Status() (interface{}, error)

Status performs a WAL-G health check

Jump to

Keyboard shortcuts

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