mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
Current progress on stats page, nonfunctional.
This commit is contained in:
parent
66894e7596
commit
b7daf91723
6 changed files with 119 additions and 3 deletions
56
app/components/stats/statsController.js
Normal file
56
app/components/stats/statsController.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
angular.module('stats', [])
|
||||
.controller('StatsController', ['Settings', '$scope', 'Messages', '$timeout', 'Container', 'LineChart', '$routeParams', function (Settings, $scope, Messages, $timeout, Container, LineChart, $routeParams) {
|
||||
var sessionKey = 'dockeruiStats-' + $routeParams.id;
|
||||
var localData = sessionStorage.getItem(sessionKey);
|
||||
if (localData) {
|
||||
$scope.dockerStats = localData;
|
||||
} else {
|
||||
$scope.dockerStats = [];
|
||||
}
|
||||
|
||||
|
||||
function updateStats() {
|
||||
Container.stats({id: $routeParams.id}, function (d) {
|
||||
console.log(d);
|
||||
var arr = Object.keys(d).map(function (key) {return d[key];});
|
||||
if (arr.join('').indexOf('no such id') !== -1) {
|
||||
Messages.error('Unable to retrieve container stats', 'Has this container been removed?');
|
||||
return;
|
||||
}
|
||||
$scope.dockerStats.push(d);
|
||||
sessionStorage.setItem(sessionKey, $scope.dockerStats);
|
||||
$timeout(updateStats, 1000);
|
||||
// Update graph with latest data
|
||||
updateChart($scope.dockerStats);
|
||||
}, function () {
|
||||
Messages.error('Unable to retrieve container stats', 'Has this container been removed?');
|
||||
});
|
||||
}
|
||||
|
||||
updateStats();
|
||||
|
||||
$scope.calculateCPUPercent = function (stats) {
|
||||
// Same algorithm the official client uses: https://github.com/docker/docker/blob/master/api/client/stats.go#L195-L208
|
||||
var prevCpu = stats.precpu_stats;
|
||||
var curCpu = stats.cpu_stats;
|
||||
|
||||
var cpuPercent = 0.0;
|
||||
|
||||
// calculate the change for the cpu usage of the container in between readings
|
||||
var cpuDelta = curCpu.cpu_usage.total_usage - prevCpu.cpu_usage.total_usage;
|
||||
// calculate the change for the entire system between readings
|
||||
var systemDelta = curCpu.system_cpu_usage - prevCpu.system_cpu_usage;
|
||||
|
||||
if (systemDelta > 0.0 && cpuDelta > 0.0) {
|
||||
cpuPercent = (cpuDelta / systemDelta) * curCpu.cpu_usage.percpu_usage.size() * 100.0;
|
||||
}
|
||||
return cpuPercent
|
||||
};
|
||||
|
||||
function updateChart(data) {
|
||||
// TODO: Build data in the right format and create chart.
|
||||
//LineChart.build('#cpu-stats-chart', $scope.dockerStats, function (d) {
|
||||
// return $scope.calculateCPUPercent(d)
|
||||
//});
|
||||
}
|
||||
}]);
|
Loading…
Add table
Add a link
Reference in a new issue