stats first try
This commit is contained in:
		@@ -413,7 +413,7 @@ function Docker() {
 | 
			
		||||
                $("#popup6").click(function() {
 | 
			
		||||
                    var download = document.createElement('a');
 | 
			
		||||
                    download.href = 'data:application/json,'
 | 
			
		||||
                        + encodeURI(JSON.stringify(_containers.creation(name), null, 2));
 | 
			
		||||
                        + encodeURI(JSON.stringify(_containers.configuration(name), null, 2));
 | 
			
		||||
                    download.target = '_blank';
 | 
			
		||||
                    download.download = name+'.json';
 | 
			
		||||
                    var clickEvent = new MouseEvent("click", {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,39 @@ module.exports = function() {
 | 
			
		||||
        var pty = require('pty.js');
 | 
			
		||||
        var proc = require('child_process');
 | 
			
		||||
 | 
			
		||||
        function stats(ids) {
 | 
			
		||||
            var res = [];
 | 
			
		||||
            var fs = require('fs');
 | 
			
		||||
            var base = "/sys/fs/cgroup/";
 | 
			
		||||
            var dataPoints = {
 | 
			
		||||
                "cpuacct": "stat",
 | 
			
		||||
                "memory": "usage_in_bytes",
 | 
			
		||||
                "memory": "max_usage_in_bytes"
 | 
			
		||||
            };
 | 
			
		||||
            ids.forEach(function(id) {
 | 
			
		||||
                res[id] = {};
 | 
			
		||||
                for (key in dataPoints) {
 | 
			
		||||
                    var file = base + key + '/docker/' + id + '/' + dataPoints[key];
 | 
			
		||||
                    res[id][key] = {};
 | 
			
		||||
                    fs.readFile(file, 'utf8', function(err, data) {
 | 
			
		||||
                        if (err) return;
 | 
			
		||||
                        data.trim().split('\n').forEach(function(v, i) {
 | 
			
		||||
                            var vals = v.split(' ');
 | 
			
		||||
                            switch (vals.length) {
 | 
			
		||||
                            case 1:
 | 
			
		||||
                                res[id][dataPoints[key]] = parseInt(vals[0]);
 | 
			
		||||
                                break;
 | 
			
		||||
                            case 2:
 | 
			
		||||
                                res[id][key][dataPoints[key]] = {};
 | 
			
		||||
                                res[id][key][dataPoints[key]][vals[0]] = parseInt(vals[1]);
 | 
			
		||||
                                break;
 | 
			
		||||
                            }
 | 
			
		||||
                        });
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        console.log("new client");
 | 
			
		||||
 | 
			
		||||
        function emit(signal, data, info) {
 | 
			
		||||
@@ -49,6 +82,7 @@ module.exports = function() {
 | 
			
		||||
                    error: error, stderr: stderr, stdout: stdout
 | 
			
		||||
                });
 | 
			
		||||
            exec("docker inspect "+stdout.trim().replace(/\n/g, " "), containerinspect);
 | 
			
		||||
            stats(stdout.trim().split('\n'));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        function updatecontainers(error, stdout, stderr) {
 | 
			
		||||
@@ -56,7 +90,7 @@ module.exports = function() {
 | 
			
		||||
                return fail("update docker container failed", {
 | 
			
		||||
                    error: error, stderr: stderr, stdout: stdout
 | 
			
		||||
                });
 | 
			
		||||
            exec("docker ps -aq", containerlist);
 | 
			
		||||
            exec("docker ps -aq --no-trunc ", containerlist);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        function modify(cmd, name) {
 | 
			
		||||
@@ -91,7 +125,7 @@ module.exports = function() {
 | 
			
		||||
                return fail("update docker images failed", {
 | 
			
		||||
                    error: error, stderr: stderr, stdout: stdout
 | 
			
		||||
                });
 | 
			
		||||
            exec("docker images -q", imagelist);
 | 
			
		||||
            exec("docker images -q --no-trunc", imagelist);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        function modify(cmd, name) {
 | 
			
		||||
@@ -169,7 +203,7 @@ module.exports = function() {
 | 
			
		||||
        
 | 
			
		||||
        function bash_input(data) {
 | 
			
		||||
            console.log("-> bash-input("+data.name+", "+data.text+")");
 | 
			
		||||
            new_bash(name);
 | 
			
		||||
            new_bash(data.name);
 | 
			
		||||
            bash_connections[data.name].stdin.resume();
 | 
			
		||||
            bash_connections[data.name].stdin.write(data.text);
 | 
			
		||||
        }
 | 
			
		||||
@@ -193,6 +227,7 @@ module.exports = function() {
 | 
			
		||||
            .on('bash-start', bash_start)
 | 
			
		||||
            .on('bash-input', bash_input)
 | 
			
		||||
            .on('bash-end', bash_end);
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user