check

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 11 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(config integration.Config) bool

IsJMXConfig checks if a certain YAML config contains at least one instance of a JMX config

func IsJMXInstance

func IsJMXInstance(name string, instance integration.Data, initConfig integration.Data) bool

IsJMXInstance checks if a certain YAML instance 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 runs the check
	Run() error
	// Stop stops the check if it's running
	Stop()
	// Cancel cancels the check. Cancel is called when the check is unscheduled:
	// - unlike Stop, it is called even if the check is not running when it's unscheduled
	// - if the check is running, Cancel is called after Stop and may be called before the call to Stop completes
	Cancel()
	// String provides a printable version of the check name
	String() string
	// Configure configures the check
	Configure(config, initConfig integration.Data, source string) error
	// Interval returns the interval time for the check
	Interval() time.Duration
	// ID provides a unique identifier for every check instance
	ID() ID
	// GetWarnings returns the last warning registered by the check
	GetWarnings() []error
	// GetMetricStats gets metric stats from the sender
	GetMetricStats() (map[string]int64, error)
	// Version returns the version of the check if available
	Version() string
	// ConfigSource returns the configuration source of the check
	ConfigSource() string
	// IsTelemetryEnabled returns if telemetry is enabled for this check
	IsTelemetryEnabled() bool
}

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 {
	Name() string
	Load(config integration.Config, instance integration.Data) (Check, error)
}

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

A single check is loaded for the given `instance` YAML.

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
	CheckConfigSource    string
	CheckID              ID
	TotalRuns            uint64
	TotalErrors          uint64
	TotalWarnings        uint64
	MetricSamples        int64
	Events               int64
	ServiceChecks        int64
	TotalMetricSamples   uint64
	TotalEvents          uint64
	TotalServiceChecks   uint64
	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
	LastSuccessDate      int64     // most recent successful execution date, unix timestamp in seconds
	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

type StubCheck

type StubCheck struct{}

StubCheck stubs a check, should only be used in tests

func (*StubCheck) Cancel

func (c *StubCheck) Cancel()

Cancel is a noop

func (*StubCheck) ConfigSource

func (c *StubCheck) ConfigSource() string

ConfigSource returns the empty string

func (*StubCheck) Configure

Configure is a noop

func (*StubCheck) GetMetricStats

func (c *StubCheck) GetMetricStats() (map[string]int64, error)

GetMetricStats returns an empty map

func (*StubCheck) GetWarnings

func (c *StubCheck) GetWarnings() []error

GetWarnings returns an empty slice

func (*StubCheck) ID

func (c *StubCheck) ID() ID

ID returns the check name

func (*StubCheck) Interval

func (c *StubCheck) Interval() time.Duration

Interval returns a duration of one second

func (*StubCheck) IsTelemetryEnabled

func (c *StubCheck) IsTelemetryEnabled() bool

IsTelemetryEnabled returns false

func (*StubCheck) Run

func (c *StubCheck) Run() error

Run is a noop

func (*StubCheck) Stop

func (c *StubCheck) Stop()

Stop is a noop

func (*StubCheck) String

func (c *StubCheck) String() string

String provides a printable version of the check name

func (*StubCheck) Version

func (c *StubCheck) Version() string

Version returns the empty string

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