check

package
v0.0.0-...-3dd6856 Latest Latest
Warning

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

Go to latest
Published: May 20, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

package check

This package is responsible of defining the types representing an agent check along with an interface implemented by the code responsible to create a check instance based on an existing configuration.

Check Loaders

Loaders implement the CheckLoader interface, they are responsible to instantiate one object of type check.Check for every configuration instance within a integration.Config object. A Loader usually invokes the Configure method on check objects passing in the configuration instance in YAML format: how to use it, it's up to the check itself.

Usage example:

// given a list of configurations, try to load corresponding checks using different loaders
checks := []check.Check{}
for _, conf := range configs {
  for _, loader := range loaders {
    res, err := loader.Load(conf)
    if err == nil {
      checks = append(checks, res...)
    }
  }
}
// `checks` contains one check per configuration instance found.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectDefaultMetrics

func CollectDefaultMetrics(c integration.Config) bool

CollectDefaultMetrics returns if the config is for a JMX check which has collect_default_metrics: true

func IDToCheckName

func IDToCheckName(id ID) string

IDToCheckName returns the check name from a check ID

func IsJMXConfig

func IsJMXConfig(name string, initConf integration.Data) bool

IsJMXConfig checks if a certain YAML config is a JMX config

func Retry

func Retry(retryDuration time.Duration, retries int, callback func() error, friendlyName string) (err error)

Retry retries a callback up to `retries`-times in a `retryDuration` period of time, and bails out if the limit is reached.

Types

type Check

type Check interface {
	Run() error                                          // run the check
	Stop()                                               // stop the check if it's running
	String() string                                      // provide a printable version of the check name
	Configure(config, initConfig integration.Data) error // configure the check from the outside
	Interval() time.Duration                             // return the interval time for the check
	ID() ID                                              // provide a unique identifier for every check instance
	GetWarnings() []error                                // return the last warning registered by the check
	GetMetricStats() (map[string]int64, error)           // get metric stats from the sender
	Version() string                                     // return the version of the check if available
}

Check is an interface for types capable to run checks

type ID

type ID string

ID is the representation of the unique ID of a Check instance

func BuildID

func BuildID(checkName string, instance, initConfig integration.Data) ID

BuildID returns an unique ID for a check name and its configuration

func Identify

func Identify(check Check, instance integration.Data, initConfig integration.Data) ID

Identify returns an unique ID for a check and its configuration

type Loader

type Loader interface {
	Load(config integration.Config) ([]Check, error)
}

Loader is the interface wrapping the operations to load a check from different sources, like Python modules or Go objects.

A check is loaded for every `instance` found in the configuration file. Load is supposed to break down instances and return different checks.

type RetryableError

type RetryableError struct {
	Err error
}

RetryableError is the error type that Retry interprets as a request to retry the callback

func (RetryableError) Error

func (e RetryableError) Error() string

type Stats

type Stats struct {
	CheckName            string
	CheckVersion         string
	CheckID              ID
	TotalRuns            uint64
	TotalErrors          uint64
	TotalWarnings        uint64
	MetricSamples        int64
	Events               int64
	ServiceChecks        int64
	TotalMetricSamples   int64
	TotalEvents          int64
	TotalServiceChecks   int64
	ExecutionTimes       [32]int64 // circular buffer of recent run durations, most recent at [(TotalRuns+31) % 32]
	AverageExecutionTime int64     // average run duration
	LastExecutionTime    int64     // most recent run duration, provided for convenience
	LastError            string    // error that occurred in the last run, if any
	LastWarnings         []string  // warnings that occurred in the last run, if any
	UpdateTimestamp      int64     // latest update to this instance, unix timestamp in seconds
	// contains filtered or unexported fields
}

Stats holds basic runtime statistics about check instances

func NewStats

func NewStats(c Check) *Stats

NewStats returns a new check stats instance

func (*Stats) Add

func (cs *Stats) Add(t time.Duration, err error, warnings []error, metricStats map[string]int64)

Add tracks a new execution time

Directories

Path Synopsis
Package defaults provides common defaults used in agent checks
Package defaults provides common defaults used in agent checks

Jump to

Keyboard shortcuts

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