1. Josh VanderLinden
  2. node-iostat

Commits

Josh VanderLinden  committed 5be7cae

Column names are retrieved dynamically instead of being hard coded now

  • Participants
  • Parent commits 1a5ec6d
  • Branches master

Comments (0)

Files changed (2)

File iostat.html

View file
  • Ignore whitespace
     //timeformat: '%H:%M:%S'
   }
 };
+var columns = null
 var data = [];
 var last_stamp = null;
 var max_size = 120;
 
-var columns = new Array('rrqm_s', 'wrqm_s', 'r_s', 'w_s', 'rkb_s', 'wkb_s', 'avgrq_sz', 'avgqu_sz', 'await', 'r_await', 'w_await', 'svctm', 'util');
-
 $(function () {
   setInterval(fetchData, 1000);
 
   display_mode = $('#id_display_mode');
-  for (var i = 0; i < columns.length; i++) {
-    col = columns[i];
-    sel = col == 'util' ? ' selected="selected"' : '';
-    display_mode.append('<option' + sel +'>' + columns[i] + '</option>');
-  }
+  $.ajax({
+    url: "/data/column_names",
+    method: 'GET',
+    dataType: 'json',
+    success: function (result) {
+      columns = result;
+      for (var i = 0; i < columns.length; i++) {
+        col = columns[i];
+        sel = col == 'util' ? ' selected="selected"' : '';
+        display_mode.append('<option' + sel +'>' + columns[i] + '</option>');
+      }
+    }
+  });
   display_mode.change(function () { data = []; last_stamp = null; });
 });
 

File iostat.js

View file
  • Ignore whitespace
 app.use('/static', express.static(__dirname));
 
 app.get('/data/:col', function(req, res) {
-  if (columns.indexOf(req.params.col) != -1) {
+  if (req.params.col == 'column_names') {
+    res.writeHead(200);
+    res.end(JSON.stringify(columns));
+  } else if (columns.indexOf(req.params.col) != -1) {
     since = parseInt(req.param('since', null));
     getDiskInfo(req.params.col, since, res);
   }
 
     // make sure we have column names on the first run
     if (columns.length == 0) {
-      raw_columns = stdout.match(/^Device:(\s+[\w\/%\-]+)+/gm);
+      raw_columns = stdout.match(/^Device:(\s+[\w\/%\-]+)+$/gm);
       if (!raw_columns) return;
 
       raw_columns = raw_columns.map(splitColumns)[0];
     }
 
     // now try to parse disk information
-    disks = stdout.match(/^\w+(\s+\d+.\d+){13}/gm);
+    disks = stdout.match(/^\w+(\s+\d+.\d+)+$/gm);
     if (!disks) return;
 
     disks.forEach(function (disk) {