golarm

package module
v0.0.0-...-bcbb8a3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2015 License: MIT Imports: 5 Imported by: 0

README

golarm

GoDoc Build Status Coverage Status Go Report Card

Fire alarms with system events

Usage

golarm.AddAlarm(golarm.SystemLoad(golarm.OneMinPeriod).Above(0.8).Run(func() {
		fmt.Println("System load >0.8 !!")
		smtp.SendMail(smtpHost, emailConf.Port, "System load >0.8 !!")
	}))

Usage example

Options

  • SystemLoad
// checks if the system load is lower or equal to 0.5
golarm.AddAlarm(golarm.SystemLoad(golarm.OneMinPeriod).AboveEqual(0.5).Run(func() {
   	fmt.Println("System load >=0.5 !!")
   }))
  • SystemUptime
// checks if the system has been running for less than 1 minute
golarm.AddAlarm(golarm.SystemUptime().Below(1).Run(func() {
  	fmt.Println("System just started !!")
  }))
  • SystemMemory / SystemSwap [Free, Used]
// checks if used memory is higher that 90%
golarm.AddAlarm(golarm.SystemMemory().Used().Above(90).Percent().Run(func() {
   	fmt.Println("Used system memory > 90% !!")
   }))
// checks if free memory is lower that 500MB
golarm.AddAlarm(golarm.SystemMemory().Free().BelowEqual(500).Run(func() {
   	fmt.Println("Free memory <= 500MB !!")
   }))
  • SystemProc [Status, RunningTime, Used (Memory)]
// checks if the process 72332 has changed to zombie status
golarm.AddAlarm(golarm.SystemProc(72332).Status(golarm.Zombie).Run(func() {
  	fmt.Println("Our process with PID 72332 became Zombie !!")
  }))
// checks if the process 72332 has been running for more than 20 minutes
golarm.AddAlarm(golarm.SystemProc(72332).RunningTime().Above(20).Run(func() {
  	fmt.Println("Our process with PID 72332 exceeded 20 minutes running !!")
  }))

TODO

  • Kilobytes / Megabytes / Gigabytes (currently megabytes by default)
  • Minutes / Hours / Days (currently minutes by default)

License

Distributed under MIT license. See LICENSE for more information.

Documentation

Index

Constants

View Source
const (
	Sleeping state = iota + 1
	Running
	Stopped
	Zombie
	Idle
	Unknown
)

Linux process states to be used with status alarms

View Source
const (
	OneMinPeriod period = iota + 1
	FiveMinPeriod
	FifteenMinPeriod
)

Load average can be calculated for the last one minute, five minutes and fifteen minutes respectively. Load average is an indication of whether the system resources (mainly the CPU) are adequately available for the processes (system load) that are running, runnable or in uninterruptible sleep states during the previous n minutes.

Variables

View Source
var (
	ErrAlarmTypeNotDefined           = errors.New("Bad chain. Alarm type not defined")
	ErrComparisonNotDefined          = errors.New("Bad chain. Alarm comparison not defined")
	ErrExpectedNumWhenPercentage     = errors.New("Bad chain. A number is needed for applying a percentage")
	ErrIncorrectTypeForFree          = errors.New("Alarm type not set or trying to use Free with something different than memory or swap memory")
	ErrIncorrectTypeForUsed          = errors.New("Alarm type not set or trying to use Free with something different than memory, swap memory or memory used by a proc")
	ErrIncorrectTypeForTime          = errors.New("Alarm type not set or trying to use RunningTime with something different than uptime or uptime by a proc")
	ErrIncorrectTypeForStatus        = errors.New("Alarm type not set or trying to use Status with something different than SysteProcAlarm")
	ErrMultipleComparisonDefined     = errors.New("Alarm comparison already defined")
	ErrIncorrectTypeForAbove         = errors.New("Alarm type not set or trying to use Above with a status metric")
	ErrIncorrectTypeForBelow         = errors.New("Alarm type not set or trying to use Below with a status metric")
	ErrIncorrectTypeForPercentage    = errors.New("Couldn't apply percentage to uptime/status Alarms")
	ErrIncorrectValuesWithPercentage = errors.New("Couldn't apply percentage")
	ErrInexistentPid                 = errors.New("Pid does not exist")
	ErrIncorrectTypeForComparison    = errors.New("Alarm type not set or trying to use an incorrect comparison with this type of Alarm")
	ErrIncorrectTypeForMetric        = errors.New("Alarm type not set or trying to use an incorrect metric with this type of Alarm")
)

Error codes returned by failures when trying to create the alert chain

View Source
var Alarms = make([]*Alarm, 0)

alarms pool

View Source
var Duration = 5

check interval set to 5 seconds as default

Functions

func AddAlarm

func AddAlarm(a *Alarm) error

AddAlarm adds an alarm to the pool and starts it immediately

Types

type Alarm

type Alarm struct {
	Err error
	// contains filtered or unexported fields
}

Alarm defines a running alarm

func SystemLoad

func SystemLoad(p period) *Alarm

SystemLoad creates an alarm based on load metric P is the period needed for calculating the load, and it could be OneMinPeriod, FiveMinPeriod or FifteenMinPeriod

func SystemMemory

func SystemMemory() *Alarm

SystemMemory creates an alarm based on memory metrics

func SystemProc

func SystemProc(pid uint) *Alarm

SystemProc creates an alarm based on a process specified by PID

func SystemSwap

func SystemSwap() *Alarm

SystemSwap creates an alarm based on swap memory metrics

func SystemUptime

func SystemUptime() *Alarm

SystemUptime creates an alarm based on system uptime

func (*Alarm) Above

func (j *Alarm) Above(v float64) *Alarm

Above compares if the specified alarm is greater than the number set

func (*Alarm) AboveEqual

func (j *Alarm) AboveEqual(v float64) *Alarm

AboveEqual compares if the specified alarm is greater or equal than the number set

func (*Alarm) Below

func (j *Alarm) Below(v float64) *Alarm

Below compares if the specified alarm is lower than the number set

func (*Alarm) BelowEqual

func (j *Alarm) BelowEqual(v float64) *Alarm

BelowEqual compares if the specified alarm is lower or equal than the number set

func (*Alarm) Equal

func (j *Alarm) Equal(v float64) *Alarm

Equal compares if the specified alarm is equal than the number set

func (*Alarm) Free

func (j *Alarm) Free() *Alarm

Free allows to specify that the created alarm will use the free memory as main metric

func (*Alarm) Percent

func (j *Alarm) Percent() *Alarm

Percent allows using the value specified as a percentage

func (*Alarm) Run

func (j *Alarm) Run(f func()) *Alarm

Run allows a func to be specified. This callback will be executed when the alarm is fired

func (*Alarm) RunningTime

func (j *Alarm) RunningTime() *Alarm

RunningTime gets the time a process has been running

func (*Alarm) SetMetricsManager

func (j *Alarm) SetMetricsManager(m sigarMetrics)

SetMetricsManager allows to set a specific sigar manager

func (*Alarm) Status

func (j *Alarm) Status(s state) *Alarm

Status allows to specify the state for a given process

func (*Alarm) Used

func (j *Alarm) Used() *Alarm

Used allows to specify that the created alarm will use the used memory as main metric

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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