metric

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KibiByte uint64 = 1024
	MebiByte        = 1024 * KibiByte
	GibiByte        = 1024 * MebiByte
	TebiByte        = 1024 * GibiByte
)

Variables

View Source
var (
	ErrThresholdInvalid = errors.New("threshold invalid")
)

Functions

func ParseThreshold

func ParseThreshold(threshold string, total uint64) (uint64, error)

ParseThreshold returns the parsed unit(UOM) from threshold

Total = 100MB; Threshold = 10% => 10MB Total = 100MB; Threshold = 30MB => 30MB Viable units are: kb, kib, mb, mib, gb, gib, tb, tib, %

func ThresholdFree

func ThresholdFree(threshold string, total uint64) (uint64, error)

ThresholdFree returns the threshold level relative to the total.

10% free from 100MB = 90MB used
15MB free from 100MB = 85MB used

func ThresholdUsed

func ThresholdUsed(threshold string, total uint64) (uint64, error)

ThresholdUsed returns the threshold level relative to the total.

90% used from 100MB = 10MB free (available) 85MB used from 100MB = 15MB free (available)

Types

type Metric

type Metric struct {
	Value    uint64
	Warning  uint64
	Critical uint64
	Total    uint64
	Type     string
}

Metric allows to check a metric for levels specified by its thresholds.

Is currently implemented for byte values in IEC - which is what Nagios plugins use.

func NewMetric

func NewMetric(value, total uint64) *Metric

NewMetric returns a new Metric.

TODO Value can not be greater than Total

func (*Metric) Perfdata

func (m *Metric) Perfdata(label string) perfdata.Perfdata

Perfdata returns a perfdata.Perfdata object for output with a plugin.

Values are scaled down to MB, so they are more readable. And we won't need that much precision.

func (*Metric) SetCritical

func (m *Metric) SetCritical(threshold string) (err error)

SetCritical parses critical level for free OR used and remembers the absolute value.

Used: Total 100 MB; Threshold 90% => If 90 MB used. Returns critical

Free: Total 100MB; Threshold 90% => If 10 MB free. Returns critical

func (*Metric) SetWarning

func (m *Metric) SetWarning(threshold string) (err error)

SetWarning parses warning level for free OR used and remembers the absolute value.

Used: Total 100 MB; Threshold 80% => If 80 MB used. Returns warning

Free: Total 100MB; Threshold 80% => If 20 MB free. Returns warning

func (*Metric) Status

func (m *Metric) Status() int

Status returns the Icinga status in perspective to the current value and thresholds.

Free: Value <= Warning will result in warning state Value <= Critical will result in critical state

Used: Value >= Warning will result in warning state Value >= Critical will result in critical state

Jump to

Keyboard shortcuts

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