healthcheck

package
v0.0.0-...-f05b11c Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertConfig

type AlertConfig struct {
	Type         AlertType `yaml:"type" json:"type"`
	SilentPeriod string    `yaml:"silent_period" json:"silent_period"`

	AdanosAddr  string `yaml:"adanos_addr" json:"adanos_addr"`
	AdanosToken string `yaml:"adanos_token" json:"adanos_token"`

	HTTPAddr    string       `yaml:"http_addr" json:"http_addr"`
	HTTPHeaders []HTTPHeader `yaml:"http_header" json:"http_header"`

	Timeout int64 `yaml:"timeout" json:"timeout"`
}

AlertConfig 告警配置

func (AlertConfig) SendEvent

func (ac AlertConfig) SendEvent(ctx context.Context, status string, evt Event) error

type AlertType

type AlertType string

AlertType 告警类型

const (
	// AlertTypeAdanos 基于 Adanos 的告警通知
	AlertTypeAdanos   AlertType = "adanos"
	AlertTypeHTTP     AlertType = "http"
	AlertTypeStdout   AlertType = "stdout"
	AlertTypeErrorlog AlertType = "errorlog"
)

type CheckType

type CheckType string

CheckType 健康检查类型

const (
	// HTTP http 类型的健康检查
	HTTP CheckType = "http"
	PING CheckType = "ping"
	PUSH CheckType = "push"
)

type CheckTypeHTTP

type CheckTypeHTTP struct {
	Method      string       `yaml:"method" json:"method,omitempty"`
	URL         string       `yaml:"url" json:"url,omitempty"`
	Headers     []HTTPHeader `yaml:"headers" json:"-"`
	Body        string       `yaml:"body" json:"body,omitempty"`
	Timeout     int64        `yaml:"timeout" json:"timeout,omitempty"`
	SuccessRule string       `yaml:"success_rule" json:"success_rule,omitempty"`
}

CheckTypeHTTP HTTP 类型的心跳检测

func (CheckTypeHTTP) Check

func (cth CheckTypeHTTP) Check(ctx context.Context, hb Healthcheck) error

Check 执行心跳检测

type CheckTypeICMP

type CheckTypeICMP struct {
	Host        string `yaml:"host" json:"host,omitempty"`
	Count       int64  `yaml:"count" json:"count,omitempty"`
	Timeout     int64  `yaml:"timeout" json:"timeout,omitempty"`
	SuccessRule string `yaml:"success_rule" json:"success_rule,omitempty"`
}

CheckTypeICMP ICMP Ping 类型的心跳检测

func (CheckTypeICMP) Check

func (cth CheckTypeICMP) Check(ctx context.Context, hb Healthcheck) error

Check 执行心跳检测

type ConsulService

type ConsulService struct {
	Tags []string
	*api.CatalogService
	pattern.Helpers
}

type Discovery

type Discovery struct {
	Type         DiscoveryType `yaml:"type" json:"type,omitempty"`
	ConsulScheme string        `yaml:"consul_scheme" json:"consul_scheme,omitempty"`
	ConsulAddr   string        `yaml:"consul_addr" json:"consul_addr,omitempty"`
	ConsulToken  string        `yaml:"consul_token" json:"-"`
	ConsulDC     string        `yaml:"consul_dc" json:"consul_dc,omitempty"`
	Filter       string        `yaml:"filter" json:"filter,omitempty"`
	Template     Healthcheck   `yaml:"template" json:"template,omitempty"`
}

Discovery 服务发现

func (Discovery) LoadHealthchecks

func (dis Discovery) LoadHealthchecks(ctx context.Context, conf *GlobalConfig) ([]Healthcheck, error)

type DiscoveryType

type DiscoveryType string

DiscoveryType 服务发现类型

const (
	// DiscoveryTypeConsul 基于 Consul 的服务发现
	DiscoveryTypeConsul DiscoveryType = "consul"
)

type Event

type Event struct {
	Healthcheck Healthcheck `json:"healthcheck"`
	// LastAliveTime 最后一次该心跳检测活跃的时间,该字段用于检测一个 Alert 是否已经失效了
	LastAliveTime time.Time `json:"last_alive_time"`

	// lastAlertTime 最后一次告警时间
	LastAlertTime time.Time `json:"last_alert_time"`
	// alertTimes 告警次数,从最后一次心跳丢失开始
	AlertTimes int64 `json:"alert_times"`

	LastFailure     string    `json:"last_failure"`
	LastSuccessTime time.Time `json:"last_success_time"`
}

type GlobalConfig

type GlobalConfig struct {
	Version       string        `yaml:"version" json:"version"`
	Healthchecks  []Healthcheck `yaml:"healthchecks" json:"healthchecks"`
	Discoveries   []Discovery   `yaml:"discoveries" json:"discoveries"`
	WorkerNum     int           `yaml:"worker_num" json:"worker_num"`
	CheckInterval int64         `yaml:"check_interval" json:"check_interval"`
	LossThreshold int64         `yaml:"loss_threshold" json:"loss_threshold"`
	HTTPTimeout   int64         `yaml:"http_timeout" json:"http_timeout"`
	PINGTimeout   int64         `yaml:"ping_timeout" json:"ping_timeout"`
	Alerts        []AlertConfig `yaml:"alerts" json:"alerts"`
}

GlobalConfig is a global configuration object

func ParseYamlConfig

func ParseYamlConfig(data []byte) (*GlobalConfig, error)

ParseYamlConfig parse config from yaml

func (*GlobalConfig) ToYAML

func (gc *GlobalConfig) ToYAML() string

ToYAML return GlobalConfig as yaml

type HTTPHeader

type HTTPHeader struct {
	Key   string `yaml:"key" json:"key,omitempty"`
	Value string `yaml:"value" json:"value,omitempty"`
}

HTTPHeader http 请求头

type Healthcheck

type Healthcheck struct {
	ID            string        `yaml:"id,omitempty" json:"id,omitempty"`
	Editable      bool          `yaml:"-" json:"editable,omitempty"`
	Name          string        `yaml:"name" json:"name,omitempty"`
	Tags          []string      `yaml:"tags" json:"tags,omitempty"`
	CheckInterval int64         `yaml:"check_interval" json:"check_interval,omitempty"`
	LossThreshold int64         `yaml:"loss_threshold" json:"loss_threshold,omitempty"`
	CheckType     CheckType     `yaml:"check_type" json:"check_type,omitempty"`
	HTTP          CheckTypeHTTP `yaml:"http" json:"http,omitempty"`
	PING          CheckTypeICMP `yaml:"ping" json:"ping,omitempty"`
}

Healthcheck 健康检查对象

func (Healthcheck) Check

func (hb Healthcheck) Check(ctx context.Context) error

Check 发起健康检查

func (Healthcheck) Schedulable

func (hb Healthcheck) Schedulable() bool

Schedulable return whether the Healthcheck is schedule

func (Healthcheck) String

func (hb Healthcheck) String() string

String convert health-check to string

type SuccessRuleCheckData

type SuccessRuleCheckData struct {
	pattern.Helpers
	StatusCode int
	Status     string
	Body       string
}

SuccessRuleCheckData 请求结果判定

func (SuccessRuleCheckData) String

func (srcd SuccessRuleCheckData) String() string

String 请求结果判定对象字符串表示

Jump to

Keyboard shortcuts

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