monitor

package
v0.0.0-...-7cb0e1f Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2017 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OK when the alerts have resolved and everything is peachy
	OK int = iota
	// WARNING when the number of failed attempts passes the WarningThreshold
	WARNING
	// CRITICAL when the number of failed attempts passes the CriticalThreshold
	CRITICAL
)

States of a monitor

View Source
const (
	DEFAULT_DNS_TIMEOUT     = time.Duration(2) * time.Second
	DEFAULT_DNS_RECORD_TYPE = "A"
)
View Source
const (
	START int = iota
	STOP

	GOROUTINE_ID_LENGTH = 8
	MAX_PORT            = 65536
)
View Source
const (
	DEFAULT_CONN_TIMEOUT  = time.Duration(4) * time.Second
	DEFAULT_READ_TIMEOUT  = time.Duration(2) * time.Second
	DEFAULT_WRITE_TIMEOUT = time.Duration(2) * time.Second
	DEFAULT_READ_SIZE     = 4096
)
View Source
const (
	DEFAULT_CMD_TIMEOUT = time.Duration(3) * time.Second
)
View Source
const (
	DEFAULT_HTTP_TIMEOUT = time.Duration(3) * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	RMC         *RootMonitorConfig
	Identifier  string
	MonitorFunc func() error
	// contains filtered or unexported fields
}

Base monitor to embed into monitors that do real work

func (*Base) Identify

func (b *Base) Identify() string

Identify the monitor by a string

func (*Base) Run

func (b *Base) Run() error

Run the check on a given interval -> evaluate response via b.handle()

func (*Base) Stop

func (b *Base) Stop()

Stop the monitor

type DnsMonitor

type DnsMonitor struct {
	Base
	Timeout    time.Duration
	Client     *resolver.Client
	Expect     *regexp.Regexp
	RecordType string
}

func NewDnsMonitor

func NewDnsMonitor(rmc *RootMonitorConfig) *DnsMonitor

func (*DnsMonitor) Validate

func (dns *DnsMonitor) Validate() error

type ExecMonitor

type ExecMonitor struct {
	Base

	Timeout time.Duration
	FullCmd string
}

func NewExecMonitor

func NewExecMonitor(rmc *RootMonitorConfig) *ExecMonitor

func (*ExecMonitor) Validate

func (e *ExecMonitor) Validate() error

type HTTPMonitor

type HTTPMonitor struct {
	Base

	Timeout time.Duration
}

func NewHTTPMonitor

func NewHTTPMonitor(rmc *RootMonitorConfig) *HTTPMonitor

func (*HTTPMonitor) Validate

func (h *HTTPMonitor) Validate() error

type IMonitor

type IMonitor interface {
	Run() error
	Stop()
	Identify() string
	Validate() error
}

func NewSampleMonitor

func NewSampleMonitor(rmc *RootMonitorConfig) IMonitor

type Monitor

type Monitor struct {
	Config     *config.Config
	Log        log.FieldLogger
	Identifier string

	MessageChannel    chan *alerter.Message
	StateChannel      chan *state.Message
	SupportedMonitors map[string]func(*RootMonitorConfig) IMonitor // monitor name : NewXMonitor
	MemberID          string
	// contains filtered or unexported fields
}

func New

func New(cfg *config.Config, messageChannel chan *alerter.Message, stateChannel chan *state.Message) *Monitor

func (*Monitor) Handle

func (m *Monitor) Handle(action int, monitorName, monitorConfigLocation string) error

Start/stop or restart a monitor with a specific config

func (*Monitor) StopAll

func (m *Monitor) StopAll() error

type MonitorConfig

type MonitorConfig struct {
	// Generic attributes that fit more than one monitor type
	Type        string              `json:"type"`                  // 'tcp', 'http', 'ssh', 'exec', 'icmp', 'dns'
	Description string              `json:"description,omitempty"` // optional
	Host        string              `json:"host,omitempty"`        // required for all checks except 'exec'
	Interval    util.CustomDuration `json:"interval,omitempty"`
	Timeout     util.CustomDuration `json:"timeout,omitempty"`
	Port        int                 `json:"port,omitempty"`   // works for all checks except 'icmp' and 'exec'
	Expect      string              `json:"expect,omitempty"` // works for 'tcp', 'ssh', 'http', 'exec' checks except 'icmp'
	Disable     bool                `json:"disable,omitempty"`
	Tags        []string            `json:"tags,omitempty"`
	MemberTag   string              `json:"member-tag,omitempty"` // lock a check to specific member(s)

	// TCP specific attributes
	TCPSend         string              `json:"send,omitempty"`
	TCPReadTimeout  util.CustomDuration `json:"read-timeout,omitempty"`
	TCPWriteTimeout util.CustomDuration `json:"write-timeout,omitempty"`
	TCPReadSize     int                 `json:"read-size,omitempty"`

	// HTTP specific attributes
	HTTPURL         string `json:"url,omitempty"`
	HTTPMethod      string `json:"method,omitempty"`
	HTTPSSL         bool   `json:"ssl,omitempty"`
	HTTPStatusCode  int    `json:"status-code,omitempty"`
	HTTPRequestBody string `json:"request-body,omitempty"` // Only used if 'Method' is 'GET'

	// Exec specific attributes
	ExecCommand    string   `json:"command,omitempty"`
	ExecArgs       []string `json:"args,omitempty"`
	ExecReturnCode int      `json:"return-code,omitempty"`

	// DNS specific attributes
	DnsTarget        string              `json:"dns-target,omitempty"`
	DnsRecordType    string              `json:"dns-record-type,omitempty"`
	DnsMaxTime       util.CustomDuration `json:"dns-max-time,omitempty"`
	DnsExpectedCount int                 `json:"dns-expected-count,omitempty"`

	// Alerting related configuration
	WarningThreshold  int      `json:"warning-threshold,omitempty"`  // how many times a check must fail before a warning alert is emitted
	CriticalThreshold int      `json:"critical-threshold,omitempty"` // how many times a check must fail before a critical alert is emitted
	WarningAlerter    []string `json:"warning-alerter,omitempty"`    // these alerters will be contacted when a warning threshold is hit
	CriticalAlerter   []string `json:"critical-alerter,omitempty"`   // these alerters will be contacted when a critical threshold is hit
}

TODO: This should probably be split up between each individual check type

type Response

type Response struct{}

type RootMonitorConfig

type RootMonitorConfig struct {
	GID            string // goroutine id
	Name           string // monitor config name in member dir
	ConfigName     string // monitor config name in monitor dir
	MemberID       string
	Config         *MonitorConfig
	MessageChannel chan *alerter.Message
	StateChannel   chan *state.Message
	StopChannel    chan bool
	Ticker         *time.Ticker
	Log            log.FieldLogger
}

type SampleMonitor

type SampleMonitor struct {
	Base
}

func (*SampleMonitor) Validate

func (s *SampleMonitor) Validate() error

type TCPMonitor

type TCPMonitor struct {
	Base

	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	ConnTimeout  time.Duration
	ReadSize     int
}

func NewTCPMonitor

func NewTCPMonitor(rmc *RootMonitorConfig) *TCPMonitor

func (*TCPMonitor) Validate

func (t *TCPMonitor) Validate() error

Jump to

Keyboard shortcuts

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