probe

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: 15 Imported by: 0

Documentation

Overview

Package probe contains the probe implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckEmpty

func CheckEmpty(s string) string

CheckEmpty return "empty" if the string is empty

func CleanData

func CleanData(p []Prober)

CleanData removes the items in resultData not in []Prober Note: No need to consider the thread-safe, because this function is only called once during the startup

func CleanDataFile

func CleanDataFile(filename string, backups int)

CleanDataFile keeps the max backup of data file Note: No need to consider the thread-safe, because this function is only called once during the startup

func LoadDataFromFile

func LoadDataFromFile(filename string) error

LoadDataFromFile load the results from file Note: No need to consider the thread-safe, because this function is only called once during the startup

func SaveDataToFile

func SaveDataToFile(filename string) error

SaveDataToFile save the results to file Note: No need to consider the thread-safe, because this function and SetResultData in same goroutine

func SetMetaData

func SetMetaData(name string, ver string)

SetMetaData set the meta data Note: No need to consider the thread-safe, because this function is only called during the startup

func SetResultData

func SetResultData(name string, result *Result)

SetResultData set the result of probe Note: this function would be called by status update goroutine

int saveData() in cmd/easeprobe/report.go

func SetResultsData

func SetResultsData(r []Result)

SetResultsData set the results of probe

Types

type MetaData

type MetaData struct {
	Name string `yaml:"name"`
	Ver  string `yaml:"version"`
	// contains filtered or unexported fields
}

MetaData the meta data of data file

func GetMetaData

func GetMetaData() *MetaData

GetMetaData get the meta data

type NotificationStrategyData

type NotificationStrategyData struct {
	global.NotificationStrategySettings `yaml:",inline" json:",inline"`

	// the current notified times
	Notified int `yaml:"notified" json:"notified"`
	// the current continuous failed rounds
	Failed int `yaml:"failed" json:"failed"`
	// the next round will be notified
	Next int `yaml:"next" json:"next"`
	// the Interval is the interval between two notifications
	Interval int `yaml:"interval" json:"interval"`
	// the flag to indicate whether the notification is sent
	IsSent bool `yaml:"-" json:"-"`
}

NotificationStrategyData is the notification strategy

func NewNotificationStrategyData

func NewNotificationStrategyData(strategy global.IntervalStrategy, maxTimes int, factor int) *NotificationStrategyData

NewNotificationStrategyData returns a new NotificationStrategy

func (*NotificationStrategyData) Clone

Clone returns a new NotificationStrategyData

func (*NotificationStrategyData) IsExceedMaxTimes

func (n *NotificationStrategyData) IsExceedMaxTimes() bool

IsExceedMaxTimes returns true if the current times is equal to the max times

func (*NotificationStrategyData) NeedToSendNotification

func (n *NotificationStrategyData) NeedToSendNotification() bool

NeedToSendNotification returns true if the notification should be sent

func (*NotificationStrategyData) NextNotification

func (n *NotificationStrategyData) NextNotification()

NextNotification returns the next notification times

func (*NotificationStrategyData) ProcessStatus

func (n *NotificationStrategyData) ProcessStatus(status bool)

ProcessStatus processes the probe status

func (*NotificationStrategyData) Reset

func (n *NotificationStrategyData) Reset()

Reset resets the current times

type Prober

type Prober interface {
	LabelMap() prometheus.Labels
	SetLabelMap(labels prometheus.Labels)
	Kind() string
	Name() string
	Channels() []string
	Timeout() time.Duration
	Interval() time.Duration
	Result() *Result
	Config(global.ProbeSettings) error
	Probe() Result
}

Prober Interface

type Result

type Result struct {
	Name             string        `json:"name" yaml:"name"`
	Endpoint         string        `json:"endpoint" yaml:"endpoint"`
	StartTime        time.Time     `json:"time" yaml:"time"`
	StartTimestamp   int64         `json:"timestamp" yaml:"timestamp"`
	RoundTripTime    time.Duration `json:"rtt" yaml:"rtt"`
	Status           Status        `json:"status" yaml:"status"`
	PreStatus        Status        `json:"prestatus" yaml:"prestatus"`
	Message          string        `json:"message" yaml:"message"`
	LatestDownTime   time.Time     `json:"latestdowntime" yaml:"latestdowntime"`
	RecoveryDuration time.Duration `json:"recoverytime" yaml:"recoverytime"`
	Stat             Stat          `json:"stat" yaml:"stat"`
}

Result is the status of health check

func GetResultData

func GetResultData(name string) *Result

GetResultData get the result of probe Note: the function would be called by Data Saving, SLA Report, Web Server

func NewResult

func NewResult() *Result

NewResult return a Result object

func NewResultWithName

func NewResultWithName(name string) *Result

NewResultWithName return a Result object with name

func (*Result) Clone

func (r *Result) Clone() Result

Clone return a clone of the Result

func (*Result) DebugJSON

func (r *Result) DebugJSON() string

DebugJSON convert the object to DebugJSON

func (*Result) DebugJSONIndent

func (r *Result) DebugJSONIndent() string

DebugJSONIndent convert the object to indent JSON

func (*Result) DoStat

func (r *Result) DoStat(d time.Duration)

DoStat is the function do the statistics

func (*Result) SLAPercent

func (r *Result) SLAPercent() float64

SLAPercent calculate the SLAPercent

func (*Result) Title

func (r *Result) Title() string

Title return the title for notification

type Stat

type Stat struct {
	Since    time.Time        `json:"since" yaml:"since"`
	Total    int64            `json:"total" yaml:"total"`
	Status   map[Status]int64 `json:"status" yaml:"status"`
	UpTime   time.Duration    `json:"uptime" yaml:"uptime"`
	DownTime time.Duration    `json:"downtime" yaml:"downtime"`
	StatusCounter
	NotificationStrategyData `json:"alert" yaml:"alert"`
}

Stat is the statistics of probe result

func (*Stat) Clone

func (s *Stat) Clone() Stat

Clone return a clone of the Stat

type Status

type Status int

Status is the status of Probe

const (
	StatusInit Status = iota
	StatusUp
	StatusDown
	StatusUnknown
	StatusBad
)

The status of a probe

func (*Status) Emoji

func (s *Status) Emoji() string

Emoji convert the status to emoji

func (Status) MarshalJSON

func (s Status) MarshalJSON() (b []byte, err error)

MarshalJSON is marshal the status

func (Status) MarshalYAML

func (s Status) MarshalYAML() (interface{}, error)

MarshalYAML is Marshal the status

func (*Status) Status

func (s *Status) Status(status string)

Status convert the string to Status

func (Status) String

func (s Status) String() string

String convert the Status to string

func (Status) Title

func (s Status) Title() string

Title convert the Status to title

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON is Unmarshal the status

func (*Status) UnmarshalYAML

func (s *Status) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is Unmarshal the status

type StatusCounter

type StatusCounter struct {
	StatusHistory []StatusHistory // the status history
	MaxLen        int             // the max length of the status history
	CurrentStatus bool            // the current status
	StatusCount   int             // the count of the same status
}

StatusCounter is the object to count the status

func NewStatusCounter

func NewStatusCounter(maxLen int) *StatusCounter

NewStatusCounter return a StatusCounter object

func (*StatusCounter) AppendStatus

func (s *StatusCounter) AppendStatus(status bool, message string)

AppendStatus appends the status

func (*StatusCounter) Clone

func (s *StatusCounter) Clone() StatusCounter

Clone returns a copy of the StatusThreshold

func (*StatusCounter) SetMaxLen

func (s *StatusCounter) SetMaxLen(maxLen int)

SetMaxLen sets the max length of the status history

type StatusHistory

type StatusHistory struct {
	Status  bool
	Message string
}

StatusHistory is a history of status

type TextChecker

type TextChecker struct {
	Contain    string `yaml:"contain,omitempty" json:"contain,omitempty" jsonschema:"title=Contain Text,description=the string must be contained"`
	NotContain string `` /* 138-byte string literal not displayed */
	RegExp     bool   `` /* 141-byte string literal not displayed */
	// contains filtered or unexported fields
}

TextChecker is the struct to check the output

func (*TextChecker) Check

func (tc *TextChecker) Check(Text string) error

Check the text

func (*TextChecker) CheckRegExp

func (tc *TextChecker) CheckRegExp(Output string) error

CheckRegExp checks the output text, - if it contains a configured pattern then return nil - if it does not contain a configured pattern then return nil

func (*TextChecker) CheckText

func (tc *TextChecker) CheckText(Output string) error

CheckText checks the output text, - if it contains a configured string then return nil - if it does not contain a configured string then return nil

func (*TextChecker) Config

func (tc *TextChecker) Config() (err error)

Config the text checker initialize the regexp

func (*TextChecker) String

func (tc *TextChecker) String() string

Directories

Path Synopsis
Package base is the base package for all probes
Package base is the base package for all probes
Package client is the native client probe package
Package client is the native client probe package
conf
Package conf is the configuration package for native client
Package conf is the configuration package for native client
kafka
Package kafka is the native client probe for kafka.
Package kafka is the native client probe for kafka.
memcache
Package memcache is the native client probe for memcache
Package memcache is the native client probe for memcache
mongo
Package mongo implements a probe client for the MongoDB database.
Package mongo implements a probe client for the MongoDB database.
mysql
Package mysql is the client probe for MySQL.
Package mysql is the client probe for MySQL.
postgres
Package postgres is the native client probe for PostgreSQL
Package postgres is the native client probe for PostgreSQL
redis
Package redis is the native client probe for Redis
Package redis is the native client probe for Redis
zookeeper
Package zookeeper is the zookeeper client probe
Package zookeeper is the zookeeper client probe
Package host is the host probe package
Package host is the host probe package
Package http is the HTTP probe package.
Package http is the HTTP probe package.
Package ping is the ping probe package
Package ping is the ping probe package
Package shell is the shell probe package
Package shell is the shell probe package
Package ssh is the ssh probe package
Package ssh is the ssh probe package
Package tcp is the tcp probe package
Package tcp is the tcp probe package
Package tls is the tls probe package
Package tls is the tls probe package

Jump to

Keyboard shortcuts

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