monitoring

package
v0.0.0-...-a2846b3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

The Tideland Go Library monitoring package supports three kinds of system monitoring. They are helpful to understand what's happening inside a system during runtime. So execution times can be measured and analyzed, stay-set variables integrated and dynamic control value retrieval provided. The backend is exchangeable. So the StandardBackend workes like described above, the NullBackend does nothing, and own implementations can integrate external systems. Additionally filters can be added to reduce the monitoring to the points of interest.

Index

Constants

View Source
const (
	ErrMonitoringPanicked = iota + 1
	ErrMonitoringCannotBeRecovered
	ErrMeasuringPointNotExists
	ErrStaySetVariableNotExists
	ErrDynamicStatusNotExists
)

Variables

This section is empty.

Functions

func DecrVariable

func DecrVariable(id string)

DecrVariable decreases a stay-set variable.

func DynamicStatusValuesDo

func DynamicStatusValuesDo(f func(DynamicStatusValue)) error

DynamicStatusValuesDo performs the function f for all status values.

func DynamicStatusValuesPrintAll

func DynamicStatusValuesPrintAll() error

DynamicStatusValuesPrintAll prints all status values to STDOUT.

func DynamicStatusValuesWrite

func DynamicStatusValuesWrite(w io.Writer, ff func(DynamicStatusValue) bool) error

DynamicStatusValuesWrite prints the status values for which the passed function returns true to the passed writer.

func IncrVariable

func IncrVariable(id string)

IncrVariable increases a stay-set variable.

func IsDynamicStatusNotExistsError

func IsDynamicStatusNotExistsError(err error) bool

IsDynamicStatusNotExistsError returns true, if the error signals that a wanted dynamic status cannot be retrieved because it doesn't exists.

func IsMeasuringPointNotExistsError

func IsMeasuringPointNotExistsError(err error) bool

IsMeasuringPointNotExistsError returns true, if the error signals that a wanted measuring point cannot be retrieved because it doesn't exists.

func IsMonitoringCannotBeRecoveredError

func IsMonitoringCannotBeRecoveredError(err error) bool

IsMonitoringCannotBeRecoveredError returns true, if the error signals that the monitoring backend has panicked to often and cannot be recovered.

func IsMonitoringPanickedError

func IsMonitoringPanickedError(err error) bool

IsMonitoringPanickedError returns true, if the error signals that the monitoring backend panicked.

func IsStaySetVariableNotExistsError

func IsStaySetVariableNotExistsError(err error) bool

IsStaySetVariableNotExistsError returns true, if the error signals that a wanted stay-set variable cannot be retrieved because it doesn't exists.

func Measure

func Measure(id string, f func()) time.Duration

Measure the execution of a function.

func MeasuringPointsDo

func MeasuringPointsDo(f func(MeasuringPoint)) error

MeasuringPointsDo performs the function f for all measuring points.

func MeasuringPointsPrintAll

func MeasuringPointsPrintAll() error

MeasuringPointsPrintAll prints all measuring points to STDOUT.

func MeasuringPointsWrite

func MeasuringPointsWrite(w io.Writer, ff func(MeasuringPoint) bool) error

MeasuringPointsWrite prints the measuring points for which the passed function returns true to the passed writer.

func PackageVersion

func PackageVersion() version.Version

PackageVersion returns the version of the version package.

func ReadStatus

func ReadStatus(id string) (string, error)

ReadStatus returns the dynamic status for an id.

func Register

func Register(id string, rf DynamicStatusRetriever)

Register registers a new dynamic status retriever function.

func Reset

func Reset() error

Reset clears all monitored values.

func SetBackend

func SetBackend(mb Backend)

SetBackend allows to switch the monitoring backend.

func SetVariable

func SetVariable(id string, v int64)

SetVariable sets a value of a stay-set variable.

func StaySetVariablesDo

func StaySetVariablesDo(f func(StaySetVariable)) error

StaySetVariablesDo performs the function f for all variables.

func StaySetVariablesPrintAll

func StaySetVariablesPrintAll() error

StaySetVariablesPrintAll prints all stay-set variables to STDOUT.

func StaySetVariablesWrite

func StaySetVariablesWrite(w io.Writer, ff func(StaySetVariable) bool) error

StaySetVariablesWrite prints the stay-set variables for which the passed function returns true to the passed writer.

Types

type Backend

type Backend interface {
	// BeginMeasuring starts a new measuring with a given id.
	BeginMeasuring(id string) Measuring

	// ReadMeasuringPoint returns the measuring point for an id.
	ReadMeasuringPoint(id string) (MeasuringPoint, error)

	// MeasuringPointsDo performs the function f for
	// all measuring points.
	MeasuringPointsDo(f func(MeasuringPoint)) error

	// SetVariable sets a value of a stay-set variable.
	SetVariable(id string, v int64)

	// IncrVariable increases a variable.
	IncrVariable(id string)

	// DecrVariable decreases a variable.
	DecrVariable(id string)

	// ReadVariable returns the stay-set variable for an id.
	ReadVariable(id string) (StaySetVariable, error)

	// StaySetVariablesDo performs the function f for all
	// variables.
	StaySetVariablesDo(f func(StaySetVariable)) error

	// Register registers a new dynamic status retriever function.
	Register(id string, rf DynamicStatusRetriever)

	// ReadStatus returns the dynamic status for an id.
	ReadStatus(id string) (string, error)

	// DynamicStatusValuesDo performs the function f for all
	// status values.
	DynamicStatusValuesDo(f func(DynamicStatusValue)) error

	// SetMeasuringFilter sets the new filter for measurings
	// and returns the current one.
	SetMeasuringsFilter(f IDFilter) IDFilter

	// SetMeasuringFilter sets the new filter for variables
	// and returns the current one.
	SetVariablesFilter(f IDFilter) IDFilter

	// SetRetrieversFilter sets the new filter for status retrievers
	// and returns the current one.
	SetRetrieversFilter(f IDFilter) IDFilter

	// Reset clears all monitored values.
	Reset() error

	// Stop tells the backend that a new one has been set.
	Stop()
}

Backend defines the interface for a type managing all the information provided or needed by the public functions of the monitoring package.

func NewNullBackend

func NewNullBackend() Backend

NewNullBackend starts the null monitoring backend doing nothing.

func NewStandardBackend

func NewStandardBackend() Backend

NewStandardBackend starts the standard monitoring backend.

type DynamicStatusRetriever

type DynamicStatusRetriever func() (string, error)

DynamicStatusRetriever is called by the server and returns a current status as string.

type DynamicStatusValue

type DynamicStatusValue interface {
	fmt.Stringer

	// ID returns the identifier of the status value.
	ID() string

	// Value returns the retrieved value as string.
	Value() string
}

DynamicStatusValue contains one retrieved value.

type DynamicStatusValues

type DynamicStatusValues []DynamicStatusValue

DynamicStatusValues is a set of dynamic status values.

func (DynamicStatusValues) Len

func (d DynamicStatusValues) Len() int

func (DynamicStatusValues) Less

func (d DynamicStatusValues) Less(i, j int) bool

func (DynamicStatusValues) Swap

func (d DynamicStatusValues) Swap(i, j int)

type IDFilter

type IDFilter func(id string) bool

IDFilter allows to add filter for execution time measurings, stay-set values, and dynamic status retriever. If set only monitorings with the filter returning true will be done.

func SetMeasuringsFilter

func SetMeasuringsFilter(f IDFilter) IDFilter

SetMeasuringFilter sets the new filter for measurings and returns the current one.

func SetRetrieversFilter

func SetRetrieversFilter(f IDFilter) IDFilter

SetRetrieversFilter sets the new filter for status retrievers and returns the current one.

func SetVariablesFilter

func SetVariablesFilter(f IDFilter) IDFilter

SetMeasuringFilter sets the new filter for variables and returns the current one.

type Measuring

type Measuring interface {
	// EndMeasuring ends the measuring and passes its
	// data to the backend.
	EndMeasuring() time.Duration
}

Measuring defines one execution time measuring containg the ID and the starting time of the measuring and able to pass this data after the end of the measuring to its backend.

func BeginMeasuring

func BeginMeasuring(id string) Measuring

BeginMeasuring starts a new measuring with a given id. All measurings with the same id will be aggregated.

type MeasuringPoint

type MeasuringPoint interface {
	fmt.Stringer

	// ID returns the identifier of the measuring point.
	ID() string

	// Count returns how often this point has been measured.
	Count() int64

	// MinDuration returns the shortest execution time.
	MinDuration() time.Duration

	// MaxDuration returns the longest execution time.
	MaxDuration() time.Duration

	// AvgDuration returns the average execution time.
	AvgDuration() time.Duration
}

MeasuringPoint defines the collected information for one execution time measuring point.

func ReadMeasuringPoint

func ReadMeasuringPoint(id string) (MeasuringPoint, error)

ReadMeasuringPoint returns the measuring point for an id.

type MeasuringPoints

type MeasuringPoints []MeasuringPoint

MeasuringPoints is a set of measuring points.

func (MeasuringPoints) Len

func (m MeasuringPoints) Len() int

func (MeasuringPoints) Less

func (m MeasuringPoints) Less(i, j int) bool

func (MeasuringPoints) Swap

func (m MeasuringPoints) Swap(i, j int)

type StaySetVariable

type StaySetVariable interface {
	fmt.Stringer

	// ID returns the identifier of the stay-set variable.
	ID() string

	// Count returns how often the value has been changed.
	Count() int64

	// ActValue returns the current value of the variable.
	ActValue() int64

	// MinValue returns the minimum value of the variable.
	MinValue() int64

	// MaxValue returns the maximum value of the variable.
	MaxValue() int64

	// MinValue returns the average value of the variable.
	AvgValue() int64
}

StaySetVariable contains the cumulated values for one stay-set variable.

func ReadVariable

func ReadVariable(id string) (StaySetVariable, error)

ReadVariable returns the stay-set variable for an id.

type StaySetVariables

type StaySetVariables []StaySetVariable

StaySetVariables is a set of stay-set variables.

func (StaySetVariables) Len

func (s StaySetVariables) Len() int

func (StaySetVariables) Less

func (s StaySetVariables) Less(i, j int) bool

func (StaySetVariables) Swap

func (s StaySetVariables) Swap(i, j int)

Jump to

Keyboard shortcuts

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