Permalink
Browse files

remove crappy graph

  • Loading branch information...
1 parent c620d90 commit e6de499aeffa8dbef56a484a31c8ba0fefe8e557 @Eyjafjallajokull committed Jan 21, 2013
Showing with 26 additions and 54 deletions.
  1. +3 −1 config.yml
  2. +2 −2 widgets/network/main.css
  3. +17 −37 widgets/network/main.js
  4. +4 −14 widgets/network/main.py
View
@@ -11,7 +11,9 @@ widgets:
- {id: ProcessorWidget }
- {id: MemoryWidget }
- {id: UptimeWidget }
- - {id: NetworkWidget }
+ - id: NetworkWidget
+ config:
+ interface: eth0
- id: KeeperWidget
config:
title: System monitor
View
@@ -1,2 +1,2 @@
-.widget.UptimeWidget table { margin-top: 10px; }
-.widget.UptimeWidget table tr:nth-child(2n+1) td { background: transparent; }
+.widget.NetworkWidget table { margin-top: 45px; }
+.widget.NetworkWidget table tr:nth-child(2n+1) td { background: transparent; }
View
@@ -1,47 +1,27 @@
(function(){
var w = $.extend({}, Widget);
- /*
- w.recordTpl = '$2: <span>$1</span><br/>';
- w.render = function(data) {
- data = data.split('\n');
- var html = '';
- for(var i=0; i<data.length; i++) {
- html += data[i].replace(/^\s*(\d+)\s*(.+)\s*$/, this.recordTpl);
- }
- this.$('.widget').html(html);
- };*/
-
-
- w.mainTpl = function() {
- var w = this.$('.widget').width()-2;
- var h = this.$('.widget').height()-2;
- return '<canvas width="'+w+'" height="'+h+'"></canvas>';
- };
+
+ w.mainTpl = '<table width="99%">'+
+ '<tr style="font-size:20px"><td id="networkDataUp" align="right" width="50%">0<td><td>kbps</td>'+
+ '<tr style="font-size:20px"><td id="networkDataDown" align="right">0<td><td>kbps</td></table>';
w.init = function() {
- this.ts = {
- rx:new TimeSeries(),
- tx:new TimeSeries()
- };
- this.smoothie = new SmoothieChart({
- grid: {
- strokeStyle:'rgb(200, 200, 200)', fillStyle:'rgb(255, 255, 255)',
- lineWidth: 1, millisPerLine: 250, verticalSections: 6, },
- labels: { fillStyle:'#444' }
- });
- this.smoothie.streamTo(this.$('canvas')[0], 1000);
-
- this.smoothie.addTimeSeries(this.ts.rx,
- { strokeStyle:'rgb(0, 255, 0)', fillStyle:'rgba(0, 255, 0, 0.4)', lineWidth:3 });
- this.smoothie.addTimeSeries(this.ts.tx,
- { strokeStyle:'rgb(255, 0, 0)', fillStyle:'rgba(255, 0, 0, 0.4)', lineWidth:3 });
+ this.tx = this.rx = null;
};
w.render = function(data) {
- console.log(data);
-
- this.ts.tx.append(new Date().getTime(), data.tx);
- this.ts.rx.append(new Date().getTime(), data.rx);
+ data = data.split(' ');
+ var rx = parseInt(data[0]),
+ tx = parseInt(data[1]),
+ crx, ctx;
+ if (this.tx !== null) {
+ crx = Math.round(Math.abs(this.rx - rx)*8/1000);
+ ctx = Math.round(Math.abs(this.tx - tx)*8/1000);
+ this.$('#networkDataDown').text(crx);
+ this.$('#networkDataUp').text(ctx);
+ }
+ this.tx = tx;
+ this.rx = rx;
};
$(function(){
View
@@ -4,17 +4,7 @@ class NetworkWidget(BaseWidget):
prevValues = {'rx':0, 'tx':0}
def collectData(self):
- interfaces = self.runSystemCommand('cat /proc/net/dev | awk \'{print $2,$10}\'').split('\n')[2:-1]
- interfaces = [a.split(' ') for a in interfaces]
-
- currentValues = {'rx':0, 'tx':0}
- for interface in interfaces:
- currentValues['rx'] = currentValues['rx'] + int(interface[0])
- currentValues['tx'] = currentValues['tx'] + int(interface[1])
-
- diff = { 'rx': abs(self.prevValues['rx'] - currentValues['rx']),
- 'tx': abs(self.prevValues['tx'] - currentValues['tx']) }
- diff = diff if self.prevValues['rx']!=0 else {'rx':0, 'tx':0}
- self.prevValues = currentValues
- return diff
-
+ cmd = '''awk -v interface="%s" -F'[: \t]+' '{ sub(/^ */,"");
+ if ($1 == interface) print $2 " " $10; //down up
+ }' /proc/net/dev''' % self.config['interface']
+ return self.runSystemCommand(cmd)

0 comments on commit e6de499

Please sign in to comment.