checks

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2018 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandMetrics = map[string]MetricInfo{
	"execution_time": {
		Unit: "ms",
	},
}
View Source
var DockerStatsMetrics = map[string]MetricInfo{}
View Source
var GlobalClient = http.Client{
	Timeout: time.Duration(10 * time.Second),
}
View Source
var GlobalSCollector map[Host]CurrentMetrics = make(map[Host]CurrentMetrics)
View Source
var NewCommand = func(config Config, logger *log.Logger) (Checker, error) {
	var commandConfig CommandConfig
	err := json.Unmarshal([]byte(config.Config), &commandConfig)
	if err != nil {
		return nil, err
	}
	if commandConfig.Command == "" {
		return nil, errors.New("command: command to run cannot be blank")
	}
	if commandConfig.Shell == "" {
		commandConfig.Shell = "sh"
	}
	if commandConfig.OutputType != "" && commandConfig.OutputType != "number" {
		return nil, errors.New("command: invalid output type")
	}
	if commandConfig.OutputType == "number" {
		CommandMetrics["output"] = MetricInfo{
			Unit: "unit",
		}
	}
	return Checker(&Command{
		commandConfig.Command,
		commandConfig.Shell,
		commandConfig.OutputType,
		logger}), nil
}
View Source
var NewDockerRemoteDocker = func(config Config, logger *log.Logger) (Checker, error) {

	var remoteDockerConfig RemoteDockerConfig
	err := json.Unmarshal([]byte(config.Config), &remoteDockerConfig)
	if err != nil {
		return nil, err
	}

	tool := utils.StringDefault(remoteDockerConfig.Tool, "nc")
	if !utils.FindStringInArray(tool, []string{"nc", "socat"}) {
		return nil, errors.New("checks: unknown tool in remote docker config")
	}

	if remoteDockerConfig.User == "" {
		return nil, errors.New("remote-docker: user cannot be blank")
	}

	if remoteDockerConfig.Host == "" {
		return nil, errors.New("remote-docker: host cannot be blank")
	}

	return Checker(&RemoteDocker{
		User:     remoteDockerConfig.User,
		Password: remoteDockerConfig.Password,
		Host:     remoteDockerConfig.Host,
		Key:      remoteDockerConfig.Key,
		Tool:     tool,
		log:      logger,
	}), nil
}
View Source
var NewDockerStats = func(config Config, logger *log.Logger) (Checker, error) {
	var commandConfig DockerStatsConfig
	err := json.Unmarshal([]byte(config.Config), &commandConfig)
	if err != nil {
		return nil, err
	}
	return Checker(&DockerStats{logger}), nil
}
View Source
var NewPostgres = func(config Config, logger *log.Logger) (Checker, error) {
	postgres := new(Postgres)
	err := json.Unmarshal([]byte(config.Config), postgres)
	if err != nil {
		return nil, err
	}
	if postgres.ConnectionURL == "" {
		return nil, errors.New("postgres: connection url cannot be blank")
	}
	if len(postgres.MetricQueries) == 0 {
		return nil, errors.New("postgres: no metrics to query")
	}
	postgres.log = logger
	return Checker(postgres), nil
}
View Source
var NewRemoteCommand = func(config Config, logger *log.Logger) (Checker, error) {
	var commandConfig RemoteCommandConfig
	err := json.Unmarshal([]byte(config.Config), &commandConfig)
	if err != nil {
		return nil, err
	}
	if commandConfig.Command == "" {
		return nil, errors.New("remote-command: command to run cannot be blank")
	}
	if commandConfig.OutputType != "" && commandConfig.OutputType != "number" {
		return nil, errors.New("remote-command: invalid output type")
	}
	if commandConfig.OutputType == "number" {
		RemoteCommandMetrics["output"] = MetricInfo{
			Unit: "unit",
		}
	}
	return Checker(&RemoteCommand{
		commandConfig.Command,
		commandConfig.OutputType,
		commandConfig.SSHAuthOptions,
		logger}), nil
}
View Source
var NewSCollector = func(config Config, logger *log.Logger) (Checker, error) {
	var sCollectorConfig SCollectorConfig
	err := json.Unmarshal([]byte(config.Config), &sCollectorConfig)
	if err != nil {
		return nil, err
	}
	if sCollectorConfig.Host == "" {
		return nil, errors.New("scollector: host to collect stats via scollector cannot be blank")
	}
	return Checker(&SCollector{sCollectorConfig.Host}), nil
}
View Source
var NewTCP = func(config Config, logger *log.Logger) (Checker, error) {
	var tcpConfig TCPConfig
	err := json.Unmarshal([]byte(config.Config), &tcpConfig)
	if err != nil {
		return nil, err
	}
	if tcpConfig.Host == "" {
		return nil, errors.New("tcp: host to connect to cannot be blank")
	}
	if tcpConfig.Port == 0 {
		return nil, errors.New("tcp: port to connect to cannot be zero")
	}
	return Checker(&TCP{tcpConfig.Host, tcpConfig.Port, logger}), nil
}
View Source
var NewTestReport = func(config Config, logger *log.Logger) (Checker, error) {
	var testReportConfig TestReportConfig
	err := json.Unmarshal([]byte(config.Config), &testReportConfig)
	if err != nil {
		return nil, err
	}
	if testReportConfig.Command == "" {
		return nil, errors.New("command: command to run cannot be blank")
	}
	if testReportConfig.Shell == "" {
		testReportConfig.Shell = "sh"
	}
	return Checker(&TestReport{
		testReportConfig.Command,
		testReportConfig.Shell,
		logger}), nil
}
View Source
var NewWebPinger = func(config Config, logger *log.Logger) (Checker, error) {
	var webPingerConfig WebPingerConfig
	err := json.Unmarshal([]byte(config.Config), &webPingerConfig)
	if err != nil {
		return nil, err
	}
	if webPingerConfig.Address == "" {
		return nil, errors.New("web-ping: address to ping cannot be blank")
	}
	return Checker(&WebPinger{config, webPingerConfig, logger}), nil
}
View Source
var RemoteCommandMetrics = map[string]MetricInfo{
	"execution_time": {
		Unit: "ms",
	},
}
View Source
var TCPMetrics = map[string]MetricInfo{
	"latency": {
		Unit: "ms",
	},
}
View Source
var TestReportMetrics = map[string]MetricInfo{
	"execution_time": {
		Unit: "ms",
	},
}
View Source
var WebPingerMetrics = map[string]MetricInfo{
	"latency": {
		Unit: "ms",
	},
}

Functions

func Register

func Register(name string, constructorFn func(Config, *log.Logger) (Checker, error))

Types

type Checker

type Checker interface {
	Check() (data.CheckResponse, error)
	MetricInfo(string) MetricInfo
	MessageContext() string
}

The Checker implements a type of status check / mechanism of data collection which may be used for triggering alerts

func New

func New(config Config, logger *log.Logger) (Checker, error)

type Command

type Command struct {
	Command    string
	Shell      string
	OutputType string
	// contains filtered or unexported fields
}

func (*Command) Check

func (c *Command) Check() (data.CheckResponse, error)

func (*Command) MessageContext

func (c *Command) MessageContext() string

func (*Command) MetricInfo

func (c *Command) MetricInfo(metric string) MetricInfo

type CommandConfig

type CommandConfig struct {
	Command    string `json:"command"`
	Shell      string `json:"shell"`
	OutputType string `json:"output_type"`
}

type Config

type Config struct {
	ID             string              `json:"id"`
	Name           string              `json:"name"`
	Type           string              `json:"type"`
	SendAlerts     []string            `json:"send_alerts"`
	Backoff        backoffs.Config     `json:"backoff"`
	Config         json.RawMessage     `json:"config"`
	Assertions     []assertions.Config `json:"assertions"`
	Enabled        *bool               `json:"enabled,omitempty"`
	VerboseLogging *bool               `json:"verbose_logging,omitempty"`
}

type Container

type Container struct {
	Command string
	Created int
	Id      string
	Image   string
	Names   []string
	Ports   []PortConfig
	Status  string
}

type ContainerStats

type ContainerStats struct {
	Read    string `json:"read"`
	Network struct {
		RxDropped int `json:"rx_dropped"`
		RxBytes   int `json:"rx_bytes"`
		RxErrors  int `json:"rx_errors"`
		TxPackets int `json:"tx_packets"`
		TxDropped int `json:"tx_dropped"`
		RxPackets int `json:"rx_packets"`
		TxErrors  int `json:"tx_errors"`
		TxBytes   int `json:"tx_bytes"`
	} `json:"network"`
	MemoryStats struct {
		Stats struct {
			TotalRss int `json:"total_rss"`
		} `json:"stats"`
		MaxUsage int `json:"max_usage"`
		Usage    int `json:"usage"`
		Failcnt  int `json:"failcnt"`
		Limit    int `json:"limit"`
	} `json:"memory_stats"`
	CpuStats struct {
		CpuUsage struct {
			PercpuUsage       []int `json:"percpu_usage"`
			UsageInUsermode   int   `json:"usage_in_usermode"`
			TotalUsage        int   `json:"total_usage"`
			UsageInKernelmode int   `json:"usage_in_kernelmode"`
		} `json:"cpu_usage"`
		SystemCpuUsage int `json:"system_cpu_usage"`
	} `json:"cpu_stats"`
}

type CurrentMetrics

type CurrentMetrics map[string]*float64

type DockerStats

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

func (*DockerStats) Check

func (c *DockerStats) Check() (data.CheckResponse, error)

func (*DockerStats) MessageContext

func (c *DockerStats) MessageContext() string

func (*DockerStats) MetricInfo

func (c *DockerStats) MetricInfo(metric string) MetricInfo

type DockerStatsConfig

type DockerStatsConfig struct {
}

type Failure added in v0.2.2

type Failure struct {
	Type    string `xml:"type,attr"`
	Message string `xml:"message,attr"`
}

type Host

type Host string

type MetricInfo

type MetricInfo struct {
	Unit string
}

type MetricQuery

type MetricQuery struct {
	Metric string `json:"metric"`
	Query  string `json:"query"`
}

type PortConfig

type PortConfig struct {
	IP          string
	PrivatePort int
	PublicPort  int
	Type        string
}

type Postgres

type Postgres struct {
	ConnectionURL string        `json:"connection_url"`
	MetricQueries []MetricQuery `json:"metric_queries"`
	// contains filtered or unexported fields
}

func (*Postgres) Check

func (p *Postgres) Check() (data.CheckResponse, error)

func (*Postgres) MessageContext

func (p *Postgres) MessageContext() string

func (*Postgres) MetricInfo

func (p *Postgres) MetricInfo(metric string) MetricInfo

type RemoteCommand

type RemoteCommand struct {
	Command        string
	OutputType     string
	SSHAuthOptions SSHAuthOptions
	// contains filtered or unexported fields
}

func (*RemoteCommand) Check

func (c *RemoteCommand) Check() (data.CheckResponse, error)

func (*RemoteCommand) MessageContext

func (c *RemoteCommand) MessageContext() string

func (*RemoteCommand) MetricInfo

func (c *RemoteCommand) MetricInfo(metric string) MetricInfo

type RemoteCommandConfig

type RemoteCommandConfig struct {
	Command        string         `json:"command"`
	OutputType     string         `json:"output_type"`
	SSHAuthOptions SSHAuthOptions `json:"ssh_auth_options"`
}

type RemoteDocker

type RemoteDocker struct {
	User     string
	Password string
	Host     string
	Key      string
	Tool     string
	// contains filtered or unexported fields
}

func (*RemoteDocker) Check

func (r *RemoteDocker) Check() (data.CheckResponse, error)

func (*RemoteDocker) MessageContext

func (r *RemoteDocker) MessageContext() string

func (*RemoteDocker) MetricInfo

func (r *RemoteDocker) MetricInfo(metric string) MetricInfo

type RemoteDockerConfig

type RemoteDockerConfig struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
	Key      string `json:"key"`
	Tool     string `json:"tool"`
}

type SCollector

type SCollector struct {
	Host string
}

func (*SCollector) Check

func (sc *SCollector) Check() (data.CheckResponse, error)

func (*SCollector) MessageContext

func (sc *SCollector) MessageContext() string

func (*SCollector) MetricInfo

func (sc *SCollector) MetricInfo(metric string) MetricInfo

type SCollectorConfig

type SCollectorConfig struct {
	Host string `json:"host"`
}

type SSHAuthOptions

type SSHAuthOptions struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Key      string `json:"key"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
}

type SSHAuthenticator

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

func NewSSHAuthenticator

func NewSSHAuthenticator(logger *log.Logger, options SSHAuthOptions) *SSHAuthenticator

func (*SSHAuthenticator) Cleanup

func (s *SSHAuthenticator) Cleanup() error

type TCP

type TCP struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

func (*TCP) Check

func (t *TCP) Check() (data.CheckResponse, error)

func (*TCP) MessageContext

func (t *TCP) MessageContext() string

func (*TCP) MetricInfo

func (t *TCP) MetricInfo(metric string) MetricInfo

type TCPConfig

type TCPConfig struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

type TestCase added in v0.2.2

type TestCase struct {
	Name      string    `xml:"name,attr"`
	Time      float64   `xml:"time,attr"`
	Classname string    `xml:"classname,attr"`
	Failure   *Failure  `xml:"failure"`
	Skipped   *struct{} `xml:"skipped"`
}

type TestReport added in v0.2.2

type TestReport struct {
	Command string
	Shell   string
	// contains filtered or unexported fields
}

func (*TestReport) Check added in v0.2.2

func (c *TestReport) Check() (data.CheckResponse, error)

func (*TestReport) MessageContext added in v0.2.2

func (c *TestReport) MessageContext() string

func (*TestReport) MetricInfo added in v0.2.2

func (c *TestReport) MetricInfo(metric string) MetricInfo

type TestReportConfig added in v0.2.2

type TestReportConfig struct {
	Command string `json:"command"`
	Shell   string `json:"shell"`
}

type Testsuite added in v0.2.2

type Testsuite struct {
	Name      string      `xml:"name,attr"`
	Tests     int         `xml:"tests,attr"`
	Failures  int         `xml:"failures,attr"`
	Errors    int         `xml:"errors,attr"`
	Timestamp string      `xml:"timestamp,attr"`
	Time      float64     `xml:"time,attr"`
	Hostname  string      `xml:"hostname,attr"`
	Testcases []*TestCase `xml:"testcase"`
}

type WebPinger

type WebPinger struct {
	Config          Config
	WebPingerConfig WebPingerConfig
	// contains filtered or unexported fields
}

func (*WebPinger) Check

func (wp *WebPinger) Check() (data.CheckResponse, error)

func (*WebPinger) MessageContext

func (wp *WebPinger) MessageContext() string

func (*WebPinger) MetricInfo

func (wp *WebPinger) MetricInfo(metric string) MetricInfo

type WebPingerConfig

type WebPingerConfig struct {
	Address string            `json:"address"`
	Headers map[string]string `json:"headers"`
}

Jump to

Keyboard shortcuts

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