Révision 39705d62
Added plugin which shows number of documents in Sphinx index.
| plugins/sphinx/sphindex_ | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 2 |
# -*- coding: utf-8 -*- |
|
| 3 |
# vim: set fileencoding=utf-8 |
|
| 4 |
# |
|
| 5 |
# Munin plugin to show number of documents in Sphinx index |
|
| 6 |
# |
|
| 7 |
# Copyright Igor Borodikhin |
|
| 8 |
# |
|
| 9 |
# License : GPLv3 |
|
| 10 |
# |
|
| 11 |
# parsed environment variables: |
|
| 12 |
# server: hostname or ip-address of Sphinx server |
|
| 13 |
# port: port number of Sphinx server |
|
| 14 |
# |
|
| 15 |
#%# capabilities=autoconf |
|
| 16 |
#%# family=contrib |
|
| 17 |
|
|
| 18 |
import os, sys, sphinxsearch |
|
| 19 |
progName = sys.argv[0] |
|
| 20 |
indexName = progName[progName.find("_")+1:]
|
|
| 21 |
|
|
| 22 |
if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
|
| 23 |
print "yes" |
|
| 24 |
elif len(sys.argv) == 2 and sys.argv[1] == "config": |
|
| 25 |
print "graph_title Sphinx index %s stats"%indexName |
|
| 26 |
print "graph_vlabel docs count" |
|
| 27 |
print "graph_category search" |
|
| 28 |
|
|
| 29 |
print "documents_count.label Documents count in index" |
|
| 30 |
print "graph_args --base 1000 -l 0" |
|
| 31 |
else: |
|
| 32 |
if "server" in os.environ and os.environ["server"] != None: |
|
| 33 |
server = os.environ["server"] |
|
| 34 |
else: |
|
| 35 |
server = "localhost" |
|
| 36 |
|
|
| 37 |
if "port" in os.environ and os.environ["port"] != None: |
|
| 38 |
try: |
|
| 39 |
port = int(os.environ["port"]) |
|
| 40 |
except ValueError: |
|
| 41 |
port = 9312 |
|
| 42 |
else: |
|
| 43 |
port = 9312 |
|
| 44 |
|
|
| 45 |
client = sphinxsearch.SphinxClient() |
|
| 46 |
client.SetServer(server, port) |
|
| 47 |
result = client.Query("", indexName)
|
|
| 48 |
docCount = result["total_found"] |
|
| 49 |
|
|
| 50 |
print "documents_count.value %d"%docCount |
|
Formats disponibles : Unified diff