Skip to content

Instantly share code, notes, and snippets.

@dennisfaust
Created July 15, 2011 00:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennisfaust/1083770 to your computer and use it in GitHub Desktop.
Save dennisfaust/1083770 to your computer and use it in GitHub Desktop.
Script to create a MongoDB Collectd Plugin - Works with RightScale's monitoring and alerts
#!/bin/bash -ex
#
# Description: Graph how old the last sync was between primary and secondary mongo instances.
#
# Base code and idea thanks to: Edward M. Goldberg
#
# any mistakes courtesy of: Dennis Faust
#
if [ $RS_DISTRO = ubuntu ]; then
plugin_dir="/etc/collectd/conf"
elif [ $RS_DISTRO = centos ]; then
plugin_dir="/etc/collectd.d"
fi
echo "*** This sets up a collectd plugin container"
cat <<"EOF" >$plugin_dir/MongoDB-lag.conf
LoadPlugin exec
<Plugin exec>
Exec "mongodb" "/usr/local/bin/plugin-mongolag.sh"
</Plugin>
EOF
echo "*** This is called by the container"
cat <<"EOF" >/usr/local/bin/plugin-mongolag.sh
#!/bin/bash
#
while sleep 5; do
VALUE=`echo "db.printSlaveReplicationInfo()" | mongo | grep secs | head -1 | cut -f2 -d'=' | cut -f1 -d's' | cut -f2 -d' ' `
echo "PUTVAL \"REPLACE/mongo/gauge-secondary_lag_secs\" interval=5 N:$VALUE"
done
EOF
sed -i "s/REPLACE/$SKETCHY_UUID/g" /usr/local/bin/plugin-mongolag.sh
chmod 777 /usr/local/bin/plugin-mongolag.sh
service collectd restart
exit 0 # leave with a smile...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment