2012-07-24 08:37:34 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: set fileencoding=utf-8
|
|
|
|
#
|
|
|
|
# Munin plugin to show number of documents in Sphinx index
|
|
|
|
#
|
|
|
|
# Copyright Igor Borodikhin
|
|
|
|
#
|
|
|
|
# License : GPLv3
|
|
|
|
#
|
|
|
|
# parsed environment variables:
|
|
|
|
# server: hostname or ip-address of Sphinx server
|
|
|
|
# port: port number of Sphinx server
|
|
|
|
#
|
2012-07-24 17:25:59 +02:00
|
|
|
# This plugin shows graphs of numbers of documents in Sphinxsearch indexes.
|
|
|
|
#
|
|
|
|
# ## Requirements
|
|
|
|
# This plugin requires pythons sphinxsearch module which can be installed via easy_install.
|
|
|
|
#
|
|
|
|
# ## Installation
|
|
|
|
# Copy file to directory /usr/share/munin/pligins/ and create symbolic links for each index you wish to monitor.
|
|
|
|
# For example, if you've got indexes called index1 and index2 create these symlinks:
|
|
|
|
#
|
|
|
|
# ln -s /usr/share/munin/plugins/sphindex_ /etc/munin/plugins/sphindex_index1
|
|
|
|
# ln -s /usr/share/munin/plugins/sphindex_ /etc/munin/plugins/sphindex_index2
|
|
|
|
#
|
|
|
|
# If you run munin-node at different box than Sphinxsearch you can specify hostname and port options in munin-node.conf:
|
|
|
|
#
|
|
|
|
# [sphindex_*]
|
|
|
|
# env.server 10.216.0.141
|
|
|
|
# env.port 9312
|
|
|
|
#
|
2012-07-24 08:37:34 +02:00
|
|
|
#%# capabilities=autoconf
|
|
|
|
#%# family=contrib
|
|
|
|
|
|
|
|
import os, sys, sphinxsearch
|
|
|
|
progName = sys.argv[0]
|
|
|
|
indexName = progName[progName.find("_")+1:]
|
|
|
|
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
|
|
|
|
print "yes"
|
|
|
|
elif len(sys.argv) == 2 and sys.argv[1] == "config":
|
2012-09-10 08:36:15 +02:00
|
|
|
warning = "0:"
|
2012-09-10 08:08:04 +02:00
|
|
|
critical = "0:"
|
2012-09-10 08:36:15 +02:00
|
|
|
if "warning" in os.environ and os.environ["warning"] != None:
|
|
|
|
warning = os.environ["warning"]
|
2012-09-10 08:08:04 +02:00
|
|
|
if "critical" in os.environ and os.environ["critical"] != None:
|
2012-09-10 08:36:15 +02:00
|
|
|
critical = os.environ["critical"]
|
2012-09-10 08:08:04 +02:00
|
|
|
|
|
|
|
print "graph_title Sphinx index %s stats" % indexName
|
2012-07-24 08:37:34 +02:00
|
|
|
print "graph_vlabel docs count"
|
|
|
|
print "graph_category search"
|
2012-09-10 08:39:04 +02:00
|
|
|
print "documents_count.warning %s" % warning
|
2012-09-10 08:33:12 +02:00
|
|
|
print "documents_count.critical %s" % critical
|
2012-07-24 08:37:34 +02:00
|
|
|
print "documents_count.label Documents count in index"
|
|
|
|
print "graph_args --base 1000 -l 0"
|
|
|
|
else:
|
|
|
|
if "server" in os.environ and os.environ["server"] != None:
|
2012-09-10 08:08:04 +02:00
|
|
|
server = os.environ["server"]
|
2012-07-24 08:37:34 +02:00
|
|
|
else:
|
|
|
|
server = "localhost"
|
|
|
|
|
|
|
|
if "port" in os.environ and os.environ["port"] != None:
|
|
|
|
try:
|
|
|
|
port = int(os.environ["port"])
|
|
|
|
except ValueError:
|
|
|
|
port = 9312
|
|
|
|
else:
|
|
|
|
port = 9312
|
|
|
|
|
|
|
|
client = sphinxsearch.SphinxClient()
|
|
|
|
client.SetServer(server, port)
|
2012-07-25 12:44:19 +02:00
|
|
|
client.SetLimits(0, 1, 0, 0)
|
2012-07-24 08:37:34 +02:00
|
|
|
result = client.Query("", indexName)
|
|
|
|
docCount = result["total_found"]
|
|
|
|
|
2012-09-10 08:08:04 +02:00
|
|
|
print "documents_count.value %d" % docCount
|