From 39705d6221627904f458f185151f5eff5f09b684 Mon Sep 17 00:00:00 2001 From: iborodikhin Date: Tue, 24 Jul 2012 12:37:34 +0600 Subject: [PATCH] Added plugin which shows number of documents in Sphinx index. --- plugins/sphinx/sphindex_ | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 plugins/sphinx/sphindex_ diff --git a/plugins/sphinx/sphindex_ b/plugins/sphinx/sphindex_ new file mode 100755 index 00000000..a2b60441 --- /dev/null +++ b/plugins/sphinx/sphindex_ @@ -0,0 +1,50 @@ +#!/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 +# +#%# 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": + print "graph_title Sphinx index %s stats"%indexName + print "graph_vlabel docs count" + print "graph_category search" + + 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: + server = os.environ["server"] + 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) + result = client.Query("", indexName) + docCount = result["total_found"] + + print "documents_count.value %d"%docCount