Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple, time-based OOM check script for use with riemann-sumd
#!/bin/bash
# Run on a minutely basis by https://github.com/bmhatfield/riemann-sumd/
LAST_OOM_WINDOW=5;
LAST_OOM="$(grep 'Out of memory' /var/log/kern.log | tail -n 1)";
LAST_OOM_TIME=${LAST_OOM:0:15};
if [ -n "${LAST_OOM_TIME}" ]; then
if [ $(($((`date +%s` - `date --date="${LAST_OOM_TIME}" +%s`)) / 60 )) -le ${LAST_OOM_WINDOW} ]; then
echo "CRITICAL: OOM within last ${LAST_OOM_WINDOW} minutes!"
echo ${LAST_OOM}
exit 2
else
echo "OK: Recent OOM but outside last ${LAST_OOM_WINDOW} minutes";
echo "LAST_OOM: ${LAST_OOM}"
exit 0
fi;
else
echo "OK: No recent OOM";
exit 0
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.