Permalink
Browse files

generate so can re-use code

  • Loading branch information...
1 parent f9ccc4d commit 12dd51edeb7d0e3452c2bded2c69cc326a63d32e @erh committed Mar 24, 2010
Showing with 109 additions and 22 deletions.
  1. +12 −0 build.tcsh
  2. +17 −12 mongo_mem
  3. +12 −10 mongo_ops
  4. +26 −0 src/body_mem.py
  5. +21 −0 src/body_ops.py
  6. +8 −0 src/footer.py
  7. +13 −0 src/header.py
View
@@ -0,0 +1,12 @@
+#!/bin/tcsh
+
+foreach x ( ops mem )
+ set out = mongo_$x
+ echo "#!"`which python` > $out
+ echo "" >> $out
+ echo "## GENERATED FILE - DO NOT EDIT" >> $out
+ cat src/header.py >> $out
+ cat src/body_$x.py >> $out
+ cat src/footer.py >> $out
+ chmod 755 $out
+end
View
@@ -1,5 +1,7 @@
#!/usr/bin/python
+## GENERATED FILE - DO NOT EDIT
+
import urllib2
import sys
@@ -8,38 +10,41 @@ try:
except ImportError:
import simplejson as json
-def ok(s):
- return s == "resident" or s == "virtual" or s == "mapped"
-
-def getParsed():
+def getServerStatus():
raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
- return json.loads( raw )
+ return json.loads( raw )["serverStatus"]
-def data():
- parsed = getParsed()
- for k,v in parsed["serverStatus"]["mem"].iteritems():
+def ok(s):
+ return s == "resident" or s == "virtual" or s == "mapped"
+
+def doData():
+ for k,v in getServerStatus()["mem"].iteritems():
if ok(k):
print( str(k) + ".value " + str(v) )
-def config():
+def doConfig():
print "graph_title MongoDB memory usage"
print "graph_args --base 1000"
print "graph_vlabel mb ${graph_period}"
print "graph_category MongoDB"
- for k in getParsed()["serverStatus"]["mem"]:
+ for k in getServerStatus()["mem"]:
if ok( k ):
print k + ".label " + k
print k + ".type GAUGE"
print k + ".draw AREA"
+
+
+
+
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "config":
- config()
+ doConfig()
else:
- data()
+ doData()
View
@@ -1,5 +1,7 @@
#!/usr/bin/python
+## GENERATED FILE - DO NOT EDIT
+
import urllib2
import sys
@@ -9,35 +11,35 @@ except ImportError:
import simplejson as json
-def getParsed():
+def getServerStatus():
raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
- return json.loads( raw )
+ return json.loads( raw )["serverStatus"]
+
-def data():
- parsed = getParsed()
- for k,v in parsed["serverStatus"]["opcounters"].iteritems():
+def doData():
+ ss = getServerStatus()
+ for k,v in ss["opcounters"].iteritems():
print( str(k) + ".value " + str(v) )
-def config():
+def doConfig():
print "graph_title MongoDB ops"
print "graph_args --base 1000"
print "graph_vlabel ops / ${graph_period}"
print "graph_category MongoDB"
print "graph_total total"
- for k in getParsed()["serverStatus"]["opcounters"]:
+ for k in getServerStatus()["opcounters"]:
print k + ".label " + k
print k + ".min 0"
print k + ".type COUNTER"
print k + ".max 500000"
print k + ".draw AREA"
-
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] == "config":
- config()
+ doConfig()
else:
- data()
+ doData()
View
@@ -0,0 +1,26 @@
+
+def ok(s):
+ return s == "resident" or s == "virtual" or s == "mapped"
+
+def doData():
+ for k,v in getServerStatus()["mem"].iteritems():
+ if ok(k):
+ print( str(k) + ".value " + str(v) )
+
+def doConfig():
+
+ print "graph_title MongoDB memory usage"
+ print "graph_args --base 1000"
+ print "graph_vlabel mb ${graph_period}"
+ print "graph_category MongoDB"
+
+ for k in getServerStatus()["mem"]:
+ if ok( k ):
+ print k + ".label " + k
+ print k + ".type GAUGE"
+ print k + ".draw AREA"
+
+
+
+
+
View
@@ -0,0 +1,21 @@
+
+
+def doData():
+ ss = getServerStatus()
+ for k,v in ss["opcounters"].iteritems():
+ print( str(k) + ".value " + str(v) )
+
+def doConfig():
+
+ print "graph_title MongoDB ops"
+ print "graph_args --base 1000"
+ print "graph_vlabel ops / ${graph_period}"
+ print "graph_category MongoDB"
+ print "graph_total total"
+
+ for k in getServerStatus()["opcounters"]:
+ print k + ".label " + k
+ print k + ".min 0"
+ print k + ".type COUNTER"
+ print k + ".max 500000"
+ print k + ".draw AREA"
View
@@ -0,0 +1,8 @@
+
+if __name__ == "__main__":
+ if len(sys.argv) > 1 and sys.argv[1] == "config":
+ doConfig()
+ else:
+ doData()
+
+
View
@@ -0,0 +1,13 @@
+
+import urllib2
+import sys
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
+
+def getServerStatus():
+ raw = urllib2.urlopen( "http://127.0.0.1:28017/_status" ).read()
+ return json.loads( raw )["serverStatus"]

0 comments on commit 12dd51e

Please sign in to comment.