monitor

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package monitor provides health checks, metrics collection, and monitoring capabilities for applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseChecker

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

DatabaseChecker checks database connectivity

func NewDatabaseChecker

func NewDatabaseChecker(name string, ping func(ctx context.Context) error) *DatabaseChecker

NewDatabaseChecker creates a new database checker

func (*DatabaseChecker) Check

func (*DatabaseChecker) Name

func (d *DatabaseChecker) Name() string

type DiskSpaceChecker

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

DiskSpaceChecker checks available disk space

func NewDiskSpaceChecker

func NewDiskSpaceChecker(path string, threshold float64) *DiskSpaceChecker

NewDiskSpaceChecker creates a new disk space checker

func (*DiskSpaceChecker) Check

func (*DiskSpaceChecker) Name

func (d *DiskSpaceChecker) Name() string

type HTTPChecker

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

HTTPChecker checks HTTP endpoint health

func NewHTTPChecker

func NewHTTPChecker(name, url string) *HTTPChecker

NewHTTPChecker creates a new HTTP checker

func (*HTTPChecker) Check

func (h *HTTPChecker) Check(ctx context.Context) *HealthStatus

func (*HTTPChecker) Name

func (h *HTTPChecker) Name() string

type HealthChecker

type HealthChecker interface {
	// Check performs a health check
	Check(ctx context.Context) *HealthStatus

	// Name returns the checker name
	Name() string
}

HealthChecker defines the health check interface

type HealthReport

type HealthReport struct {
	Status    Status                   `json:"status"`
	Checks    map[string]*HealthStatus `json:"checks"`
	System    *SystemMetrics           `json:"system"`
	Timestamp time.Time                `json:"timestamp"`
}

HealthReport represents the overall health report

type HealthStatus

type HealthStatus struct {
	Status      Status                 `json:"status"`
	Message     string                 `json:"message,omitempty"`
	Details     map[string]interface{} `json:"details,omitempty"`
	LastChecked time.Time              `json:"last_checked"`
	Duration    time.Duration          `json:"duration_ms"`
}

HealthStatus represents the health status of a component

type MemoryMetrics

type MemoryMetrics struct {
	Alloc      uint64 `json:"alloc_bytes"`
	TotalAlloc uint64 `json:"total_alloc_bytes"`
	Sys        uint64 `json:"sys_bytes"`
	NumGC      uint32 `json:"num_gc"`
}

MemoryMetrics represents memory metrics

type Metrics

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

Metrics tracks application metrics

func NewMetrics

func NewMetrics() *Metrics

NewMetrics creates new metrics tracker

func (*Metrics) GetStats

func (m *Metrics) GetStats() map[string]interface{}

GetStats returns metrics statistics

func (*Metrics) GetUptime

func (m *Metrics) GetUptime() time.Duration

GetUptime returns application uptime

func (*Metrics) RecordError

func (m *Metrics) RecordError()

RecordError records an error

func (*Metrics) RecordHealthCheck

func (m *Metrics) RecordHealthCheck(name string, status Status)

RecordHealthCheck records a health check result

func (*Metrics) RecordRequest

func (m *Metrics) RecordRequest()

RecordRequest records a request

type Monitor

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

Monitor manages health checks and metrics

func NewMonitor

func NewMonitor(checkPeriod time.Duration) *Monitor

NewMonitor creates a new monitor

func (*Monitor) AddChecker

func (m *Monitor) AddChecker(checker HealthChecker)

AddChecker adds a health checker

func (*Monitor) CheckHealth

func (m *Monitor) CheckHealth(ctx context.Context) *HealthReport

CheckHealth performs an immediate health check

func (*Monitor) GetHealth

func (m *Monitor) GetHealth() *HealthReport

GetHealth returns the overall health status

func (*Monitor) RemoveChecker

func (m *Monitor) RemoveChecker(name string)

RemoveChecker removes a health checker

func (*Monitor) ServeHTTP

func (m *Monitor) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for health endpoint

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop stops the monitor

type PingChecker

type PingChecker struct{}

PingChecker checks basic connectivity

func (*PingChecker) Check

func (p *PingChecker) Check(ctx context.Context) *HealthStatus

func (*PingChecker) Name

func (p *PingChecker) Name() string

type Status

type Status string

Status represents health status

const (
	StatusHealthy   Status = "healthy"
	StatusDegraded  Status = "degraded"
	StatusUnhealthy Status = "unhealthy"
)

type SystemMetrics

type SystemMetrics struct {
	Memory     MemoryMetrics `json:"memory"`
	Goroutines int           `json:"goroutines"`
	CPUs       int           `json:"cpus"`
	Uptime     time.Duration `json:"uptime_seconds"`
}

SystemMetrics represents system-level metrics

Jump to

Keyboard shortcuts

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