Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kmuto/eef02983a1750de310bcb29779d8e553 to your computer and use it in GitHub Desktop.
Save kmuto/eef02983a1750de310bcb29779d8e553 to your computer and use it in GitHub Desktop.
#!/bin/bash
(...usage表示やオプション解析などのコード...)
(WARNはWarningアラートにする分数、CRITはCriticalアラートにする分数)
WTIME=$(expr $(date "+%s") - 60 \* $WARN)
CTIME=$(expr $(date "+%s") - 60 \* $CRIT)
(ホストID $HOST、ホストメトリック $METRIC でCRIT分前〜現在時刻のメトリック個数が0ならCriticalエラー(exit 2))
RET=$(mkr metrics -H $HOST -n $METRIC --from $CTIME -jq '. | length' 2>&1)
if [ "$RET" = "0" ]; then
echo "CRITICAL: no metric for $METRIC has been posted since at least $CRIT minutes ago"
exit 2
fi
(同様に、ホストID $HOST、ホストメトリック $METRIC でWARN分前〜現在時刻のメトリック個数が0ならWarningエラー(exit 1))
RET=$(mkr metrics -H $HOST -n $METRIC --from $WTIME -jq '. | length' 2>&1)
if [ "$RET" = "0" ]; then
echo "WARNING: no metric for $METRIC has been posted since at least $WARN minutes ago"
exit 1
fi
echo "OK: metric for $METRIC continues to post"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment