check

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 12 Imported by: 67

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

View Source
var EventPlatformNameTranslations = map[string]string{
	"dbm-samples":              "Database Monitoring Query Samples",
	"dbm-metrics":              "Database Monitoring Query Metrics",
	"dbm-activity":             "Database Monitoring Activity Samples",
	"network-devices-metadata": "Network Devices Metadata",
}

EventPlatformNameTranslations contains human readable translations for event platform event types

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.

func TranslateEventPlatformEventTypes added in v0.9.0

func TranslateEventPlatformEventTypes(aggregatorStats interface{}) (interface{}, error)

TranslateEventPlatformEventTypes translates the event platform event types in aggregator stats to human readable names

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
	// GetSenderStats returns the stats from the last run of the check.
	GetSenderStats() (SenderStats, 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 SenderStats added in v0.9.0

type SenderStats struct {
	MetricSamples    int64
	Events           int64
	ServiceChecks    int64
	HistogramBuckets int64
	// EventPlatformEvents tracks the number of events submitted for each eventType
	EventPlatformEvents map[string]int64
}

SenderStats contains statistics showing the count of various types of telemetry sent by a check sender

func NewSenderStats added in v0.9.0

func NewSenderStats() SenderStats

NewSenderStats creates a new SenderStats

func (SenderStats) Copy added in v0.9.0

func (s SenderStats) Copy() (result SenderStats)

Copy creates a copy of the current SenderStats

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
	EventPlatformEvents      map[string]int64
	TotalEventPlatformEvents map[string]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
	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 SenderStats)

Add tracks a new execution time

type StubCheck added in v0.9.0

type StubCheck struct{}

StubCheck stubs a check, should only be used in tests

func (*StubCheck) Cancel added in v0.9.0

func (c *StubCheck) Cancel()

Cancel is a noop

func (*StubCheck) ConfigSource added in v0.9.0

func (c *StubCheck) ConfigSource() string

ConfigSource returns the empty string

func (*StubCheck) Configure added in v0.9.0

Configure is a noop

func (*StubCheck) GetSenderStats added in v0.9.0

func (c *StubCheck) GetSenderStats() (SenderStats, error)

GetSenderStats returns an empty map

func (*StubCheck) GetWarnings added in v0.9.0

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

GetWarnings returns an empty slice

func (*StubCheck) ID added in v0.9.0

func (c *StubCheck) ID() ID

ID returns the check name

func (*StubCheck) Interval added in v0.9.0

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

Interval returns a duration of one second

func (*StubCheck) IsTelemetryEnabled added in v0.9.0

func (c *StubCheck) IsTelemetryEnabled() bool

IsTelemetryEnabled returns false

func (*StubCheck) Run added in v0.9.0

func (c *StubCheck) Run() error

Run is a noop

func (*StubCheck) Stop added in v0.9.0

func (c *StubCheck) Stop()

Stop is a noop

func (*StubCheck) String added in v0.9.0

func (c *StubCheck) String() string

String provides a printable version of the check name

func (*StubCheck) Version added in v0.9.0

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