@cryptotaxi247 / netdata-1 / commits / 9db3fb241

better human durations on the dashboard and more information on the alarm log

Costa Tsaousis (ktsaou) committed Oct 2, 2016 at 23:00 UTC 9db3fb2415b35885e2a9b3959d636d8a81928339
1 file changed +74 -24
web/index.html
+74 -24
@@ -1431,17 +1431,40 @@
1431 return t.toLocaleDateString() + space + t.toLocaleTimeString();
1432 }
1433
1434 - function seconds4human(seconds, sfx, space) {
1435 - if(typeof space === 'undefined')
1436 - space = ' ';
1434 + function seconds4human(seconds, options) {
1435 + var default_options = {
1436 + now: 'now',
1437 + space: ' ',
1438 + negative_suffix: 'ago',
1439 + hour: 'hour',
1440 + hours: 'hours',
1441 + minute: 'minute',
1442 + minutes: 'minutes',
1443 + second: 'second',
1444 + seconds: 'seconds',
1445 + and: 'and'
1446 + };
1447 +
1448 + if(typeof options !== 'object')
1449 + options = default_options;
1450 + else {
1451 + var x;
1452 + for(x in default_options) {
1453 + if(typeof options[x] !== 'string')
1454 + options[x] = default_options[x];
1455 + }
1456 + }
1457 +
1458 + if(typeof seconds === 'string')
1459 + seconds = parseInt(seconds);
1460
1461 if(seconds === 0)
1439 - return 'now';
1462 + return options.now;
1463
1464 var suffix = '';
1465 if(seconds < 0) {
1466 seconds = -seconds;
1444 - if(sfx) suffix = space + 'ago';
1467 + if(options.negative_suffix !== '') suffix = options.space + options.negative_suffix;
1468 }
1469
1470 var hours = Math.floor(seconds / 3600);
@@ -1452,22 +1475,22 @@
1475
1476 var txt = '';
1477
1455 - if(hours > 1) txt += hours.toString() + space + 'hours';
1456 - else if(hours === 1) txt += hours.toString() + space + 'hour';
1478 + if(hours > 1) txt += hours.toString() + options.space + options.hours;
1479 + else if(hours === 1) txt += hours.toString() + options.space + options.hour;
1480
1481 if(hours > 0 && minutes > 0 && seconds == 0)
1459 - txt += space + 'and' + space;
1482 + txt += options.space + options.and + options.space;
1483 else if(hours > 0 && minutes > 0 && seconds > 0)
1461 - txt += ',' + space;
1484 + txt += ',' + options.space;
1485
1463 - if(minutes > 1) txt += minutes.toString() + space + 'minutes';
1464 - else if(minutes === 1) txt += minutes.toString() + space + 'minute';
1486 + if(minutes > 1) txt += minutes.toString() + options.space + options.minutes;
1487 + else if(minutes === 1) txt += minutes.toString() + options.space + options.minute;
1488
1489 if((minutes > 0 || minutes > 0) && seconds > 0)
1467 - txt += space + 'and' + space;
1490 + txt += options.space + options.and + options.space;
1491
1469 - if(seconds > 1) txt += seconds.toString() + space + 'seconds';
1470 - else if(seconds === 1) txt += seconds.toString() + space + 'second';
1492 + if(seconds > 1) txt += Math.floor(seconds).toString() + options.space + options.seconds;
1493 + else if(seconds === 1) txt += Math.floor(seconds).toString() + options.space + options.second;
1494
1495 return txt + suffix;
1496 }
@@ -1489,7 +1512,7 @@
1512
1513 return '<code>' + alarm.lookup_method + '</code> '
1514 + dimensions + ', of chart <code>' + alarm.chart + '</code>'
1492 - + ', starting <code>' + seconds4human(alarm.lookup_after + alarm.lookup_before, true) + '</code> and up to <code>' + seconds4human(alarm.lookup_before, true) + '</code>'
1515 + + ', starting <code>' + seconds4human(alarm.lookup_after + alarm.lookup_before) + '</code> and up to <code>' + seconds4human(alarm.lookup_before) + '</code>'
1516 + ((alarm.lookup_options)?(', with options <code>' + alarm.lookup_options.replace(' ', ',&nbsp;') + '</code>'):'')
1517 + '.';
1518 }
@@ -1512,25 +1535,25 @@
1535 var delay = '';
1536 if((alarm.delay_up_duration > 0 || alarm.delay_down_duration > 0) && alarm.delay_multiplier != 0 && alarm.delay_max_duration > 0) {
1537 if(alarm.delay_up_duration == alarm.delay_down_duration) {
1515 - delay += '<small><br/>hysteresis ' + seconds4human(alarm.delay_up_duration);
1538 + delay += '<small><br/>hysteresis ' + seconds4human(alarm.delay_up_duration, { negative_suffix: '' });
1539 }
1540 else {
1541 delay = '<small><br/>hysteresis ';
1542 if(alarm.delay_up_duration > 0) {
1520 - delay += 'on&nbsp;escalation&nbsp;<code>' + seconds4human(alarm.delay_up_duration) + '</code>, ';
1543 + delay += 'on&nbsp;escalation&nbsp;<code>' + seconds4human(alarm.delay_up_duration, { negative_suffix: '' }) + '</code>, ';
1544 }
1545 if(alarm.delay_down_duration > 0) {
1523 - delay += 'on&nbsp;recovery&nbsp;<code>' + seconds4human(alarm.delay_down_duration) + '</code>, ';
1546 + delay += 'on&nbsp;recovery&nbsp;<code>' + seconds4human(alarm.delay_down_duration, { negative_suffix: '' }) + '</code>, ';
1547 }
1548 }
1549 if(alarm.delay_multiplier != 1.0) {
1550 delay += 'multiplied&nbsp;by&nbsp;<code>' + alarm.delay_multiplier.toString() + '</code>';
1528 - delay += ',&nbsp;up&nbsp;to&nbsp;<code>' + seconds4human(alarm.delay_max_duration) + '</code>';
1551 + delay += ',&nbsp;up&nbsp;to&nbsp;<code>' + seconds4human(alarm.delay_max_duration, { negative_suffix: '' }) + '</code>';
1552 }
1553 delay += '</small>';
1554 }
1555
1533 - html += '<tr><td width="10%" style="text-align:right">check&nbsp;every</td><td>' + seconds4human(alarm.update_every) + '</td></tr>'
1556 + html += '<tr><td width="10%" style="text-align:right">check&nbsp;every</td><td>' + seconds4human(alarm.update_every, { negative_suffix: '' }) + '</td></tr>'
1557 + '<tr><td width="10%" style="text-align:right">execute</td><td><span style="font-family: monospace;">' + alarm.exec + '</span>' + delay + '</td></tr>'
1558 + '<tr><td width="10%" style="text-align:right">source</td><td><span style="font-family: monospace;">' + alarm.source + '</span></td></tr>'
1559 + '</table></td></tr>';
@@ -1706,6 +1729,7 @@
1729 field: 'when',
1730 title: 'Event Date',
1731 valign: 'middle',
1732 + titleTooltip: 'The date and time the even took place',
1733 switchable: false,
1734 sortable: true,
1735 formatter: function(value, row, index) { return timestamp4human(value, ' '); },
@@ -1714,12 +1738,14 @@
1738 field: 'hostname',
1739 title: 'Host',
1740 valign: 'middle',
1741 + titleTooltip: 'The host that generated this event',
1742 visible: false,
1743 sortable: true
1744 },
1745 {
1746 field: 'unique_id',
1747 title: 'Unique ID',
1748 + titleTooltip: 'The host unique ID for this event',
1749 valign: 'middle',
1750 visible: false,
1751 sortable: true
@@ -1727,6 +1753,7 @@
1753 {
1754 field: 'alarm_id',
1755 title: 'Alarm ID',
1756 + titleTooltip: 'The ID of the alarm that generated this event',
1757 valign: 'middle',
1758 visible: false,
1759 sortable: true
@@ -1734,6 +1761,7 @@
1761 {
1762 field: 'alarm_event_id',
1763 title: 'Alarm Event ID',
1764 + titleTooltip: 'The incremental ID of this event for the given alarm',
1765 valign: 'middle',
1766 visible: false,
1767 sortable: true
@@ -1741,6 +1769,7 @@
1769 {
1770 field: 'chart',
1771 title: 'Chart',
1772 + titleTooltip: 'The chart the alarm is attached to',
1773 valign: 'middle',
1774 switchable: false,
1775 sortable: true
@@ -1748,6 +1777,7 @@
1777 {
1778 field: 'family',
1779 title: 'Family',
1780 + titleTooltip: 'The family of the chart the alarm is attached to',
1781 valign: 'middle',
1782 visible: false,
1783 sortable: true
@@ -1755,6 +1785,7 @@
1785 {
1786 field: 'name',
1787 title: 'Alarm',
1788 + titleTooltip: 'The alarm name that generated this event',
1789 formatter: function(value, row, index) {
1790 return value.toString().replace(/_/g, ' ');
1791 },
@@ -1765,6 +1796,7 @@
1796 {
1797 field: 'old_value',
1798 title: 'Old Value',
1799 + titleTooltip: 'The value of the alarm, just before this event',
1800 valign: 'middle',
1801 visible: false,
1802 sortable: true
@@ -1772,6 +1804,7 @@
1804 {
1805 field: 'value',
1806 title: 'Value',
1807 + titleTooltip: 'The value of the alarm, that triggered this event',
1808 formatter: function(value, row, index) {
1809 return ((value !== null)?Math.floor(value):'NaN').toString();
1810 },
@@ -1782,12 +1815,14 @@
1815 {
1816 field: 'units',
1817 title: 'Units',
1818 + titleTooltip: 'The units of the value of the alarm',
1819 valign: 'middle',
1820 sortable: true
1821 },
1822 {
1823 field: 'old_status',
1824 title: 'Old Status',
1825 + titleTooltip: 'The status of the alarm, just before this event',
1826 valign: 'middle',
1827 visible: false,
1828 sortable: true
@@ -1795,14 +1830,16 @@
1830 {
1831 field: 'status',
1832 title: 'Status',
1833 + titleTooltip: 'The status of the alarm, that was set due to this event',
1834 valign: 'middle',
1835 switchable: false,
1836 sortable: true
1837 },
1838 {
1839 field: 'duration',
1804 - title: 'Duration',
1805 - formatter: function(value, row, index) { return seconds4human(value, false, ' '); },
1840 + title: 'Last Duration',
1841 + titleTooltip: 'The duration the alarm was at its previous state, just before this event',
1842 + formatter: function(value, row, index) { return seconds4human(value, { negative_suffix: '', space: ' ', now: 'no time' }); },
1843 valign: 'middle',
1844 visible: false,
1845 sortable: true
@@ -1810,7 +1847,8 @@
1847 {
1848 field: 'non_clear_duration',
1849 title: 'Raised Duration',
1813 - formatter: function(value, row, index) { return seconds4human(value, false, ' '); },
1850 + titleTooltip: 'The duration the alarm was raised, just before this event',
1851 + formatter: function(value, row, index) { return seconds4human(value, { negative_suffix: '', space: ' ', now: 'no time' }); },
1852 valign: 'middle',
1853 visible: false,
1854 sortable: true
@@ -1818,6 +1856,7 @@
1856 {
1857 field: 'recipient',
1858 title: 'Recipient',
1859 + titleTooltip: 'The recipient of this event',
1860 valign: 'middle',
1861 visible: false,
1862 sortable: true
@@ -1825,6 +1864,7 @@
1864 {
1865 field: 'processed',
1866 title: 'Processed Status',
1867 + titleTooltip: 'True when this event is processed',
1868 valign: 'middle',
1869 visible: false,
1870 sortable: true
@@ -1832,6 +1872,7 @@
1872 {
1873 field: 'updated',
1874 title: 'Updated Status',
1875 + titleTooltip: 'True when this event has been updated by another event',
1876 valign: 'middle',
1877 visible: false,
1878 sortable: true
@@ -1839,6 +1880,7 @@
1880 {
1881 field: 'updated_by_id',
1882 title: 'Updated By ID',
1883 + titleTooltip: 'The unique ID of the event that obsoleted this one',
1884 valign: 'middle',
1885 visible: false,
1886 sortable: true
@@ -1846,6 +1888,7 @@
1888 {
1889 field: 'updates_id',
1890 title: 'Updates ID',
1891 + titleTooltip: 'The unique ID of the event obsoleted because of this event',
1892 valign: 'middle',
1893 visible: false,
1894 sortable: true
@@ -1853,6 +1896,7 @@
1896 {
1897 field: 'exec',
1898 title: 'Script',
1899 + titleTooltip: 'The script to handle the event notification',
1900 valign: 'middle',
1901 visible: false,
1902 sortable: true
@@ -1860,6 +1904,7 @@
1904 {
1905 field: 'exec_run',
1906 title: 'Script Run At',
1907 + titleTooltip: 'The date and time the script has been ran',
1908 formatter: function(value, row, index) { return timestamp4human(value, ' '); },
1909 valign: 'middle',
1910 visible: false,
@@ -1868,6 +1913,7 @@
1913 {
1914 field: 'exec_code',
1915 title: 'Script Return Value',
1916 + titleTooltip: 'The return code of the script',
1917 valign: 'middle',
1918 visible: false,
1919 sortable: true
@@ -1875,7 +1921,8 @@
1921 {
1922 field: 'delay',
1923 title: 'Script Delay',
1878 - formatter: function(value, row, index) { return seconds4human(value, false, ' '); },
1924 + titleTooltip: 'The hysteresis of the notification',
1925 + formatter: function(value, row, index) { return seconds4human(value, { negative_suffix: '', space: ' ', now: 'no time' }); },
1926 valign: 'middle',
1927 visible: false,
1928 sortable: true
@@ -1883,6 +1930,7 @@
1930 {
1931 field: 'delay_up_to_timestamp',
1932 title: 'Script Delay Run At',
1933 + titleTooltip: 'The date and time the script should be run, after hysteresis',
1934 formatter: function(value, row, index) { return timestamp4human(value, ' '); },
1935 valign: 'middle',
1936 visible: false,
@@ -1891,6 +1939,7 @@
1939 {
1940 field: 'info',
1941 title: 'Description',
1942 + titleTooltip: 'A short description of the alarm',
1943 valign: 'middle',
1944 visible: false,
1945 sortable: true
@@ -1898,6 +1947,7 @@
1947 {
1948 field: 'source',
1949 title: 'Alarm Source',
1950 + titleTooltip: 'The source of configuration of the alarm',
1951 valign: 'middle',
1952 visible: false,
1953 sortable: true