Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now using circusd-stats in circushttpd. the next step is to use a str…

…eam w/ socket.io
  • Loading branch information...
commit f3bcd3b4626817dbd98120ab3bed9a3474adf11a 1 parent f433e3b
@tarekziade tarekziade authored
View
18 circus/web/circus.js
@@ -37,7 +37,7 @@ function initializeGraphs(name) {
function refreshData(name) {
var i = 0;
- $.getJSON('/watchers/' + name + '/stats/cpu?start=-3&end=-1', function (data) {
+ $.getJSON('/watchers/' + name + '/stats/cpu?start=-10&end=-1', function (data) {
$.each(data, function (key, values) {
for (i = 0; i < values.length; i++) {
cpu_data[key].push(values[i]);
@@ -48,7 +48,7 @@ function refreshData(name) {
}
});
});
- $.getJSON('/watchers/' + name + '/stats/mem', function (data) {
+ $.getJSON('/watchers/' + name + '/stats/mem?start=-10&end=-1', function (data) {
$.each(data, function (key, values) {
for (i = 0; i < values.length; i++) {
mem_data[key].push(values[i]);
@@ -104,7 +104,7 @@ function refreshCircusdGraph() {
circusd_cpu_data = circusd_cpu_data.slice(start);
}
});
-
+
$.getJSON('/circusd/stats/mem?start=-3&end=-1', function (data) {
var values = data['info'];
@@ -116,7 +116,7 @@ function refreshCircusdGraph() {
circusd_mem_data = circusd_mem_data.slice(start);
}
});
-
+
updateCircusdGraph();
}
@@ -153,7 +153,7 @@ function initializeCircusdGraph() {
function refreshCircusdGraph() {
- $.getJSON('/circusd/stats/cpu?start=-3&end=-1', function(data) {
+ $.getJSON('/circusd/stats/cpu?start=-10&end=-1', function(data) {
var values = data['info'];
for (i=0;i<values.length;i++) {
circusd_cpu_data.push(values[i]);
@@ -164,8 +164,8 @@ function refreshCircusdGraph() {
}
});
-
- $.getJSON('/circusd/stats/mem?start=-3&end=-1', function(data) {
+
+ $.getJSON('/circusd/stats/mem?start=-10&end=-1', function(data) {
var values = data['info'];
for (i=0;i<values.length;i++) {
@@ -176,7 +176,7 @@ function refreshCircusdGraph() {
circusd_mem_data = circusd_mem_data.slice(start);
}
});
-
+
updateCircusdGraph();
}
@@ -184,5 +184,5 @@ $(document).ready(function () {
$('.add_watcher').click(function () {
$('#overlay').show();
return false;
- });
+ });
});
View
4 circus/web/circushttpd.py
@@ -43,8 +43,8 @@ def index():
@route('/circusd/stats/<field>', method='GET')
def get_dstat(field):
- start = int(request.query.get('start', '0'))
- end = int(request.query.get('end', '-1'))
+ #start = int(request.query.get('start', '0'))
+ #end = int(request.query.get('end', '-1'))
if client is None:
return {}
View
57 circus/web/controller.py
@@ -1,9 +1,9 @@
import os
from collections import defaultdict
from threading import Thread
-import time
from circus.commands import get_commands
from circus.client import CircusClient, CallError
+from circus.stats.client import StatsClient
_DIR = os.path.dirname(__file__)
@@ -18,43 +18,36 @@ def __init__(self, client):
self.client = client
self.daemon = True
self.running = False
- self.cclient = CircusClient(endpoint=client.endpoint)
+ self.cclient = None
+
+ def _check_size(self, stat):
+ if len(stat) > MAX_STATS:
+ start = len(stat) - MAX_STATS
+ stat[:] = stat[start:]
def run(self):
+ self.cclient = StatsClient(endpoint=self.client.stats_endpoint)
stats = self.client.stats
dstats = self.client.dstats
- call = self.cclient.call
self.running = True
while self.running:
- for name, __ in self.client.watchers:
- msg = cmds['stats'].make_message(name=name)
- try:
- res = call(msg)
- except CallError:
- continue
- stats[name].append(res['info'])
- if len(stats[name]) > MAX_STATS:
- start = len(stats[name]) - MAX_STATS
- stats[name][:] = stats[name][start:]
-
- # getting circusd stats
- msg = cmds['dstats'].make_message(name=name)
- try:
- res = call(msg)
- except CallError:
- continue
+ for watcher, pid, stat in self.cclient:
+ if watcher == 'circus':
+ data = dstats
+ else:
+ data = stats[watcher]
+ data.append(stat)
+ #self._check_size(data)
- dstats.append(res['info'])
- if len(dstats) > MAX_STATS:
- start = len(dstats) - MAX_STATS
- dstats[:] = dstats[start:]
-
- time.sleep(.2)
+ def stop(self):
+ self.running = False
+ self.cclient.stop()
class LiveClient(object):
def __init__(self, endpoint):
self.endpoint = str(endpoint)
+ self.stats_endpoint = None
self.client = CircusClient(endpoint=self.endpoint)
self.connected = False
self.watchers = []
@@ -81,6 +74,7 @@ def verify(self):
options = self.client.call(msg)
self.watchers.append((watcher, options['options']))
self.watchers.sort()
+ self.stats_endpoint = self.get_global_options()['stats_endpoint']
if not self.refresher.running:
self.refresher.start()
except CallError:
@@ -129,18 +123,19 @@ def get_dstats(self, field, start=0, end=-1):
return res
def get_pids(self, name):
- msg = cmds['list'].make_message(name=name)
+ msg = cmds['listpids'].make_message(name=name)
res = self.client.call(msg)
- return res['processes']
+ return res['pids']
def get_series(self, name, pid, field, start=0, end=-1):
stats = self.get_stats(name, start, end)
res = []
- pid = str(pid)
for stat in stats:
- if pid not in stat:
+ pids = stat['pid']
+ if isinstance(pids, list):
continue
- res.append(stat[pid][field])
+ if str(pid) == str(stat['pid']):
+ res.append(stat[field])
return res
def get_status(self, name):
Please sign in to comment.
Something went wrong with that request. Please try again.