Last active
October 7, 2016 09:29
-
-
Save alxarch/06a39bfb58e1dec318578c18dc674972 to your computer and use it in GitHub Desktop.
Monitoring events and push to Redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$(which redis-cli)" ]; then | |
apk add --no-cache redis | |
fi | |
MONITOR_URL=$1 | |
EVENT_NAME=${EVENT_NAME:=status} | |
REDIS_HOST=${REDIS_HOST:=localhost} | |
EVENT_QUEUE=${EVENT_QUEUE:=monitoring:events} | |
TIMEOUT=${TIMEOUT:=1} | |
INTERVAL=${INTERVAL:=5} | |
echo "Monitoring ${MONITOR_URL} for '${EVENT_NAME}' events" | |
while true; do | |
event="$(wget -q -O - -T $TIMEOUT $MONITOR_URL)" | |
if [ ! -z "$event" ]; then | |
echo "$(date -uIseconds) $event" | |
ok=$(timeout -t $TIMEOUT \ | |
redis-cli -h $REDIS_HOST lpush $EVENT_QUEUE \ | |
"$EVENT_NAME\0$(hostname)\0$(date +%s)\0${event}") | |
if [ -z "$ok" ]; then | |
echo "$(date -uIseconds) Failed to queue event" | |
fi | |
else | |
echo "$(date -uIseconds) Failed to fetch event" | |
fi | |
sleep $INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment