Skip to content

Commit

Permalink
Fixed bugs.
Browse files Browse the repository at this point in the history
Rewritten API.
  • Loading branch information
eterey committed Sep 18, 2014
1 parent fbc1a90 commit f8207f8
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 156 deletions.
52 changes: 21 additions & 31 deletions pyspectator_tornado/static/js/monitor/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,42 +55,32 @@ function CpuInfoUpdater(params) {
}

this.__update = function() {
$.get(
'/api/computer_info/processor.load',
function(data) {
var cpu_load = data['processor.load'];
if((cpu_load !== null) && (self.actual_load !== cpu_load)) {
self.actual_load = cpu_load;
self.__label_load.text(cpu_load);
}
},
'json'
);
$.getJSON('/api/comp_info/cpu/load', function(cpu_load) {
if((cpu_load !== null) && (self.actual_load !== cpu_load)) {
self.actual_load = cpu_load;
self.__label_load.text(cpu_load);
}
});
}

this.__get_chart_data = function(callback) {
$.get(
'/api/computer_info/processor.load_stats[]',
function(data) {
var chart_data = data['processor.load_stats[]'];
if(chart_data.length < self.__chart_data_size) {
var filled_data = [];
for(var i=0; i<self.__chart_data_size-chart_data.length; i++) {
filled_data.push([i, -1]);
}
for(var i=0, key=filled_data.length; i<chart_data.length; i++, key++) {
var val = chart_data[i][1];
filled_data.push([key, val]);
}
chart_data = filled_data;
$.getJSON('/api/comp_info/cpu/load_stats', function(chart_data) {
if(chart_data.length < self.__chart_data_size) {
var filled_data = [];
for(var i=0; i<self.__chart_data_size-chart_data.length; i++) {
filled_data.push([i, -1]);
}
self.__chart_series[0].data = chart_data;
if(callback) {
callback();
for(var i=0, key=filled_data.length; i<chart_data.length; i++, key++) {
var val = chart_data[i][1];
filled_data.push([key, val]);
}
},
'json'
);
chart_data = filled_data;
}
self.__chart_series[0].data = chart_data;
if(callback) {
callback();
}
});
}

this.__init_chart = function() {
Expand Down
24 changes: 10 additions & 14 deletions pyspectator_tornado/static/js/monitor/disk.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,16 @@ function DiskDevInfoUpdater(params) {
}

this.__update = function() {
$.get(
'/api/computer_info/computer.nonvolatile_memory[]',
function(data) {
devices = [];
$.each(data['computer.nonvolatile_memory[]'], function() {
var dev = new DiskDevInfo(this);
devices.push(dev);
});
self.__check_for_old(devices);
self.__check_for_modified(devices);
self.__check_for_new(devices);
},
'json'
);
$.getJSON('/api/comp_info/disk', function(disk_info) {
devices = [];
$.each(disk_info, function() {
var dev = new DiskDevInfo(this);
devices.push(dev);
});
self.__check_for_old(devices);
self.__check_for_modified(devices);
self.__check_for_new(devices);
});
}

this.__check_for_old = function(devices) {
Expand Down
85 changes: 38 additions & 47 deletions pyspectator_tornado/static/js/monitor/memory.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
$(function() {

var memory_info_updater = new MemoryInfoUpdater({
label_memory_available: '#available',
label_memory_used_percent: '#used_percent',
chart_container: '#memory-used_percent-chart',
var mem_info_updater = new MemInfoUpdater({
label_mem_available: '#available',
label_mem_used_percent: '#used-percent',
chart_container: '#used-percent-chart',
interval: 500
});
memory_info_updater.start_updating();
mem_info_updater.start_updating();

});


function MemoryInfoUpdater(params) {
function MemInfoUpdater(params) {

var self = this;

this.__label_memory_available = $(params.label_memory_available);
this.__label_mem_available = $(params.label_mem_available);

this.__label_memory_used_percent = $(params.label_memory_used_percent);
this.__label_mem_used_percent = $(params.label_mem_used_percent);

this.__chart_container = $(params.chart_container);

Expand All @@ -33,9 +33,9 @@ function MemoryInfoUpdater(params) {

this.__chart_plot = null;

this.actual_memory_available = null;
this.actual_mem_available = null;

this.actual_memory_used_percent = null;
this.actual_mem_used_percent = null;

this.interval = params.interval;

Expand All @@ -54,53 +54,44 @@ function MemoryInfoUpdater(params) {
}

this.__start_updating_chart = function() {
self.__add_chart_value(self.actual_memory_used_percent);
self.__add_chart_value(self.actual_mem_used_percent);
self.__draw_chart();
setTimeout(self.__start_updating_chart, self.__updating_chart_interval);
}

this.__update = function() {
$.get(
'/api/computer_info/virtual_memory.available&virtual_memory.used_percent',
function(data) {
var memory_available = data['virtual_memory.available'];
if((memory_available !== null) && (self.actual_memory_available !== memory_available)) {
self.actual_memory_available = memory_available;
self.__label_memory_available.text(memory_available);
}
var memory_used_percent = data['virtual_memory.used_percent'];
if((memory_used_percent !== null) && (self.actual_memory_used_percent !== memory_used_percent)) {
self.actual_memory_used_percent = memory_used_percent;
self.__label_memory_used_percent.text(memory_used_percent);
}
},
'json'
);
$.getJSON('/api/comp_info/mem/available', function(mem_available) {
if((mem_available !== null) && (self.actual_mem_available !== mem_available)) {
self.actual_mem_available = mem_available;
self.__label_mem_available.text(mem_available);
}
});
$.getJSON('/api/comp_info/mem/used_percent', function(mem_used_percent) {
if((mem_used_percent !== null) && (self.actual_mem_used_percent !== mem_used_percent)) {
self.actual_mem_used_percent = mem_used_percent;
self.__label_mem_used_percent.text(mem_used_percent);
}
});
}

this.__get_chart_data = function(callback) {
$.get(
'/api/computer_info/virtual_memory.used_percent_stats[]',
function(data) {
var chart_data = data['virtual_memory.used_percent_stats[]'];
if(chart_data.length < self.__chart_data_size) {
var filled_data = [];
for(var i=0; i<self.__chart_data_size-chart_data.length; i++) {
filled_data.push([i, -1]);
}
for(var i=0, key=filled_data.length; i<chart_data.length; i++, key++) {
var val = chart_data[i][1];
filled_data.push([key, val]);
}
chart_data = filled_data;
$.getJSON('/api/comp_info/mem/used_percent_stats', function(chart_data) {
if(chart_data.length < self.__chart_data_size) {
var filled_data = [];
for(var i=0; i<self.__chart_data_size-chart_data.length; i++) {
filled_data.push([i, -1]);
}
self.__chart_series[0].data = chart_data;
if(callback) {
callback();
for(var i=0, key=filled_data.length; i<chart_data.length; i++, key++) {
var val = chart_data[i][1];
filled_data.push([key, val]);
}
},
'json'
);
chart_data = filled_data;
}
self.__chart_series[0].data = chart_data;
if(callback) {
callback();
}
});
}

this.__init_chart = function() {
Expand Down
28 changes: 12 additions & 16 deletions pyspectator_tornado/static/js/monitor/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,18 @@ function NetworkInfoUpdater(params) {
}

this.__update = function() {
$.get(
'/api/computer_info/network_interface.bytes_sent&network_interface.bytes_recv',
function(data) {
var bytes_sent = data['network_interface.bytes_sent'];
var bytes_recv = data['network_interface.bytes_recv'];
if(self.actual_bytes_sent !== bytes_sent) {
self.actual_bytes_sent = bytes_sent;
self.__label_bytes_sent.text(bytes_sent);
}
if(self.actual_bytes_recv !== bytes_recv) {
self.actual_bytes_recv = bytes_recv;
self.__label_bytes_recv.text(bytes_recv);
}
},
'json'
);
$.getJSON('/api/comp_info/nif/bytes_sent', function(bytes_sent) {
if(self.actual_bytes_sent !== bytes_sent) {
self.actual_bytes_sent = bytes_sent;
self.__label_bytes_sent.text(bytes_sent);
}
});
$.getJSON('/api/comp_info/nif/bytes_recv', function(bytes_recv) {
if(self.actual_bytes_recv !== bytes_recv) {
self.actual_bytes_recv = bytes_recv;
self.__label_bytes_recv.text(bytes_recv);
}
});
}

}
4 changes: 2 additions & 2 deletions pyspectator_tornado/templates/monitor/memory.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dl class="dl-horizontal">
<dt>Used</dt>
<dd>
<span id="used_percent">{{ memory['used_percent'] }}</span>%
<span id="used-percent">{{ memory['used_percent'] }}</span>%
</dd>
</dl>

Expand All @@ -27,7 +27,7 @@
<!-- /.panel-heading -->
<div class="panel-body">
<div class="flot-chart">
<div class="flot-chart-content" id="memory-used_percent-chart"></div>
<div class="flot-chart-content" id="used-percent-chart"></div>
</div>
</div>
<!-- /.panel-body -->
Expand Down
Loading

0 comments on commit f8207f8

Please sign in to comment.