diff --git a/glances/outputs/static/html/plugins/alert.html b/glances/outputs/static/html/plugins/alert.html index e8011851..8ba093de 100644 --- a/glances/outputs/static/html/plugins/alert.html +++ b/glances/outputs/static/html/plugins/alert.html @@ -1,7 +1,7 @@
-{{alert.begin}} ({{(alert[1]-alert[0]) | date : 'h:mm:ss'}}) - {{alert[2]}} on {{alert[3]}} ({{alert[4]}}) +{{alert.begin | date : 'yyyy-MM-dd H:mm:ss'}} ({{ alert.ongoing ? 'ongoing' : alert.duration }}) - {{alert[2]}} on {{alert[3]}} ({{alert[4]}})
diff --git a/glances/outputs/static/js/stats_controller.js b/glances/outputs/static/js/stats_controller.js index 569d265f..e6b128c8 100644 --- a/glances/outputs/static/js/stats_controller.js +++ b/glances/outputs/static/js/stats_controller.js @@ -106,22 +106,13 @@ glancesApp.controller('statsController', function($scope, $http, $interval, $q, return hour +":" + minutes + ":" + seconds + "." + millisecondsStr }; - function dateformat(input) { - var millis = input * 1000.0; - var d = new Date(millis) - var year = d.getFullYear() - var month = leftpad(d.getMonth() + 1) // JANUARY = 0 - var day = leftpad(d.getDate()) - return year + "-" + month + "-" + day + " " + datetimeformat(input) + function durationBetweenTwoDates(startDate, endDate) { + var duration = endDate - startDate; + var seconds = parseInt((duration/1000)%60) + , minutes = parseInt((duration/(1000*60))%60) + , hours = parseInt((duration/(1000*60*60))%24); - } - function datetimeformat(input) { - var millis = input * 1000.0; - var d = new Date(millis) - var hour = leftpad(d.getUTCHours()) // TODO : multiple days ( * (d.getDay() * 24))) - var minutes = leftpad(d.getUTCMinutes()) - var seconds = leftpad(d.getUTCSeconds()) - return hour + ":" + minutes + ":" + seconds + return _.padLeft(hours,2,'0') + ":" + _.padLeft(minutes,2,'0') + ":" + _.padLeft(seconds,2,'0'); } for (var i = 0; i < response['processlist'].length; i++) { @@ -134,9 +125,14 @@ glancesApp.controller('statsController', function($scope, $http, $interval, $q, process.io_write = (process.io_counters[1] - process.io_counters[3]) / process.time_since_update } for (var i = 0; i < response['alert'].length; i++) { - var alert = response['alert'][i] - alert.begin = dateformat(alert[0]) - alert.end = datetimeformat(alert[1] - alert[0]) + var alert = response['alert'][i]; + alert.begin = alert[0] * 1000; + alert.end = alert[1] * 1000; + alert.ongoing = alert[1] == -1; + + if (!alert.ongoing) { + alert.duration = durationBetweenTwoDates(alert.begin, alert.end); + } } $scope.result = response; canceler.resolve()