Projet

Général

Profil

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

root / plugins / mongodb / mongo_conn @ c6f88968

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

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

    
5
mongo_conn - MongoDB connections Plugin
6

    
7
=head1 APPLICABLE SYSTEMS
8

    
9
Works until MongoDB 3.6. The httpinterface was later removed.
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 = "connections"
39

    
40

    
41
def doData():
42
    print name + ".value " + str( getServerStatus()["connections"]["current"] )
43

    
44
def doConfig():
45

    
46
    print "graph_title MongoDB current connections"
47
    print "graph_args --base 1000 -l 0"
48
    print "graph_vlabel connections"
49
    print "graph_category db"
50

    
51
    print name + ".label " + name
52

    
53

    
54

    
55

    
56

    
57

    
58
if __name__ == "__main__":
59
    if len(sys.argv) > 1 and sys.argv[1] == "config":
60
        doConfig()
61
    else:
62
        doData()