Projet

Général

Profil

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

root / plugins / mongodb / mongo_lock @ c6f88968

Historique | Voir | Annoter | Télécharger (1,47 ko)

1
#!/usr/bin/env python
2
"""
3
=head1 NAME
4

    
5
mongo_lock - MongoDB lock Plugin
6

    
7
=head1 APPLICABLE SYSTEMS
8

    
9
MongoDB 2.X. The "lockTime" field was removed in later versions.
10

    
11
=head1 CONFIGURATION
12

    
13
    [mongo_lock]
14
    env.MONGO_DB_URI mongodb://user:password@host:port/dbname
15

    
16
=head1 AUTHOR
17

    
18
Original script there : https://github.com/comerford/mongo-munin
19

    
20
Doc added by Alban Espie-Guillon <alban.espie@alterway.fr>
21

    
22
=cut
23
"""
24

    
25
import urllib2
26
import sys
27

    
28
try:
29
    import json
30
except ImportError:
31
    import simplejson as json
32

    
33

    
34
def getServerStatus():
35
    raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
36
    return json.loads( raw )["serverStatus"]
37

    
38
name = "locked"
39

    
40
def doData():
41
    status = getServerStatus()
42
    if status["version"] >= "2.2.0":
43
        if status["globalLock"]["lockTime"]["$numberLong"]:
44
            ratio = float(status["globalLock"]["lockTime"]["$numberLong"]) / float(status["globalLock"]["totalTime"]["$numberLong"])
45
        else:
46
            ratio = float(status["globalLock"]["lockTime"]) / status["globalLock"]["totalTime"]
47
    else:
48
        ratio = status["globalLock"]["ratio"]
49
    print name + ".value " + str( 100 * ratio )
50

    
51
def doConfig():
52

    
53
    print "graph_title MongoDB write lock percentage"
54
    print "graph_args --base 1000 -l 0 "
55
    print "graph_vlabel percentage"
56
    print "graph_category db"
57

    
58
    print name + ".label " + name
59

    
60

    
61

    
62

    
63

    
64

    
65
if __name__ == "__main__":
66
    if len(sys.argv) > 1 and sys.argv[1] == "config":
67
        doConfig()
68
    else:
69
        doData()