health

package
v0.0.0-...-df163ab Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckNodeHealth

func CheckNodeHealth(Node map[string]interface{}, db *sql.DB, mongoClient *mongo.Client, signalRClient signalr.Client) (map[string]interface{}, error)

func CheckSignalRServerHealth

func CheckSignalRServerHealth(Node map[string]interface{}, url string, wc string) (map[string]interface{}, error)

func CheckSystemHealth

func CheckSystemHealth(c *gin.Context) (map[string]interface{}, error)

func CheckWebServerHealth

func CheckWebServerHealth(Node map[string]interface{}) (map[string]interface{}, error)

Types

type Check

type Check struct {
	// Status is the check status.
	Status Status `json:"status"`
	// Result is the check result.
	Results map[string]interface{} `json:"results"`
	// Timestamp is the time in which the check occurred.
	Timestamp time.Time `json:"timestamp"`
	// Failures holds the failed checks along with their messages.
	Failures map[string]string `json:"failures,omitempty"`
	// System holds information of the go process.
	*System `json:"system,omitempty"`
	// Component holds information on the component for which checks are made
	Component `json:"component"`
}

Check represents the health check response.

type CheckFunc

type CheckFunc func(context.Context) error

CheckFunc is the func which executes the check.

type Component

type Component struct {
	// Name is the name of the component.
	Name         string `json:"name"`
	Instance     string `json:"instance"`
	InstanceName string `json:"instancename"`
	InstanceType string `json:"instancetype"`
	// Version is the component version.
	Version string `json:"version"`
}

Component descriptive values about the component for which checks are made

type Config

type Config struct {
	// Name is the name of the resource to be checked.
	Name string
	// Timeout is the timeout defined for every check.
	Timeout time.Duration
	// SkipOnErr if set to true, it will retrieve StatusOK providing the error message from the failed resource.
	SkipOnErr bool
	// Check is the func which executes the check.
	Check CheckFunc
}

Config carries the parameters to run the check.

type Health

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

Health is the health-checks container

func New

func New(opts ...Option) (*Health, error)

New instantiates and build new health check container

func (*Health) Handler

func (h *Health) Handler() http.Handler

Handler returns an HTTP handler (http.HandlerFunc).

func (*Health) HandlerFunc

func (h *Health) HandlerFunc(w http.ResponseWriter, r *http.Request)

HandlerFunc is the HTTP handler function.

func (*Health) Measure

func (h *Health) Measure(ctx context.Context) Check

Measure runs all the registered health checks and returns summary status

func (*Health) Register

func (h *Health) Register(c Config) error

Register registers a check config to be performed.

type Option

type Option func(*Health) error

Option is the health-container options type

func WithChecks

func WithChecks(checks ...Config) Option

WithChecks adds checks to newly instantiated health-container

func WithComponent

func WithComponent(component Component) Option

WithComponent sets the component description of the component to which this check refer

func WithMaxConcurrent

func WithMaxConcurrent(n int) Option

WithMaxConcurrent sets max number of concurrently running checks. Set to 1 if want to run all checks sequentially.

func WithSystemInfo

func WithSystemInfo() Option

WithSystemInfo enables the option to return system information about the go process.

func WithTracerProvider

func WithTracerProvider(tp trace.TracerProvider, instrumentationName string) Option

WithTracerProvider sets trace provider for the checks and instrumentation name that will be used for tracer from trace provider.

type Status

type Status string

Status type represents health status

const (
	StatusOK                 Status = "OK"
	StatusPartiallyAvailable Status = "Partially Available"
	StatusUnavailable        Status = "Unavailable"
	StatusTimeout            Status = "Timeout during health check"
)

Possible health statuses

type System

type System struct {
	// Version is the go version.
	Version string `json:"version"`
	// GoroutinesCount is the number of the current goroutines.
	GoroutinesCount int `json:"goroutines_count"`
	// TotalAllocBytes is the total bytes allocated.
	TotalAllocBytes int `json:"total_alloc_bytes"`
	// HeapObjectsCount is the number of objects in the go heap.
	HeapObjectsCount int `json:"heap_objects_count"`
	// TotalAllocBytes is the bytes allocated and not yet freed.
	AllocBytes int `json:"alloc_bytes"`

	Metrics map[string]interface{} `json:"system"`
}

System runtime variables about the go process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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