Skip to content

Instantly share code, notes, and snippets.

@aurora
Created November 30, 2011 11:48
Show Gist options
  • Save aurora/1408793 to your computer and use it in GitHub Desktop.
Save aurora/1408793 to your computer and use it in GitHub Desktop.
Munin plugin which monitors Sphinx
#!/bin/bash
=head1 NAME
sphinx - Plugin to monitor various sphinx (searchd) stats
=head1 CONFIGURATION
No configuration
=head1 AUTHORS
Original Author: Adam Oleksy
=head1 LICENSE
Unknown license
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
whattodo=$1
progmode=`basename $0 | cut -d'_' -f2`;
search_bin="/usr/local/bin/searchd"
[ -n "$progmode" ] || exit 1;
function searchesmode
{
case $whattodo in
autoconfig)
echo "yes"
exit 0;;
config)
cat <<'EOM'
graph_title Sphinx Searches and connections
graph_vlabel /${graph_period}
graph_args --base 1000 -l 0
graph_category sphinx
graph_order sphinx_searches sphinx_connections
sphinx_searches.info Number of searches
sphinx_searches.draw LINE2
sphinx_searches.min 0
sphinx_searches.max 5000
sphinx_searches.label Searches
sphinx_searches.type DERIVE
sphinx_connections.info Number of connections
sphinx_connections.draw LINE2
sphinx_connections.min 0
sphinx_connections.max 5000
sphinx_connections.label Connections
sphinx_connections.type DERIVE
EOM
exit 0;;
"")
print_searches_stats
exit 0;;
*)
exit 1;;
esac
}
function print_searches_stats
{
$search_bin --status --config /srv/sphinx/sphinx.conf | awk \
'/^command_search: [[:digit:]]+/ { print "sphinx_searches.value "$2}
/^connections: [[:digit:]]+/ { print "sphinx_connections.value "$2}'
exit 0
}
function timemode
{
case $whattodo in
autoconfig)
echo "yes"
exit 0;;
config)
cat <<'EOM'
graph_title Sphinx indexing time
graph_vlabel seconds
graph_args --base 1000 -l 0
graph_category sphinx
graph_order sphinx_indexing_avg sphinx_indexing_max sphinx_indexing_min
sphinx_indexing_avg.info Average indexing time in 5 minutes
sphinx_indexing_avg.draw LINE2
sphinx_indexing_avg.label Average time
sphinx_indexing_avg.type GAUGE
sphinx_indexing_max.info Maximal indexing time in 5 minutes
sphinx_indexing_max.draw LINE2
sphinx_indexing_max.label Maximal time
sphinx_indexing_max.type GAUGE
sphinx_indexing_min.info Minimal indexing time in 5 minutes
sphinx_indexing_min.draw LINE2
sphinx_indexing_min.label Minimal time
sphinx_indexing_min.type GAUGE
EOM
exit 0;;
"")
print_time_stats
exit 0;;
*)
exit 1;;
esac
}
function print_time_stats
{
cat /var/log/messages | awk \
'BEGIN {
"LANG=C date +\"%b %d %T*\" --date=\"5 minutes ago\"" | getline from;
timesum=0;
timecount=0;
timemax=0;
timemin=10000;
}
$0 > from && /^[[:print:]]*Real execution time: [[:digit:]]+\.[[:digit:]]+s$/ {
timesum += $9; ++timecount;
timemax = timemax > $9 ? timemax : $9;
timemin = timemin < $9 ? timemin : $9;
}
END {
if (timecount > 0)
print "sphinx_indexing_avg.value "timesum/timecount;
if (timemax > 0)
print "sphinx_indexing_max.value "timemax/1;
if (timemin < 10000)
print "sphinx_indexing_min.value "timemin/1;
}'
exit 0
}
case $progmode in
time)
timemode;;
searches)
searchesmode;;
*)
exit 1;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment