shared

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPersistentStore

func LoadPersistentStore(identifier string, v interface{}) error

LoadPersistentStore loads a persistent shm-based store, which can represent any structure/type as long as it can be unmarshalled by the builtin 'json.Unmarshal' function. Please note that this function should only be called when protected by a flock, as several processes operating the same store can lead to data loss.

func NagopherRangeVar

func NagopherRangeVar(s kingpin.Settings, target *nagopher.Range)

NagopherRangeVar is a helper method for defining kingpin flags which should be parsed as a Nagopher range specifier.

func RegexpSubMatchMap

func RegexpSubMatchMap(r *regexp.Regexp, str string) (map[string]string, bool)

RegexpSubMatchMap is a utility function which matches a string against a regular expression and returns a map of the type 'map[string]string', which contains all named capture groups.

func RetryDuring

func RetryDuring(timeout time.Duration, delay time.Duration, function func() error) (err error)

RetryDuring retries a given function until it no longer returns an error or the timeout value was reached. The delay parameter specifies the delay between each unsuccessful attempt.

func Round

func Round(value float64, precision float64) float64

Round is a utility function which allows rounding a float64 to a given precision

func SavePersistentStore

func SavePersistentStore(identifier string, v interface{}) error

SavePersistentStore stores a persistent shm-based store, which can represent any structure/type as long as it can be marshalled by the builtin 'json.Marshal' function. Please note that this function should only be called when protected by a flock, as several processes operating the same store can lead to data loss.

Types

type BasePlugin

type BasePlugin struct {
	Verbose       bool
	WarningRange  *nagopher.Range
	CriticalRange *nagopher.Range
}

BasePlugin represents a generic plugin from which all other plugin types should originate.

func NewPlugin

func NewPlugin() *BasePlugin

NewPlugin instantiates 'BasePlugin'.

func (*BasePlugin) DefineFlags

func (p *BasePlugin) DefineFlags(kp KingpinInterface, useDefaultRanges bool)

DefineFlags defines common flags which should be provided by all plugins. It will also define flags for the default ranges, unless p.useDefaultRanges is set to false.

func (*BasePlugin) ExecuteCheck

func (p *BasePlugin) ExecuteCheck(check *nagopher.Check)

ExecuteCheck is a helper method which creates a new nagopher 'Runtime', executes a check and exits

func (*BasePlugin) ExecutePersistentCheck

func (p *BasePlugin) ExecutePersistentCheck(check *nagopher.Check, uniqueKey string, store interface{})

ExecutePersistentCheck is a helper method which extends Execute() with flock (based on given unique key, which should be chosen wisely) and a persistent store, which is also named by the unique key passed. This is especially useful when used with contexts like 'DeltaContext', which compare the current measurement against a previously measurement.

func (*BasePlugin) Probe

func (p *BasePlugin) Probe(warnings *nagopher.WarningCollection) (metrics []nagopher.Metric, _ error)

Probe represents the method executing the actual check/metrics logic and should be overridden by each plugin for returning metrics. It also supports adding warnings through the passed 'WarningCollection' or returning an error in case metric collection goes wrong.

type BasePluginResource

type BasePluginResource struct {
	*nagopher.BaseResource
	// contains filtered or unexported fields
}

BasePluginResource presents a generic nagopher 'BaseResource' linked to a plugin.

func NewPluginResource

func NewPluginResource(plugin Plugin) *BasePluginResource

NewPluginResource instantiates 'BasePluginResource' and links it with the given plugin.

func (*BasePluginResource) Probe

Probe is an override for 'BaseResource.Probe(...)', which is being called by nagopher for collecting metrics. This method should never be overridden by any of the plugins, as it will just pass all arguments to 'Plugin.Probe()', where the plugins should define their actual check/metrics logic.

type KingpinInterface

type KingpinInterface interface {
	Arg(name, help string) *kingpin.ArgClause
	Flag(name, help string) *kingpin.FlagClause
}

KingpinInterface is a generic interface for kingpin, which is implemented by both "kingpin.Application" and "kingpin.CmdClause". This allows us to define a single "DefineFlags" method in the "Plugin" interface, which can handle both top-level and command-level flags.

type Plugin

type Plugin interface {
	DefineFlags(kp KingpinInterface)
	Execute()

	Probe(*nagopher.WarningCollection) ([]nagopher.Metric, error)
}

Plugin represents a interface for all plugin types.

Jump to

Keyboard shortcuts

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