@cryptotaxi247 / netdata-1 / commits / 892885e90

support data-common-units="NAME"

Costa Tsaousis (ktsaou) committed Oct 6, 2017 at 22:52 UTC 892885e90d67b1d5d27d74946739a3aff74caf9c
2 files changed +86 -9
web/dashboard.js
+76 -7
@@ -383,7 +383,7 @@ var NETDATA = window.NETDATA || {};
383 focus: false,
384 visibility: false,
385 chart_data_url: false,
386 - chart_errors: false, // FIXME: remember to set it to false before merging
386 + chart_errors: true, // FIXME: remember to set it to false before merging
387 chart_timing: false,
388 chart_calls: false,
389 libraries: false,
@@ -1470,6 +1470,8 @@ var NETDATA = window.NETDATA || {};
1470 // units conversion
1471
1472 NETDATA.unitsConversion = {
1473 + keys: {},
1474 + latest: {},
1475 units: {
1476 'kilobits/s': {
1477 'bits/s' : 0.001,
@@ -1483,16 +1485,19 @@ var NETDATA = window.NETDATA || {};
1485 'megabytes/s': 1000,
1486 'gigabytes/s': 1000000
1487 },
1488 + 'KB': {
1489 + 'B' : 0.001,
1490 + 'KB': 1,
1491 + 'MB': 1000,
1492 + 'GB': 1000000
1493 + },
1494 'MB': {
1487 - 'B' : 0.000001,
1495 'KB': 0.001,
1496 'MB': 1,
1497 'GB': 1000,
1498 'TB': 1000000
1499 },
1500 'GB': {
1494 - 'B' : 0.000000001,
1495 - 'KB': 0.000001,
1501 'MB': 0.001,
1502 'GB': 1,
1503 'TB': 1000
@@ -1506,7 +1511,7 @@ var NETDATA = window.NETDATA || {};
1511 }
1512 },
1513
1509 - get: function(min, max, units, desired_units, switch_units_callback) {
1514 + get: function(uuid, min, max, units, desired_units, common_units_name, switch_units_callback) {
1515 if(typeof units === 'undefined')
1516 units = 'undefined';
1517
@@ -1538,7 +1543,70 @@ var NETDATA = window.NETDATA || {};
1543 }
1544 }
1545
1541 - if (tunits !== null) {
1546 + if(tunits !== null && typeof common_units_name === 'string' && typeof uuid === 'string') {
1547 + // console.log(uuid + ' name: ' + common_units_name + ', divider: ' + tdivider.toString() + ', units: ' + tunits);
1548 +
1549 + var t = this.keys[common_units_name];
1550 + if(typeof t === 'undefined') {
1551 + // add our commonUnits
1552 + this.keys[common_units_name] = {};
1553 + t = this.keys[common_units_name];
1554 + }
1555 +
1556 + // add our divider
1557 + t[uuid] = tdivider;
1558 + var td = tdivider;
1559 +
1560 + // find the max divider
1561 + for(x in t)
1562 + if(t.hasOwnProperty(x) && t[x] > tdivider)
1563 + tdivider = t[x];
1564 +
1565 + // console.log(uuid + ' old divider ' + t[uuid].toString() + ', new divider ' + tdivider.toString());
1566 +
1567 + if(td !== tdivider) {
1568 + // find the name for this divider
1569 + tunits = null;
1570 + for (x in NETDATA.unitsConversion.units[units]) {
1571 + if (NETDATA.unitsConversion.units[units].hasOwnProperty(x) && NETDATA.unitsConversion.units[units][x] === tdivider) {
1572 + tunits = x;
1573 + break;
1574 + }
1575 + }
1576 +
1577 + // console.log(uuid + ' new units ' + tunits);
1578 + }
1579 +
1580 + if (tunits !== null && tdivider > 0) {
1581 + switch_units_callback(tunits);
1582 + divider = tdivider;
1583 +
1584 + var latest = NETDATA.unitsConversion.latest[common_units_name];
1585 + if(typeof latest === 'undefined') {
1586 + NETDATA.unitsConversion.latest[common_units_name] = {
1587 + units: tunits,
1588 + divider: tdivider
1589 + };
1590 + latest = NETDATA.unitsConversion.latest[common_units_name];
1591 + }
1592 + else {
1593 + latest.units = tunits;
1594 + latest.divider = tdivider;
1595 + }
1596 +
1597 + return function(value) {
1598 + if(tdivider !== latest.divider) {
1599 + // console.log(uuid + ' new units detected, old divider ' + tdivider.toString() + ', new divider ' + latest.divider.toString() + ' new units ' + latest.units);
1600 + switch_units_callback(latest.units);
1601 + tdivider = latest.divider;
1602 + }
1603 +
1604 + return value / tdivider;
1605 + }
1606 + }
1607 + }
1608 +
1609 + if (tunits !== null && tdivider > 0) {
1610 switch_units_callback(tunits);
1611 divider = tdivider;
1612 }
@@ -1794,6 +1862,7 @@ var NETDATA = window.NETDATA || {};
1862 that.units = NETDATA.dataAttribute(that.element, 'units', null); // the units of the chart dimensions
1863 that.units_desired = NETDATA.dataAttribute(that.element, 'desired-units', NETDATA.options.current.units); // the units of the chart dimensions
1864 that.units_current = that.units;
1865 + that.units_common = NETDATA.dataAttribute(that.element, 'common-units', null);
1866
1867 that.append_options = NETDATA.dataAttribute(that.element, 'append-options', null); // additional options to pass to netdata
1868 that.override_options = NETDATA.dataAttribute(that.element, 'override-options', null); // override options to pass to netdata
@@ -2659,7 +2728,7 @@ var NETDATA = window.NETDATA || {};
2728 __unitsConversionLastMin = min;
2729 __unitsConversionLastMax = max;
2730
2662 - __unitsConversion = NETDATA.unitsConversion.get(min, max, this.units, this.units_desired, function (units) {
2731 + __unitsConversion = NETDATA.unitsConversion.get(this.uuid, min, max, this.units, this.units_desired, this.units_common, function (units) {
2732 // console.log('switching units from ' + that.units.toString() + ' to ' + units.toString());
2733 that.units_current = units;
2734 that.legendSetUnitsString(that.units_current);
web/index.html
+10 -2
@@ -1333,6 +1333,7 @@
1333 + ' data-before="0"'
1334 + ' data-after="-' + duration.toString() + '"'
1335 + ' data-points="' + duration.toString() + '"'
1336 + + ' data-common-units="system.io.mainhead"'
1337 + ' role="application"></div>';
1338
1339 head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.io"'
@@ -1343,6 +1344,7 @@
1344 + ' data-before="0"'
1345 + ' data-after="-' + duration.toString() + '"'
1346 + ' data-points="' + duration.toString() + '"'
1347 + + ' data-common-units="system.io.mainhead"'
1348 + ' role="application"></div>';
1349 }
1350
@@ -1367,6 +1369,7 @@
1369 + ' data-before="0"'
1370 + ' data-after="-' + duration.toString() + '"'
1371 + ' data-points="' + duration.toString() + '"'
1372 + + ' data-common-units="system.ipv4.mainhead"'
1373 + ' role="application"></div>';
1374
1375 head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.ipv4"'
@@ -1377,6 +1380,7 @@
1380 + ' data-before="0"'
1381 + ' data-after="-' + duration.toString() + '"'
1382 + ' data-points="' + duration.toString() + '"'
1383 + + ' data-common-units="system.ipv4.mainhead"'
1384 + ' role="application"></div>';
1385 }
1386 else if(typeof charts['system.ipv6'] !== 'undefined') {
@@ -1389,6 +1393,7 @@
1393 + ' data-before="0"'
1394 + ' data-after="-' + duration.toString() + '"'
1395 + ' data-points="' + duration.toString() + '"'
1396 + + ' data-common-units="system.ipv6.mainhead"'
1397 + ' role="application"></div>';
1398
1399 head += '<div class="netdata-container" style="margin-right: 10px;" data-netdata="system.ipv6"'
@@ -1400,6 +1405,7 @@
1405 + ' data-before="0"'
1406 + ' data-after="-' + duration.toString() + '"'
1407 + ' data-points="' + duration.toString() + '"'
1408 + + ' data-common-units="system.ipv6.mainhead"'
1409 + ' role="application"></div>';
1410 }
1411
@@ -2721,7 +2727,9 @@
2727 var units_sync_option = function(option) {
2728 var self = $('#' + option);
2729
2724 - self.bootstrapToggle(NETDATA.options.current.units === 'auto'?'on':'off');
2730 + if(self.prop('checked') !== (NETDATA.getOption('units') === 'auto')) {
2731 + self.bootstrapToggle(NETDATA.getOption('units') === 'auto' ? 'on' : 'off');
2732 + }
2733 };
2734
2735 sync_option('eliminate_zero_dimensions');
@@ -3554,4 +3562,4 @@
3562 </div>
3563 </body>
3564 </html>
3557 -<script type="text/javascript" src="dashboard.js?v20171005-1"></script>
3565 +<script type="text/javascript" src="dashboard.js?v20171006-1"></script>