Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / sphinx / sphindex_ @ 862e559c

Historique | Voir | Annoter | Télécharger (2,07 ko)

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
# 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
#%# 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
    print "graph_title Sphinx index %s stats"%indexName
44
    print "graph_vlabel docs count"
45
    print "graph_category search"
46

    
47
    print "documents_count.label Documents count in index"
48
    print "graph_args --base 1000 -l 0"
49
else:
50
    if "server" in os.environ and os.environ["server"] != None:
51
        server = os.environ["server"] 
52
    else:
53
        server =  "localhost"
54

    
55
    if "port" in os.environ and os.environ["port"] != None:
56
        try:
57
            port = int(os.environ["port"])
58
        except ValueError:
59
            port = 9312
60
    else:
61
        port = 9312
62

    
63
    client = sphinxsearch.SphinxClient()
64
    client.SetServer(server, port)
65
    result = client.Query("", indexName)
66
    docCount = result["total_found"]
67

    
68
    print "documents_count.value %d"%docCount