check

package
v0.0.0-...-c036721 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2018 License: Apache-2.0 Imports: 10 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 CheckConfig 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

View Source
const (
	// DefaultCheckInterval is the interval in seconds the scheduler should apply
	// when no value was provided in Check configuration.
	DefaultCheckInterval time.Duration = 15 * time.Second
)

Variables

This section is empty.

Functions

func IsConfigJMX

func IsConfigJMX(name string, initConf ConfigData) bool

IsConfigJMX 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 ConfigData) 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
}

Check is an interface for types capable to run checks

type Config

type Config struct {
	Name          string       // the name of the check
	Instances     []ConfigData // array of Yaml configurations
	InitConfig    ConfigData   // the init_config in Yaml (python check only)
	MetricConfig  ConfigData   // the metric config in Yaml (jmx check only)
	LogsConfig    ConfigData   // the logs config in Yaml (logs-agent only)
	ADIdentifiers []string     // the list of AutoDiscovery identifiers (optional)
}

Config is a generic container for configuration files

func (*Config) AddMetrics

func (c *Config) AddMetrics(metrics ConfigData) error

AddMetrics adds metrics to a check configuration

func (*Config) CollectDefaultMetrics

func (c *Config) CollectDefaultMetrics() bool

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

func (*Config) Digest

func (c *Config) Digest() string

Digest returns an hash value representing the data stored in this configuration

func (*Config) Equal

func (c *Config) Equal(config *Config) bool

Equal determines whether the passed config is the same

func (*Config) GetTemplateVariablesForInstance

func (c *Config) GetTemplateVariablesForInstance(i int) (vars [][]byte)

GetTemplateVariablesForInstance returns a slice of raw template variables it found in a config instance template.

func (*Config) IsTemplate

func (c *Config) IsTemplate() bool

IsTemplate returns if the config has AD identifiers and template variables

func (*Config) String

func (c *Config) String() string

String YAML representation of the config

type ConfigData

type ConfigData []byte

ConfigData contains YAML code

func (*ConfigData) MergeAdditionalTags

func (c *ConfigData) MergeAdditionalTags(tags []string) error

MergeAdditionalTags merges additional tags to possible existing config tags

type ConfigJSONMap

type ConfigJSONMap map[string]interface{}

ConfigJSONMap is the generic type to hold YAML configurations

type ConfigRawMap

type ConfigRawMap map[interface{}]interface{}

ConfigRawMap is the generic type to hold YAML configurations

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 ConfigData) ID

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

func Identify

func Identify(check Check, instance ConfigData, initConfig ConfigData) ID

Identify returns an unique ID for a check and its configuration

type Loader

type Loader interface {
	Load(config 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
	CheckID            ID
	TotalRuns          uint64
	TotalErrors        uint64
	TotalWarnings      uint64
	Metrics            int64
	Events             int64
	ServiceChecks      int64
	TotalMetrics       int64
	TotalEvents        int64
	TotalServiceChecks int64
	ExecutionTimes     [32]int64 // circular buffer of recent run durations, most recent at [(TotalRuns+31) % 32]
	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

Jump to

Keyboard shortcuts

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