Skip to content

Commit

Permalink
removed trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Waldvogel committed Oct 27, 2010
1 parent be56588 commit 9f7636c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions gmetric-mongodb.py
@@ -1,4 +1,5 @@
#!/usr/bin/python
# vim: set ts=4 sw=4 et :

from subprocess import Popen
import sys, os, urllib2
Expand All @@ -11,7 +12,7 @@
GMETRIC = "/usr/bin/gmetric --name=\"%s\" --value=\"%s\" --type=\"int32\" --units=\"%s\""

class ServerStatus:
ops_tmp_file = os.path.join("/", "tmp", "mongo-prevops")
ops_tmp_file = os.path.join("/", "tmp", "mongo-prevops")

def __init__(self):
self.status = self.getServerStatus()
Expand All @@ -22,12 +23,12 @@ def __init__(self):
def getServerStatus(self):
raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
return json.loads( raw )["serverStatus"]

def callGmetric(self, d):
for k,v in d.iteritems():
cmd = GMETRIC % ("mongodb_" + k, v[0], v[1])
Popen(cmd, shell=True)

def conns(self):
ss = self.status
self.callGmetric({
Expand All @@ -43,7 +44,7 @@ def btree(self):
"btree_resets" : (b["resets"], "count"),
"btree_miss_ratio" : (b["missRatio"], "ratio"),
})

def mem(self):
m = self.status["mem"]
self.callGmetric({
Expand All @@ -62,22 +63,22 @@ def ops(self):
f.close()
except (ValueError, IOError):
prev_ops = {}

for k,v in cur_ops.iteritems():
if k in prev_ops:
name = k + "s_per_second"
if k == "query":
name = "queries_per_second"
out[name] = ((float(v) - float(prev_ops[k]) ) / 60, "ops/s")

f = open(self.ops_tmp_file, 'w')
f = open(self.ops_tmp_file, 'w')
try:
f.write(json.dumps(cur_ops))
finally:
f.close()

self.callGmetric(out)

def repl(self):
self.callGmetric({
"is_master" : (self.status["repl"]["ismaster"], "boolean")
Expand All @@ -87,6 +88,6 @@ def lock(self):
self.callGmetric({
"lock_ratio" : (self.status["globalLock"]["ratio"], "ratio")
})

if __name__ == "__main__":
ServerStatus()

0 comments on commit 9f7636c

Please sign in to comment.