Projet

Général

Profil

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

root / plugins / mongodb / mongo_lock @ dca09431

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

1 276169a6 Alban
#!/usr/bin/env python
2
"""
3
=head1 NAME
4 c6f88968 Lars Kruse
5
mongo_lock - MongoDB lock Plugin
6 237bf058 Eliot Horowitz
7 276169a6 Alban
=head1 APPLICABLE SYSTEMS
8
9 c6f88968 Lars Kruse
MongoDB 2.X. The "lockTime" field was removed in later versions.
10 276169a6 Alban
11
=head1 CONFIGURATION
12
13
    [mongo_lock]
14
    env.MONGO_DB_URI mongodb://user:password@host:port/dbname
15
16
=head1 AUTHOR
17
18 c6f88968 Lars Kruse
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 276169a6 Alban
"""
24 237bf058 Eliot Horowitz
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 271a38f0 Dimitri Savineau
    status = getServerStatus()
42
    if status["version"] >= "2.2.0":
43 68d23cce Takuya Matsuyama
        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 271a38f0 Dimitri Savineau
    else:
48
        ratio = status["globalLock"]["ratio"]
49
    print name + ".value " + str( 100 * ratio )
50 237bf058 Eliot Horowitz
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 99542938 dipohl
    print "graph_category db"
57 237bf058 Eliot Horowitz
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()