diff --git a/ChangeLog b/ChangeLog index af20fd7..3a1af91 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2016-11-22 15:56 marc + + * nodejs/authentication, nodejs/package.json.in: authentication is + now in an own npm package + +2016-09-21 17:24 marc + + * ChangeLog, debian/control.in, servicedock.spec.in: fix build + where java is not installed + 2016-09-21 09:43 marc * debian/control.in, nodejs/makefile.am: fix build problem in diff --git a/nodejs/etc/servicedock.json b/nodejs/etc/servicedock.json index 185bf95..805856f 100644 --- a/nodejs/etc/servicedock.json +++ b/nodejs/etc/servicedock.json @@ -2,14 +2,7 @@ "port": 8888, "restrict": { "passwords": { - "foo": ["sha256", "fcde2b2edxx56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"] - }, - "ldap": { - "url": "ldap://dev.marc.waeckerlin.org", - "adminDn": "cn=tmp,ou=system,ou=people,dc=dev,dc=marc,dc=waeckerlin,dc=org", - "adminPassword": "secret", - "searchBase": "ou=person,ou=people,dc=dev,dc=marc,dc=waeckerlin,dc=org", - "searchFilter": "(uid={{username}})" + "foo": ["sha256", "fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9"] } } } diff --git a/nodejs/public/javascripts/servicedock.js b/nodejs/public/javascripts/servicedock.js index f6f2d03..643f387 100644 --- a/nodejs/public/javascripts/servicedock.js +++ b/nodejs/public/javascripts/servicedock.js @@ -308,6 +308,7 @@ function showviz(vizpath, more) { res = "digraph {\n"+" rankdir="+rankdir+";\n"+viz+"\n}"; try { status(more?Viz(res)+more:Viz(res)); + stats(); $('#main a > ellipse + text').attr('font-size', '12'); $('#main a > ellipse + text + text') .attr('font-weight', 'bold') @@ -349,29 +350,21 @@ function size(num) { } } -var oldoldstats = null; -var oldstats = null; +var laststats=null; function stats(data) { - console.log("->rcv stats"); - if (!data && oldstats && oldoldstats) { - data = oldstats; - oldstats = oldoldstats; - } - if (oldstats) for (name in data) { - var s = data[name]; - var o = oldstats[name]; - if (!o|| !s) continue; - $('#main text + text:contains("'+name+'") + text') - .html('cpu: ' - +(Math.round((s.cpuacct.usage.data-o.cpuacct.usage.data) - /(s.cpuacct.usage.date-o.cpuacct.usage.date) - /100) - /100) - +'% mem: ' - +size(s.memory.usage_in_bytes.data)); - } - oldoldstats = oldstats; - oldstats = data; + if (data) + console.log("->rcv stats"); + else + data=laststats; + if (!data) return; + var lines = data.split("\n"); + var head = lines.shift(); + lines.forEach(function(line) { + if (!line) return; + elements = line.split(/ +/); + $('#main text + text:contains("'+elements[0]+'") + text') + .html('cpu: '+elements[1]+' mem: '+elements[7]); + }); } function images(i) { diff --git a/nodejs/servicedock.js b/nodejs/servicedock.js index 679c321..678f1f6 100644 --- a/nodejs/servicedock.js +++ b/nodejs/servicedock.js @@ -1,3 +1,9 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 try { process.on('uncaughtException', function(e) { @@ -19,7 +25,7 @@ try { var package = require(__dirname+'/package.json'); var config = require(package.path.config); var docker = require(__dirname+'/docker')(app); - var authentication = require(__dirname+'/authentication')(config.restrict); + var authentication = require('authentication.js')(config.restrict); var sockets = require(__dirname+'/sockets')(io, authentication); // Configuration diff --git a/nodejs/sockets/index.js b/nodejs/sockets/index.js index b0d668d..f688554 100644 --- a/nodejs/sockets/index.js +++ b/nodejs/sockets/index.js @@ -5,7 +5,7 @@ module.exports = function(io, authentication) { var docker = require(__dirname+'/../docker')(); var module={}; - var idtoname = {}; + var running=""; function broadcast(signal, data) { console.log("<= signal: "+signal); @@ -31,13 +31,12 @@ module.exports = function(io, authentication) { return fail("inspect docker containers failed", { error: error, stderr: stderr, stdout: stdout }); - idtoname = {}; + running = ""; JSON.parse(stdout).forEach(function(n) { - if (n.State.Running) idtoname[n.Id] = n.Name.replace(/^\//, ''); + if (n.State.Running) running+=" "+n.Name.replace(/^\//, ''); }); - if (oldcontainer && oldcontainer==stdout) return; // do not resend same containers + if (oldcontainer!=stdout) broadcast("containers", stdout); oldcontainer = stdout; - broadcast("containers", stdout); } function containerlist(error, stdout, stderr) { @@ -45,7 +44,8 @@ module.exports = function(io, authentication) { return fail("list docker containers failed", { error: error, stderr: stderr, stdout: stdout }); - exec("docker inspect "+stdout.trim().replace(/\n/g, " "), containerinspect); + var containers = stdout.trim().replace(/\n/g, " "); + exec("docker inspect "+containers, containerinspect); } function updatecontainers(error, stdout, stderr) { @@ -227,57 +227,13 @@ module.exports = function(io, authentication) { .on('bash-end', bash_end); } - - function stats() { - var res = {}; - var fs = require('fs'); - var async = require('async'); - var base = "/sys/fs/cgroup/"; - var dataPoints = { - "cpuacct": [ - "usage" - ], - "memory": [ - "usage_in_bytes", - "limit_in_bytes", - "max_usage_in_bytes" - ] - }; - async.forEachOf(idtoname, function(name, id, cb1) { - res[name] = {}; - async.forEachOf(dataPoints, function(val1, category, cb2) { - res[name][category] = {}; - async.each(val1, function(element, cb3) { - var file = base + category + '/docker/' + id + '/' + category + '.' + element; - fs.readFile(file, 'utf8', function(err, data) { - res[name][category][element] = { - date: (new Date()).getTime(), - data: {} - }; - if (err) {cb3(); console.log(err); return} - data.trim().split('\n').forEach(function(v, i) { - var vals = v.split(' '); - switch (vals.length) { - case 1: - res[name][category][element].data = parseInt(vals[0]); - break; - case 2: - res[name][category][element].data[vals[0]] = parseInt(vals[1]); - break; - } - }); - cb3(); - }); - }, function(err) { - cb2(); - }); - }, function(err) { - cb1(); + + function stats(error, stdout, stderr) { + if (error || stderr) + return fail("get containers stats failed", { + error: error, stderr: stderr, stdout: stdout }); - }, function(err) { - if (err) return; - broadcast("stats", res); - }); + broadcast("stats", stdout); } // Handle Connection @@ -295,16 +251,16 @@ module.exports = function(io, authentication) { timeout: "none" }); - // Regular Update of Stats - setInterval(function() { - stats(); - }, 1000); - // Regular Update of Images and Containers setInterval(function() { updateimages(); updatecontainers(); }, 10000); + + // Regular Update of Stats + setInterval(function() { + exec('docker stats --no-stream'+running, stats); + }, 1000); return module; }