root / plugins / sphinx / sphindex_ @ ef960abc
Historique | Voir | Annoter | Télécharger (2,45 ko)
| 1 | 39705d62 | iborodikhin | #!/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 | 862e559c | iborodikhin | # This plugin shows graphs of numbers of documents in Sphinxsearch indexes. |
| 16 | # |
||
| 17 | # ## Requirements |
||
| 18 | # This plugin requires pythons sphinxsearch module which can be installed via easy_install. |
||
| 19 | # |
||
| 20 | # ## Installation |
||
| 21 | # Copy file to directory /usr/share/munin/pligins/ and create symbolic links for each index you wish to monitor. |
||
| 22 | # For example, if you've got indexes called index1 and index2 create these symlinks: |
||
| 23 | # |
||
| 24 | # ln -s /usr/share/munin/plugins/sphindex_ /etc/munin/plugins/sphindex_index1 |
||
| 25 | # ln -s /usr/share/munin/plugins/sphindex_ /etc/munin/plugins/sphindex_index2 |
||
| 26 | # |
||
| 27 | # If you run munin-node at different box than Sphinxsearch you can specify hostname and port options in munin-node.conf: |
||
| 28 | # |
||
| 29 | # [sphindex_*] |
||
| 30 | # env.server 10.216.0.141 |
||
| 31 | # env.port 9312 |
||
| 32 | # |
||
| 33 | 39705d62 | iborodikhin | #%# capabilities=autoconf |
| 34 | #%# family=contrib |
||
| 35 | |||
| 36 | import os, sys, sphinxsearch |
||
| 37 | progName = sys.argv[0] |
||
| 38 | indexName = progName[progName.find("_")+1:]
|
||
| 39 | |||
| 40 | if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
||
| 41 | print "yes" |
||
| 42 | elif len(sys.argv) == 2 and sys.argv[1] == "config": |
||
| 43 | 61de47eb | iborodikhin | warning = "0:" |
| 44 | 2c99f327 | iborodikhin | critical = "0:" |
| 45 | 61de47eb | iborodikhin | if "warning" in os.environ and os.environ["warning"] != None: |
| 46 | warning = os.environ["warning"] |
||
| 47 | 2c99f327 | iborodikhin | if "critical" in os.environ and os.environ["critical"] != None: |
| 48 | 61de47eb | iborodikhin | critical = os.environ["critical"] |
| 49 | 2c99f327 | iborodikhin | |
| 50 | print "graph_title Sphinx index %s stats" % indexName |
||
| 51 | 39705d62 | iborodikhin | print "graph_vlabel docs count" |
| 52 | print "graph_category search" |
||
| 53 | c5e74d82 | iborodikhin | print "documents_count.warning %s" % warning |
| 54 | b3beac1c | iborodikhin | print "documents_count.critical %s" % critical |
| 55 | 39705d62 | iborodikhin | print "documents_count.label Documents count in index" |
| 56 | print "graph_args --base 1000 -l 0" |
||
| 57 | else: |
||
| 58 | if "server" in os.environ and os.environ["server"] != None: |
||
| 59 | 2c99f327 | iborodikhin | server = os.environ["server"] |
| 60 | 39705d62 | iborodikhin | else: |
| 61 | server = "localhost" |
||
| 62 | |||
| 63 | if "port" in os.environ and os.environ["port"] != None: |
||
| 64 | try: |
||
| 65 | port = int(os.environ["port"]) |
||
| 66 | except ValueError: |
||
| 67 | port = 9312 |
||
| 68 | else: |
||
| 69 | port = 9312 |
||
| 70 | |||
| 71 | client = sphinxsearch.SphinxClient() |
||
| 72 | client.SetServer(server, port) |
||
| 73 | f8909aa4 | iborodikhin | client.SetLimits(0, 1, 0, 0) |
| 74 | 39705d62 | iborodikhin | result = client.Query("", indexName)
|
| 75 | docCount = result["total_found"] |
||
| 76 | |||
| 77 | 2c99f327 | iborodikhin | print "documents_count.value %d" % docCount |
