Projet

Général

Profil

Révision a4a9e755

IDa4a9e755b51eb8f66dd53b08012b11e645b10e37
Parent fa896dff
Enfant 34840ad9

Ajouté par Lars Kruse il y a plus de 7 ans

Plugin sphindex_: fix style issues

Voir les différences:

plugins/sphinx/sphindex_
18 18
# This plugin requires pythons sphinxsearch module which can be installed via easy_install.
19 19
#
20 20
# ## Installation
21
# Copy file to directory /usr/share/munin/pligins/ and create symbolic links for each index you wish to monitor.
21
# Copy file to directory /usr/share/munin/pligins/ and create symbolic links for each index you
22
# wish to monitor.
22 23
# For example, if you've got indexes called index1 and index2 create these symlinks:
23 24
#
24 25
#     ln -s /usr/share/munin/plugins/sphindex_ /etc/munin/plugins/sphindex_index1
25 26
#     ln -s /usr/share/munin/plugins/sphindex_ /etc/munin/plugins/sphindex_index2
26 27
#
27
# If you run munin-node at different box than Sphinxsearch you can specify hostname and port options in munin-node.conf:
28
# If you run munin-node at different box than Sphinxsearch you can specify hostname and port
29
# options in munin-node.conf:
28 30
#
29 31
#     [sphindex_*]
30 32
#     env.server 10.216.0.141
31 33
#     env.port 9312
32 34
#
33
#%# capabilities=autoconf
34
#%# family=contrib
35
#  #%# capabilities=autoconf
36
#  #%# family=contrib
35 37

  
36
import os, sys, sphinxsearch
37
progName  = sys.argv[0]
38
indexName = progName[progName.find("_")+1:]
38
import os
39
import sys
40

  
41
import sphinxsearch
42

  
43

  
44
prog_name = sys.argv[0]
45
index_name = prog_name[prog_name.find("_")+1:]
39 46

  
40 47
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
41
    print "yes"
48
    print("yes")
42 49
elif len(sys.argv) == 2 and sys.argv[1] == "config":
43 50
    warning = "0:"
44 51
    critical = "0:"
45
    if "warning" in os.environ and os.environ["warning"] != None:
52
    if "warning" in os.environ and os.environ["warning"]:
46 53
        warning = os.environ["warning"]
47
    if "critical" in os.environ and os.environ["critical"] != None:
54
    if "critical" in os.environ and os.environ["critical"]:
48 55
        critical = os.environ["critical"]
49 56

  
50
    print "graph_title Sphinx index %s stats" % indexName
51
    print "graph_vlabel docs count"
52
    print "graph_category search"
53
    print "documents_count.warning %s" % warning
54
    print "documents_count.critical %s" % critical
55
    print "documents_count.label Documents count in index"
56
    print "graph_args --base 1000 -l 0"
57
    print("graph_title Sphinx index %s stats" % index_name)
58
    print("graph_vlabel docs count")
59
    print("graph_category search")
60
    print("documents_count.warning %s" % warning)
61
    print("documents_count.critical %s" % critical)
62
    print("documents_count.label Documents count in index")
63
    print("graph_args --base 1000 -l 0")
57 64
else:
58
    if "server" in os.environ and os.environ["server"] != None:
65
    if "server" in os.environ and os.environ["server"]:
59 66
        server = os.environ["server"]
60 67
    else:
61
        server =  "localhost"
68
        server = "localhost"
62 69

  
63
    if "port" in os.environ and os.environ["port"] != None:
70
    if "port" in os.environ and os.environ["port"]:
64 71
        try:
65 72
            port = int(os.environ["port"])
66 73
        except ValueError:
......
71 78
    client = sphinxsearch.SphinxClient()
72 79
    client.SetServer(server, port)
73 80
    client.SetLimits(0, 1, 0, 0)
74
    result = client.Query("", indexName)
75
    docCount = result["total_found"]
81
    result = client.Query("", index_name)
82
    doc_count = result["total_found"]
76 83

  
77
    print "documents_count.value %d" % docCount
84
    print("documents_count.value %d" % doc_count)

Formats disponibles : Unified diff