host

package
v0.0.0-...-c3423aa Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package host is the host probe package

Index

Constants

View Source
const (
	DefaultCPUThreshold  = 0.8
	DefaultMemThreshold  = 0.8
	DefaultDiskThreshold = 0.95
	DefaultLoadThreshold = 0.8
)

Default threshold

Variables

View Source
var BastionMap ssh.BastionMapType

BastionMap is a map of bastion

Functions

This section is empty.

Types

type Basic

type Basic struct {
	base.DefaultProbe `yaml:",inline"`
	HostName          string `yaml:"hostname"`
	OS                string `yaml:"os"`
	Core              int64  `yaml:"core"`
	// contains filtered or unexported fields
}

Basic is the basic information of the host

func (*Basic) CheckThreshold

func (b *Basic) CheckThreshold() (bool, string)

CheckThreshold check the cpu usage

func (*Basic) Command

func (b *Basic) Command() string

Command returns the command to get the cpu usage

func (*Basic) Config

func (b *Basic) Config(s *Server)

Config returns the config of the basic info

func (*Basic) CreateMetrics

func (b *Basic) CreateMetrics(subsystem, name string)

CreateMetrics create the cpu metrics

func (*Basic) ExportMetrics

func (b *Basic) ExportMetrics(name string)

ExportMetrics export the cpu metrics

func (*Basic) Name

func (b *Basic) Name() string

Name returns the name of the metric

func (*Basic) OutputLines

func (b *Basic) OutputLines() int

OutputLines returns the lines of command output

func (*Basic) Parse

func (b *Basic) Parse(s []string) error

Parse a string to a CPU struct

func (*Basic) SetThreshold

func (b *Basic) SetThreshold(t *Threshold)

SetThreshold set the basic threshold

func (*Basic) UsageInfo

func (b *Basic) UsageInfo() string

UsageInfo returns the usage info of the cpu

type CPU

type CPU struct {
	base.DefaultProbe `yaml:",inline"`
	User              float64 `yaml:"user"`
	Sys               float64 `yaml:"sys"`
	Nice              float64 `yaml:"nice"`
	Idle              float64 `yaml:"idle"`
	Wait              float64 `yaml:"wait"`
	Hard              float64 `yaml:"hard"`
	Soft              float64 `yaml:"soft"`
	Steal             float64 `yaml:"steal"`

	Threshold float64 `yaml:"threshold"`
	// contains filtered or unexported fields
}

CPU is the cpu usage "1.6 us, 1.6 sy, 3.2 ni, 91.9 id, 1.6 wa, 0.0 hi, 0.0 si, 0.0 st"

func (*CPU) CheckThreshold

func (c *CPU) CheckThreshold() (bool, string)

CheckThreshold check the cpu usage

func (*CPU) Command

func (c *CPU) Command() string

Command returns the command to get the cpu usage

func (*CPU) Config

func (c *CPU) Config(s *Server)

Config returns the config of the cpu

func (*CPU) CreateMetrics

func (c *CPU) CreateMetrics(subsystem, name string)

CreateMetrics create the cpu metrics

func (*CPU) ExportMetrics

func (c *CPU) ExportMetrics(name string)

ExportMetrics export the cpu metrics

func (*CPU) Name

func (c *CPU) Name() string

Name returns the name of the metric

func (*CPU) OutputLines

func (c *CPU) OutputLines() int

OutputLines returns the lines of command output

func (*CPU) Parse

func (c *CPU) Parse(s []string) error

Parse a string to a CPU struct

func (*CPU) SetThreshold

func (c *CPU) SetThreshold(t *Threshold)

SetThreshold set the cpu threshold

func (*CPU) UsageInfo

func (c *CPU) UsageInfo() string

UsageInfo returns the cpu usage info

type Disks

type Disks struct {
	base.DefaultProbe
	Mount []string
	Usage []ResourceUsage

	Threshold float64
	// contains filtered or unexported fields
}

Disks is the disk usage

func (*Disks) CheckThreshold

func (d *Disks) CheckThreshold() (bool, string)

CheckThreshold check the cpu usage

func (*Disks) Command

func (d *Disks) Command() string

Command returns the command to get the cpu usage

func (*Disks) Config

func (d *Disks) Config(s *Server)

Config returns the config of the cpu

func (*Disks) CreateMetrics

func (d *Disks) CreateMetrics(subsystem, name string)

CreateMetrics create the disk metrics

func (*Disks) ExportMetrics

func (d *Disks) ExportMetrics(name string)

ExportMetrics export the disk metrics

func (*Disks) Name

func (d *Disks) Name() string

Name returns the name of the metric

func (*Disks) OutputLines

func (d *Disks) OutputLines() int

OutputLines returns the lines of command output

func (*Disks) Parse

func (d *Disks) Parse(s []string) error

Parse a string to a CPU struct

func (*Disks) SetThreshold

func (d *Disks) SetThreshold(t *Threshold)

SetThreshold set the threshold of the disk

func (*Disks) UsageInfo

func (d *Disks) UsageInfo() string

UsageInfo returns the usage info of the disks

type Host

type Host struct {
	Bastion *ssh.BastionMapType `` /* 129-byte string literal not displayed */
	Servers []Server            `yaml:"servers" json:"servers" jsonschema:"required,title=Host Servers,description=the host servers to be monitored"`
}

Host is the host probe configuration

type IMetrics

type IMetrics interface {
	Name() string                   // Name is the name of the metrics
	Command() string                // Command returns the command to get the metrics
	OutputLines() int               // OutputLines returns the lines of command output
	Config(s *Server)               // Config returns the config of the metrics
	SetThreshold(t *Threshold)      // SetThreshold sets the threshold of the metrics
	Parse(s []string) error         // Parse a string to a metrics struct
	UsageInfo() string              // UsageInfo returns the usage info of the metrics
	CheckThreshold() (bool, string) // CheckThreshold check the metrics usage
	CreateMetrics(kind, tag string) // CreateMetrics creates the metrics
	ExportMetrics(name string)      // ExportMetrics export the metrics
}

IMetrics is the interface of metrics

type Info

type Info struct {
	Basic  `yaml:",inline"`
	CPU    CPU   `yaml:"cpu"`
	Memory Mem   `yaml:"memory"`
	Disks  Disks `yaml:"disks"`
	Load   Load  `yaml:"load"`
}

Info is the host probe information

func (*Info) IMetrics

func (info *Info) IMetrics() []IMetrics

IMetrics put all of the Info member into IMetrics slices

type Load

type Load struct {
	base.DefaultProbe `yaml:",inline"`
	Core              int64              `json:"core"`
	Metrics           map[string]float64 `json:"metrics"`

	Threshold map[string]float64
	// contains filtered or unexported fields
}

Load is the load average of the host

func (*Load) CheckThreshold

func (l *Load) CheckThreshold() (bool, string)

CheckThreshold check the load average threshold

func (*Load) Command

func (l *Load) Command() string

Command returns the command to get the load average

func (*Load) Config

func (l *Load) Config(s *Server)

Config returns the config of the load average

func (*Load) CreateMetrics

func (l *Load) CreateMetrics(subsystem, name string)

CreateMetrics create the load average metrics

func (*Load) ExportMetrics

func (l *Load) ExportMetrics(name string)

ExportMetrics export the load average metrics

func (*Load) Name

func (l *Load) Name() string

Name returns the name of the metrics

func (*Load) OutputLines

func (l *Load) OutputLines() int

OutputLines returns the lines of command output

func (*Load) Parse

func (l *Load) Parse(s []string) error

Parse a string to a CPU struct

func (*Load) SetThreshold

func (l *Load) SetThreshold(t *Threshold)

SetThreshold set the threshold of the load average

func (*Load) UsageInfo

func (l *Load) UsageInfo() string

UsageInfo returns the usage info of the load average

type Mem

type Mem struct {
	base.DefaultProbe `yaml:",inline"`
	ResourceUsage     `yaml:",inline"`

	Threshold float64 `yaml:"threshold"`
	// contains filtered or unexported fields
}

Mem is the resource usage for memory and disk

func (*Mem) CheckThreshold

func (m *Mem) CheckThreshold() (bool, string)

CheckThreshold check the memory usage

func (*Mem) Command

func (m *Mem) Command() string

Command returns the command to get the memory usage

func (*Mem) Config

func (m *Mem) Config(s *Server)

Config returns the config of the memory

func (*Mem) CreateMetrics

func (m *Mem) CreateMetrics(subsystem, name string)

CreateMetrics create the memory metrics

func (*Mem) ExportMetrics

func (m *Mem) ExportMetrics(name string)

ExportMetrics export the memory metrics

func (*Mem) Name

func (m *Mem) Name() string

Name returns the name of the metric

func (*Mem) OutputLines

func (m *Mem) OutputLines() int

OutputLines returns the lines of command output

func (*Mem) Parse

func (m *Mem) Parse(s []string) error

Parse a string to a Memory struct

func (*Mem) SetThreshold

func (m *Mem) SetThreshold(t *Threshold)

SetThreshold set the threshold of the memory

func (*Mem) UsageInfo

func (m *Mem) UsageInfo() string

UsageInfo returns the usage info of the memory

type ResourceUsage

type ResourceUsage struct {
	Used  int     `yaml:"used"`
	Total int     `yaml:"total"`
	Usage float64 `yaml:"usage"`
	Tag   string  `yaml:"tag"`
}

ResourceUsage is the resource usage for cpu and memory

type Server

type Server struct {
	ssh.Server `yaml:",inline"`
	Threshold  Threshold `` /* 141-byte string literal not displayed */
	Disks      []string  `` /* 135-byte string literal not displayed */
	// contains filtered or unexported fields
}

Server is the server of a host probe

func (*Server) CheckThreshold

func (s *Server) CheckThreshold(info Info) (bool, string)

CheckThreshold check the threshold

func (*Server) Config

func (s *Server) Config(gConf global.ProbeSettings) error

Config is the host probe configuration

func (*Server) DoProbe

func (s *Server) DoProbe() (bool, string)

DoProbe return the checking result

func (*Server) ExportMetrics

func (s *Server) ExportMetrics()

ExportMetrics export the metrics

func (*Server) ParseHostInfo

func (s *Server) ParseHostInfo(str string) (Info, error)

ParseHostInfo parse the host info

func (*Server) Usage

func (s *Server) Usage(info Info) string

Usage return all of the resources usage

type Threshold

type Threshold struct {
	CPU  float64            `yaml:"cpu,omitempty" json:"cpu,omitempty" jsonschema:"title=CPU threshold,description=CPU threshold (default: 0.8)"`
	Mem  float64            `yaml:"mem,omitempty" json:"mem,omitempty" jsonschema:"title=Memory threshold,description=Memory threshold (default: 0.8)"`
	Disk float64            `yaml:"disk,omitempty" json:"disk,omitempty" jsonschema:"title=Disk threshold,description=Disk threshold (default: 0.95)"`
	Load map[string]float64 `` /* 145-byte string literal not displayed */
}

Threshold is the threshold of a probe

func (*Threshold) String

func (t *Threshold) String() string

Jump to

Keyboard shortcuts

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