Skip to content

Commit cf4cb1d

Browse files
committed
Added a MongoDB memory plugin
1 parent f549c24 commit cf4cb1d

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

munin/mongodb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import sys
55

66
class MuninMongoDBPlugin(object):
7-
dbname_in_args = True
7+
dbname_in_args = False
88
category = "MongoDB"
99

1010
def __init__(self):
1111
super(MuninMongoDBPlugin, self).__init__()
1212

1313
self.dbname = ((sys.argv[0].rsplit('_', 1)[-1] if self.dbname_in_args else None)
14-
or os.environ['MONGODB_DATABASE'])
14+
or os.environ.get('MONGODB_DATABASE') or None)
1515
host = os.environ.get('MONGODB_SERVER') or 'localhost'
1616
if ':' in host:
1717
host, port = host.split(':')

plugins/mongodb_memory

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from munin.mongodb import MuninMongoDBPlugin
5+
6+
class MongoDBMemoryPlugin(MuninMongoDBPlugin):
7+
args = "-l 0 --base 1024"
8+
vlabel = "bytes"
9+
tital = "MongoDB memory usage"
10+
info = "Memory usage"
11+
field_types = (
12+
('virtual', dict(
13+
label = "virtual",
14+
info = "Bytes of virtual memory",
15+
type = "GAUGE",
16+
min = "0",
17+
)),
18+
('resident', dict(
19+
label = "resident",
20+
info = "Bytes of resident memory",
21+
type = "GAUGE",
22+
min = "0",
23+
)),
24+
('mapped', dict(
25+
label = "mapped",
26+
info = "Bytes of mapped memory",
27+
type = "GAUGE",
28+
min = "0",
29+
)),
30+
)
31+
32+
def run(self):
33+
status = self.connection.admin.command('serverStatus')
34+
print "virtual.value", status["mem"]["virtual"]
35+
print "resident.value", status["mem"]["resident.value"]
36+
print "mapped.value", status["mem"]["mapped"]
37+
38+
if __name__ == "__main__":
39+
MongoDBMemoryPlugin().run()

0 commit comments

Comments
 (0)