shared

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MetaNcPlugin = "nc#plugin"

MetaNcPlugin contains the metadata key for storing the plugin instance.

Variables

This section is empty.

Functions

func DurationString added in v0.1.4

func DurationString(duration time.Duration) string

DurationString outputs a time.Duration variable in the same way as time.Duration.String() with additional support for days instead of just hours, minutes and seconds.

func FormatBinarySize added in v0.1.5

func FormatBinarySize(size float64) string

FormatBinarySize expects a size given in bytes and returns a formatted string with a precision of two with the most appropriate unit, which can either be B, K, M, G or T.

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 BaseModule added in v0.1.6

type BaseModule struct{}

BaseModule represents a generic module from which all other module types should originate.

func (*BaseModule) DefineFlags added in v0.1.6

func (m *BaseModule) DefineFlags(kp KingpinInterface)

DefineFlags defines an empty method which can be overridden by modules to specify a common subset of flags for all the module plugins.

func (*BaseModule) Execute added in v0.1.6

func (m *BaseModule) Execute(plugin Plugin)

Execute calls the 'Execute' method of the given plugin. This method can be overridden by modules to initialize module-specific code/variables before executing the plugin OR to suppress execution of a plugin in specific cases.

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 represents 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 BasePluginSummary added in v0.1.5

type BasePluginSummary struct {
	*nagopher.BaseSummary
}

BasePluginSummary represents a generic nagopher 'BaseSummary'. While it does not currently offer any additional methods or attributes, it can be easily extended within the future. All plugins are supposed to use this type.

func NewPluginSummary added in v0.1.5

func NewPluginSummary() *BasePluginSummary

NewPluginSummary instantiates 'BasePluginSummary'.

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 Module added in v0.1.6

type Module interface {
	DefineFlags(KingpinInterface)
	Execute(Plugin)
	GetModuleCommand() ModuleCommand
}

Module represents a interface for all module types.

type ModuleCommand added in v0.1.2

type ModuleCommand struct {
	Name           string
	Description    string
	Module         Module
	PluginCommands PluginCommands
}

ModuleCommand represents a command declaration for a module, which contains one or more plugin commands

type ModuleCommands added in v0.1.2

type ModuleCommands []ModuleCommand

ModuleCommands represents a collection of 'ModuleCommand' structures with additional helper methods

func (ModuleCommands) GetByName added in v0.1.2

func (mc ModuleCommands) GetByName(name string) (command ModuleCommand, _ error)

GetByName tries to find a 'ModuleCommand' with the given name and returns if found. An error will be returned in case no module with such a name exists.

type Plugin

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

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

Plugin represents a interface for all plugin types.

type PluginCommand added in v0.1.2

type PluginCommand struct {
	Name        string
	Description string
	Plugin      Plugin
}

PluginCommand represents a command declaration for a single plugin, which contains a plugin instance for execution

type PluginCommands added in v0.1.2

type PluginCommands []PluginCommand

PluginCommands represents a collection of 'PluginCommand' structures with additional helper methods

func (PluginCommands) GetByName added in v0.1.2

func (pc PluginCommands) GetByName(name string) (command PluginCommand, _ error)

GetByName tries to find a 'PluginCommand' with the given name and returns if found. An error will be returned in case no plugin with such a name exists.

Jump to

Keyboard shortcuts

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