Documentation ¶
Index ¶
- Constants
- func DurationString(duration time.Duration) string
- func FormatBinarySize(size float64) string
- func LoadPersistentStore(identifier string, v interface{}) error
- func NagopherRangeVar(s kingpin.Settings, target **nagopher.Range)
- func RegexpSubMatchMap(r *regexp.Regexp, str string) (map[string]string, bool)
- func RetryDuring(timeout time.Duration, delay time.Duration, function func() error) (err error)
- func Round(value float64, precision float64) float64
- func SavePersistentStore(identifier string, v interface{}) error
- type BaseModule
- type BasePlugin
- func (p *BasePlugin) DefineFlags(kp KingpinInterface, useDefaultRanges bool)
- func (p *BasePlugin) ExecuteCheck(check *nagopher.Check)
- func (p *BasePlugin) ExecutePersistentCheck(check *nagopher.Check, uniqueKey string, store interface{})
- func (p *BasePlugin) Probe(warnings *nagopher.WarningCollection) (metrics []nagopher.Metric, _ error)
- type BasePluginResource
- type BasePluginSummary
- type KingpinInterface
- type Module
- type ModuleCommand
- type ModuleCommands
- type Plugin
- type PluginCommand
- type PluginCommands
Constants ¶
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
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
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 ¶
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 ¶
NagopherRangeVar is a helper method for defining kingpin flags which should be parsed as a Nagopher range specifier.
func RegexpSubMatchMap ¶
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 ¶
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 SavePersistentStore ¶
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 ¶
BasePlugin represents a generic plugin from which all other plugin types should originate.
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 ¶
func (pr *BasePluginResource) Probe(warnings *nagopher.WarningCollection) ([]nagopher.Metric, error)
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
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.