Browse files

added memory usage graph

  • Loading branch information...
1 parent 0981bdf commit 5abe88b469e2f97f2b3bb5be68991076f0279eda @forrestv forrestv committed Jan 7, 2013
Showing with 29 additions and 1 deletion.
  1. +14 −0 p2pool/util/memory.py
  2. +8 −1 p2pool/web.py
  3. +7 −0 web-static/graphs.html
View
14 p2pool/util/memory.py
@@ -0,0 +1,14 @@
+import gc
+import os
+
+_scale = {'kB': 1024, 'mB': 1024*1024,
+ 'KB': 1024, 'MB': 1024*1024}
+
+def resident():
+ gc.collect()
+ with open('/proc/%d/status' % os.getpid()) as f:
+ v = f.read()
+ i = v.index('VmRSS:')
+ v = v[i:].split(None, 3)
+ #assert len(v) == 3, v
+ return float(v[1]) * _scale[v[2]]
View
9 p2pool/web.py
@@ -5,6 +5,7 @@
import os
import sys
import time
+import traceback
from twisted.internet import defer, task
from twisted.python import log
@@ -13,7 +14,7 @@
import p2pool
from bitcoin import data as bitcoin_data
from . import data as p2pool_data
-from util import deferred_resource, graph, math, pack, variable
+from util import deferred_resource, graph, math, memory, pack, variable
def _atomic_read(filename):
try:
@@ -392,6 +393,7 @@ def get_total_pool_rate(t):
multivalue_undefined_means_0=True, default_func=build_desired_rates),
'traffic_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False, multivalues=True),
'getwork_latency': graph.DataStreamDescription(dataview_descriptions),
+ 'memory_usage': graph.DataStreamDescription(dataview_descriptions),
}, hd_obj)
x = task.LoopingCall(lambda: _atomic_write(hd_path, json.dumps(hd.to_obj())))
x.start(100)
@@ -438,6 +440,11 @@ def add_point():
vs_total = sum(vs.itervalues())
hd.datastreams['desired_versions'].add_datum(t, dict((str(k), v/vs_total) for k, v in vs.iteritems()))
hd.datastreams['desired_version_rates'].add_datum(t, dict((str(k), v/vs_total*pool_total) for k, v in vs.iteritems()))
+ try:
+ hd.datastreams['memory_usage'].add_datum(t, memory.resident())
+ except:
+ if p2pool.DEBUG:
+ traceback.print_exc()
x = task.LoopingCall(add_point)
x.start(5)
stop_event.watch(x.stop)
View
7 web-static/graphs.html
@@ -59,6 +59,9 @@
<h2>Bitcoind GetBlockTemplate Latency</h2>
<svg id="getwork_latency"></svg>
+ <h2>Memory Usage</h2>
+ <svg id="memory_usage"></svg>
+
<script type="text/javascript">
function compose() {
var funcs = arguments;
@@ -416,6 +419,10 @@
plot_later(d3.select("#getwork_latency"), "s", null, [
{"url": "/web/graph_data/getwork_latency/last_" + lowerperiod, "color": "#FF0000", "label": "Getwork Latency"}
], false);
+
+ plot_later(d3.select("#memory_usage"), "s", null, [
+ {"url": "/web/graph_data/memory_usage/last_" + lowerperiod, "color": "#FF0000", "label": "Memory Usage"}
+ ], false);
}
d3.json('/local_stats', function(local_stats) {

1 comment on commit 5abe88b

@Rav3nPL

Killed that line:

  • gc.collect()

and it stop spiking.
Forcing GC is not good idea...

Please sign in to comment.