项目作者: msempere

项目描述 :
Fire alarms with system events
高级语言: Go
项目地址: git://github.com/msempere/golarm.git
创建时间: 2015-08-14T16:51:53Z
项目社区:https://github.com/msempere/golarm

开源协议:MIT License

下载


golarm

GoDoc
Build Status
Coverage Status
Go Report Card

Fire alarms with system events

Usage

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

Usage example

Options

  • SystemLoad

    1. // checks if the system load is lower or equal to 0.5
    2. golarm.AddAlarm(golarm.SystemLoad(golarm.OneMinPeriod).AboveEqual(0.5).Run(func() {
    3. fmt.Println("System load >=0.5 !!")
    4. }))
  • SystemUptime

    1. // checks if the system has been running for less than 1 minute
    2. golarm.AddAlarm(golarm.SystemUptime().Below(1).Run(func() {
    3. fmt.Println("System just started !!")
    4. }))
  • SystemMemory / SystemSwap [Free, Used]

    1. // checks if used memory is higher that 90%
    2. golarm.AddAlarm(golarm.SystemMemory().Used().Above(90).Percent().Run(func() {
    3. fmt.Println("Used system memory > 90% !!")
    4. }))
    1. // checks if free memory is lower that 500MB
    2. golarm.AddAlarm(golarm.SystemMemory().Free().BelowEqual(500).Run(func() {
    3. fmt.Println("Free memory <= 500MB !!")
    4. }))
  • SystemProc [Status, RunningTime, Used (Memory)]

    1. // checks if the process 72332 has changed to zombie status
    2. golarm.AddAlarm(golarm.SystemProc(72332).Status(golarm.Zombie).Run(func() {
    3. fmt.Println("Our process with PID 72332 became Zombie !!")
    4. }))
    1. // checks if the process 72332 has been running for more than 20 minutes
    2. golarm.AddAlarm(golarm.SystemProc(72332).RunningTime().Above(20).Run(func() {
    3. fmt.Println("Our process with PID 72332 exceeded 20 minutes running !!")
    4. }))

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.