Skip to content

Instantly share code, notes, and snippets.

@andrewhampton
Created March 24, 2015 18:39
Show Gist options
  • Save andrewhampton/a7886cab5d3ee8ee5b81 to your computer and use it in GitHub Desktop.
Save andrewhampton/a7886cab5d3ee8ee5b81 to your computer and use it in GitHub Desktop.
require "string"
os = require "os"
alert = require "alert"
local alert_threshold = read_config("alert_threshold") or 5
local alert_throttle_time = read_config("alert_throttle_time") or 300
local nanosecondsInASecond = 1000000000
alert.set_throttle(alert_throttle_time * nanosecondsInASecond)
function process_message ()
local buffers = read_message("Fields[Buffers]")
local cached = read_message("Fields[Cached]")
local memFree = read_message("Fields[MemFree]")
local memTotal = read_message("Fields[MemTotal]")
local pctMemFree = ((buffers + cached + memFree) / memTotal) * 100
local host = read_message("Hostname")
local currentTime = os.time() * nanosecondsInASecond
if pctMemFree < alert_threshold and not alert.throttled(currentTime) then
local payload = string.format("Low Memory on %s, only %d percent free", host, pctMemFree)
alert.send(currentTime, payload)
end
return 0
end
function timer_event(ns)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment