forked from erh/mongo-munin
-
Notifications
You must be signed in to change notification settings - Fork 19
/
mongo_docs
63 lines (48 loc) · 1.42 KB
/
mongo_docs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
## GENERATED FILE - DO NOT EDIT
import urllib2
import sys
import os
import pymongo
def getDatabasesStats():
host = "127.0.0.1"
port = 27017
c = pymongo.MongoClient(host, port)
dbs = {}
for k in c.database_names():
if k != "admin" and k != "local" and k != "":
db = c[k]
dbs[k] = {}
for coll in db.collection_names():
if '.' not in coll:
dbs[k][coll] = db[coll].count()
return dbs
name = "documents"
def doData():
ss = getDatabasesStats()
for k,v in ss.iteritems():
for a,b in v.iteritems():
print(str(k)+str(a) + ".value " + str(b))
def doConfig():
print "graph_title MongoDB documents count"
print "graph_args --base 1000 -l 0 --vertical-label Docs"
print "graph_category MongoDB"
ss = getDatabasesStats()
for k,v in ss.iteritems():
for a,b in v.iteritems():
print str(k)+str(a) + ".label " + str(k) + " " + str(a)
print str(k)+str(a) + ".draw LINE1"
if __name__ == "__main__":
from os import environ
if 'HOST' in environ:
host = environ['HOST']
if 'PORT' in environ:
port = environ['PORT']
if 'USER' in environ:
user = environ['USER']
if 'PASSWORD' in environ:
password = environ['PASSWORD']
if len(sys.argv) > 1 and sys.argv[1] == "config":
doConfig()
else:
doData()