@depup/systeminformation 5.31.4-depup.0 → 5.33.1-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/changes.json +1 -1
- package/lib/audio.js +6 -5
- package/lib/battery.js +6 -2
- package/lib/bluetooth.js +6 -2
- package/lib/cpu.js +108 -60
- package/lib/docker.js +50 -62
- package/lib/dockerSocket.js +56 -261
- package/lib/filesystem.js +114 -27
- package/lib/graphics.js +175 -89
- package/lib/index.d.ts +6 -8
- package/lib/index.js +4 -2
- package/lib/memory.js +14 -5
- package/lib/network.js +60 -74
- package/lib/osinfo.js +27 -9
- package/lib/printer.js +5 -5
- package/lib/processes.js +49 -15
- package/lib/system.js +3 -4
- package/lib/usb.js +0 -4
- package/lib/util.js +79 -18
- package/lib/virtualbox.js +10 -4
- package/lib/wifi.js +40 -44
- package/package.json +12 -9
package/lib/docker.js
CHANGED
|
@@ -19,9 +19,8 @@ const DockerSocket = require('./dockerSocket');
|
|
|
19
19
|
const _platform = process.platform;
|
|
20
20
|
const _windows = _platform === 'win32';
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const _docker_cpu_last_read = {};
|
|
23
23
|
let _docker_socket;
|
|
24
|
-
let _docker_last_read = 0;
|
|
25
24
|
|
|
26
25
|
// --------------------------
|
|
27
26
|
// get containers (parameter all: get also inactive/exited containers)
|
|
@@ -123,7 +122,9 @@ function dockerImages(all, callback) {
|
|
|
123
122
|
if (element.Names && Object.prototype.toString.call(element.Names) === '[object Array]' && element.Names.length > 0) {
|
|
124
123
|
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
|
|
125
124
|
}
|
|
126
|
-
|
|
125
|
+
if (element.Id && typeof element.Id === 'string') {
|
|
126
|
+
workload.push(dockerImagesInspect(element.Id.trim(), element));
|
|
127
|
+
}
|
|
127
128
|
});
|
|
128
129
|
if (workload.length) {
|
|
129
130
|
Promise.all(workload).then((data) => {
|
|
@@ -165,13 +166,13 @@ function dockerImagesInspect(imageID, payload) {
|
|
|
165
166
|
if (typeof imageID !== 'string') {
|
|
166
167
|
return resolve();
|
|
167
168
|
}
|
|
168
|
-
const imageIDSanitized =
|
|
169
|
+
const imageIDSanitized = util.isPrototypePolluted() ? '' : util.sanitizeImageID(imageID);
|
|
169
170
|
if (imageIDSanitized) {
|
|
170
171
|
if (!_docker_socket) {
|
|
171
172
|
_docker_socket = new DockerSocket();
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
_docker_socket.inspectImage(imageIDSanitized
|
|
175
|
+
_docker_socket.inspectImage(imageIDSanitized, (data) => {
|
|
175
176
|
try {
|
|
176
177
|
resolve({
|
|
177
178
|
id: payload.Id,
|
|
@@ -188,8 +189,8 @@ function dockerImagesInspect(imageID, payload) {
|
|
|
188
189
|
created: data.Created ? Math.round(new Date(data.Created).getTime() / 1000) : 0,
|
|
189
190
|
containerConfig: data.ContainerConfig ? data.ContainerConfig : {},
|
|
190
191
|
graphDriver: data.GraphDriver ? data.GraphDriver : {},
|
|
191
|
-
repoDigests: data.RepoDigests ? data.RepoDigests :
|
|
192
|
-
repoTags: data.RepoTags ? data.RepoTags :
|
|
192
|
+
repoDigests: data.RepoDigests ? data.RepoDigests : [],
|
|
193
|
+
repoTags: data.RepoTags ? data.RepoTags : [],
|
|
193
194
|
config: data.Config ? data.Config : {},
|
|
194
195
|
rootFS: data.RootFS ? data.RootFS : {}
|
|
195
196
|
});
|
|
@@ -208,14 +209,7 @@ exports.dockerImages = dockerImages;
|
|
|
208
209
|
|
|
209
210
|
function dockerContainers(all, callback) {
|
|
210
211
|
function inContainers(containers, id) {
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* @namespace
|
|
214
|
-
* @property {string} Id
|
|
215
|
-
*/
|
|
216
|
-
return obj.Id && obj.Id === id;
|
|
217
|
-
});
|
|
218
|
-
return filtered.length > 0;
|
|
212
|
+
return containers.some((obj) => obj.Id && obj.Id.indexOf(id) === 0);
|
|
219
213
|
}
|
|
220
214
|
|
|
221
215
|
// fallback - if only callback is given
|
|
@@ -244,11 +238,11 @@ function dockerContainers(all, callback) {
|
|
|
244
238
|
try {
|
|
245
239
|
docker_containers = data;
|
|
246
240
|
if (docker_containers && Object.prototype.toString.call(docker_containers) === '[object Array]' && docker_containers.length > 0) {
|
|
247
|
-
// GC in
|
|
248
|
-
for (let key in
|
|
249
|
-
if ({}.hasOwnProperty.call(
|
|
241
|
+
// GC in _docker_cpu_last_read
|
|
242
|
+
for (let key in _docker_cpu_last_read) {
|
|
243
|
+
if ({}.hasOwnProperty.call(_docker_cpu_last_read, key)) {
|
|
250
244
|
if (!inContainers(docker_containers, key)) {
|
|
251
|
-
delete
|
|
245
|
+
delete _docker_cpu_last_read[key];
|
|
252
246
|
}
|
|
253
247
|
}
|
|
254
248
|
}
|
|
@@ -257,7 +251,9 @@ function dockerContainers(all, callback) {
|
|
|
257
251
|
if (element.Names && Object.prototype.toString.call(element.Names) === '[object Array]' && element.Names.length > 0) {
|
|
258
252
|
element.Name = element.Names[0].replace(/^\/|\/$/g, '');
|
|
259
253
|
}
|
|
260
|
-
|
|
254
|
+
if (element.Id && typeof element.Id === 'string') {
|
|
255
|
+
workload.push(dockerContainerInspect(element.Id.trim(), element));
|
|
256
|
+
}
|
|
261
257
|
});
|
|
262
258
|
if (workload.length) {
|
|
263
259
|
Promise.all(workload).then((data) => {
|
|
@@ -279,14 +275,6 @@ function dockerContainers(all, callback) {
|
|
|
279
275
|
resolve(result);
|
|
280
276
|
}
|
|
281
277
|
} catch (err) {
|
|
282
|
-
// GC in _docker_container_stats
|
|
283
|
-
for (let key in _docker_container_stats) {
|
|
284
|
-
if ({}.hasOwnProperty.call(_docker_container_stats, key)) {
|
|
285
|
-
if (!inContainers(docker_containers, key)) {
|
|
286
|
-
delete _docker_container_stats[key];
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
278
|
if (callback) {
|
|
291
279
|
callback(result);
|
|
292
280
|
}
|
|
@@ -307,13 +295,13 @@ function dockerContainerInspect(containerID, payload) {
|
|
|
307
295
|
if (typeof containerID !== 'string') {
|
|
308
296
|
return resolve();
|
|
309
297
|
}
|
|
310
|
-
const containerIdSanitized =
|
|
298
|
+
const containerIdSanitized = util.isPrototypePolluted() ? '' : util.sanitizeContainerID(containerID);
|
|
311
299
|
if (containerIdSanitized) {
|
|
312
300
|
if (!_docker_socket) {
|
|
313
301
|
_docker_socket = new DockerSocket();
|
|
314
302
|
}
|
|
315
303
|
|
|
316
|
-
_docker_socket.getInspect(containerIdSanitized
|
|
304
|
+
_docker_socket.getInspect(containerIdSanitized, (data) => {
|
|
317
305
|
try {
|
|
318
306
|
resolve({
|
|
319
307
|
id: payload.Id,
|
|
@@ -327,10 +315,12 @@ function dockerContainerInspect(containerID, payload) {
|
|
|
327
315
|
createdAt: data.Created ? data.Created : '',
|
|
328
316
|
startedAt: data.State && data.State.StartedAt ? data.State.StartedAt : '',
|
|
329
317
|
finishedAt: data.State && data.State.FinishedAt && !data.State.FinishedAt.startsWith('0001-01-01') ? data.State.FinishedAt : '',
|
|
318
|
+
status: data.State && data.State.Health && data.State.Health.Status ? data.State.Health.Status : '',
|
|
330
319
|
state: payload.State,
|
|
331
320
|
restartCount: data.RestartCount || 0,
|
|
332
321
|
platform: data.Platform || '',
|
|
333
322
|
driver: data.Driver || '',
|
|
323
|
+
labels: data.Config && data.Config.Labels ? data.Config.Labels : {},
|
|
334
324
|
ports: payload.Ports,
|
|
335
325
|
mounts: payload.Mounts
|
|
336
326
|
// hostconfig: payload.HostConfig,
|
|
@@ -352,7 +342,7 @@ exports.dockerContainers = dockerContainers;
|
|
|
352
342
|
// --------------------------
|
|
353
343
|
// helper functions for calculation of docker stats
|
|
354
344
|
|
|
355
|
-
function docker_calcCPUPercent(cpu_stats, precpu_stats) {
|
|
345
|
+
function docker_calcCPUPercent(cpu_stats, precpu_stats, id) {
|
|
356
346
|
/**
|
|
357
347
|
* @namespace
|
|
358
348
|
* @property {object} cpu_usage
|
|
@@ -361,42 +351,47 @@ function docker_calcCPUPercent(cpu_stats, precpu_stats) {
|
|
|
361
351
|
* @property {object} cpu_usage
|
|
362
352
|
* @property {Array} cpu_usage.percpu_usage
|
|
363
353
|
*/
|
|
354
|
+
if (!cpu_stats || !cpu_stats.cpu_usage || !precpu_stats) {
|
|
355
|
+
return 0;
|
|
356
|
+
}
|
|
357
|
+
const precpuTotal = precpu_stats.cpu_usage && precpu_stats.cpu_usage.total_usage ? precpu_stats.cpu_usage.total_usage : 0;
|
|
364
358
|
|
|
365
359
|
if (!_windows) {
|
|
366
360
|
let cpuPercent = 0.0;
|
|
367
361
|
// calculate the change for the cpu usage of the container in between readings
|
|
368
|
-
|
|
362
|
+
const cpuDelta = cpu_stats.cpu_usage.total_usage - precpuTotal;
|
|
369
363
|
// calculate the change for the entire system between readings
|
|
370
|
-
|
|
364
|
+
const systemDelta = cpu_stats.system_cpu_usage - (precpu_stats.system_cpu_usage || 0);
|
|
371
365
|
|
|
372
366
|
if (systemDelta > 0.0 && cpuDelta > 0.0) {
|
|
373
367
|
// calculate the change for the cpu usage of the container in between readings
|
|
374
368
|
if (precpu_stats.online_cpus) {
|
|
375
369
|
cpuPercent = (cpuDelta / systemDelta) * precpu_stats.online_cpus * 100.0;
|
|
376
|
-
} else {
|
|
370
|
+
} else if (cpu_stats.cpu_usage.percpu_usage && cpu_stats.cpu_usage.percpu_usage.length) {
|
|
377
371
|
cpuPercent = (cpuDelta / systemDelta) * cpu_stats.cpu_usage.percpu_usage.length * 100.0;
|
|
378
372
|
}
|
|
379
373
|
}
|
|
380
374
|
|
|
381
375
|
return cpuPercent;
|
|
382
376
|
} else {
|
|
383
|
-
|
|
377
|
+
const nanoSecNow = util.nanoSeconds();
|
|
384
378
|
let cpuPercent = 0.0;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
379
|
+
const lastRead = _docker_cpu_last_read[id] || 0;
|
|
380
|
+
if (lastRead > 0) {
|
|
381
|
+
const possIntervals = nanoSecNow - lastRead;
|
|
382
|
+
const intervalsUsed = cpu_stats.cpu_usage.total_usage - precpuTotal;
|
|
388
383
|
if (possIntervals > 0) {
|
|
389
384
|
cpuPercent = (100.0 * intervalsUsed) / possIntervals;
|
|
390
385
|
}
|
|
391
386
|
}
|
|
392
|
-
|
|
387
|
+
_docker_cpu_last_read[id] = nanoSecNow;
|
|
393
388
|
return cpuPercent;
|
|
394
389
|
}
|
|
395
390
|
}
|
|
396
391
|
|
|
397
392
|
function docker_calcNetworkIO(networks) {
|
|
398
|
-
let rx;
|
|
399
|
-
let wx;
|
|
393
|
+
let rx = 0;
|
|
394
|
+
let wx = 0;
|
|
400
395
|
for (let key in networks) {
|
|
401
396
|
// skip loop if the property is from prototype
|
|
402
397
|
if (!{}.hasOwnProperty.call(networks, key)) {
|
|
@@ -481,25 +476,16 @@ function dockerContainerStats(containerIDs, callback) {
|
|
|
481
476
|
Object.setPrototypeOf(containerIDsSanitized, util.stringObj);
|
|
482
477
|
}
|
|
483
478
|
|
|
484
|
-
containerIDsSanitized = containerIDs;
|
|
485
|
-
containerIDsSanitized = containerIDsSanitized.trim();
|
|
479
|
+
containerIDsSanitized = containerIDs.trim();
|
|
486
480
|
if (containerIDsSanitized !== '*') {
|
|
487
|
-
containerIDsSanitized = '';
|
|
488
|
-
const s = (util.isPrototypePolluted() ? '' : util.sanitizeShellString(containerIDs, true)).trim();
|
|
489
|
-
const l = util.mathMin(s.length, 2000);
|
|
490
|
-
for (let i = 0; i <= l; i++) {
|
|
491
|
-
if (s[i] !== undefined) {
|
|
492
|
-
s[i].__proto__.toLowerCase = util.stringToLower;
|
|
493
|
-
const sl = s[i].toLowerCase();
|
|
494
|
-
if (sl && sl[0] && !sl[1]) {
|
|
495
|
-
containerIDsSanitized = containerIDsSanitized + sl[0];
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
481
|
+
containerIDsSanitized = util.isPrototypePolluted() ? '' : util.sanitizeContainerID(containerIDs);
|
|
499
482
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
483
|
+
containerArray = containerIDsSanitized
|
|
484
|
+
.trim()
|
|
485
|
+
.toLowerCase()
|
|
486
|
+
.replace(/,+/g, '|')
|
|
487
|
+
.split('|')
|
|
488
|
+
.filter((item) => item.trim());
|
|
503
489
|
}
|
|
504
490
|
|
|
505
491
|
const result = [];
|
|
@@ -508,8 +494,10 @@ function dockerContainerStats(containerIDs, callback) {
|
|
|
508
494
|
if (containerArray.length && containerArray[0].trim() === '*') {
|
|
509
495
|
containerArray = [];
|
|
510
496
|
dockerContainers().then((allContainers) => {
|
|
511
|
-
for (let container of allContainers) {
|
|
512
|
-
|
|
497
|
+
for (let container of (allContainers || []).filter(Boolean)) {
|
|
498
|
+
if (container.id) {
|
|
499
|
+
containerArray.push(container.id.substring(0, 12));
|
|
500
|
+
}
|
|
513
501
|
}
|
|
514
502
|
if (containerArray.length) {
|
|
515
503
|
dockerContainerStats(containerArray.join(',')).then((result) => {
|
|
@@ -592,7 +580,7 @@ function dockerContainerStatsSingle(containerID) {
|
|
|
592
580
|
result.memUsage = stats.memory_stats && stats.memory_stats.usage ? stats.memory_stats.usage : 0;
|
|
593
581
|
result.memLimit = stats.memory_stats && stats.memory_stats.limit ? stats.memory_stats.limit : 0;
|
|
594
582
|
result.memPercent = stats.memory_stats && stats.memory_stats.usage && stats.memory_stats.limit ? (stats.memory_stats.usage / stats.memory_stats.limit) * 100.0 : 0;
|
|
595
|
-
result.cpuPercent = stats.cpu_stats && stats.precpu_stats ? docker_calcCPUPercent(stats.cpu_stats, stats.precpu_stats) : 0;
|
|
583
|
+
result.cpuPercent = stats.cpu_stats && stats.precpu_stats ? docker_calcCPUPercent(stats.cpu_stats, stats.precpu_stats, containerID) : 0;
|
|
596
584
|
result.pids = stats.pids_stats && stats.pids_stats.current ? stats.pids_stats.current : 0;
|
|
597
585
|
result.restartCount = dataInspect.RestartCount ? dataInspect.RestartCount : 0;
|
|
598
586
|
if (stats.networks) {
|
|
@@ -636,7 +624,7 @@ function dockerContainerProcesses(containerID, callback) {
|
|
|
636
624
|
if (typeof containerID !== 'string') {
|
|
637
625
|
return resolve(result);
|
|
638
626
|
}
|
|
639
|
-
const containerIdSanitized =
|
|
627
|
+
const containerIdSanitized = util.isPrototypePolluted() ? '' : util.sanitizeContainerID(containerID);
|
|
640
628
|
|
|
641
629
|
if (containerIdSanitized) {
|
|
642
630
|
if (!_docker_socket) {
|
package/lib/dockerSocket.js
CHANGED
|
@@ -15,307 +15,102 @@
|
|
|
15
15
|
|
|
16
16
|
const net = require('net');
|
|
17
17
|
const isWin = require('os').type() === 'Windows_NT';
|
|
18
|
-
const socketPath = isWin ? '//./pipe/docker_engine' : '/var/run/docker.sock';
|
|
18
|
+
const socketPath = process.env.DOCKER_SOCKET || (isWin ? '//./pipe/docker_engine' : '/var/run/docker.sock');
|
|
19
|
+
const socketTimeout = +process.env.DOCKER_SOCKET_TIMEOUT || 30000;
|
|
20
|
+
|
|
21
|
+
function fetchJson(path, callback) {
|
|
22
|
+
let done = false;
|
|
23
|
+
const finish = (result) => {
|
|
24
|
+
if (!done) {
|
|
25
|
+
done = true;
|
|
26
|
+
callback(result);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
const socket = net.createConnection({ path: socketPath });
|
|
31
|
+
let alldata = '';
|
|
32
|
+
|
|
33
|
+
socket.setTimeout(socketTimeout, () => {
|
|
34
|
+
socket.destroy();
|
|
35
|
+
finish({});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
socket.on('connect', () => {
|
|
39
|
+
socket.write(`GET ${path} HTTP/1.0\r\n\r\n`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
socket.on('data', (data) => {
|
|
43
|
+
alldata = alldata + data.toString();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
socket.on('error', () => {
|
|
47
|
+
finish({});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
socket.on('end', () => {
|
|
51
|
+
const startbody = alldata.indexOf('\r\n\r\n');
|
|
52
|
+
const status = parseInt(alldata.split(' ')[1], 10);
|
|
53
|
+
if (startbody < 0 || isNaN(status) || status < 200 || status >= 300) {
|
|
54
|
+
return finish({});
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
finish(JSON.parse(alldata.substring(startbody + 4)));
|
|
58
|
+
} catch {
|
|
59
|
+
finish({});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} catch {
|
|
63
|
+
finish({});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
19
66
|
|
|
20
67
|
class DockerSocket {
|
|
21
68
|
getInfo(callback) {
|
|
22
|
-
|
|
23
|
-
let socket = net.createConnection({ path: socketPath });
|
|
24
|
-
let alldata = '';
|
|
25
|
-
let data;
|
|
26
|
-
|
|
27
|
-
socket.on('connect', () => {
|
|
28
|
-
socket.write('GET http:/info HTTP/1.0\r\n\r\n');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
socket.on('data', (data) => {
|
|
32
|
-
alldata = alldata + data.toString();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
socket.on('error', () => {
|
|
36
|
-
socket = false;
|
|
37
|
-
callback({});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
socket.on('end', () => {
|
|
41
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
42
|
-
alldata = alldata.substring(startbody + 4);
|
|
43
|
-
socket = false;
|
|
44
|
-
try {
|
|
45
|
-
data = JSON.parse(alldata);
|
|
46
|
-
callback(data);
|
|
47
|
-
} catch {
|
|
48
|
-
callback({});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
} catch {
|
|
52
|
-
callback({});
|
|
53
|
-
}
|
|
69
|
+
fetchJson('http:/info', callback);
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
listImages(all, callback) {
|
|
57
|
-
|
|
58
|
-
let socket = net.createConnection({ path: socketPath });
|
|
59
|
-
let alldata = '';
|
|
60
|
-
let data;
|
|
61
|
-
|
|
62
|
-
socket.on('connect', () => {
|
|
63
|
-
socket.write('GET http:/images/json' + (all ? '?all=1' : '') + ' HTTP/1.0\r\n\r\n');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
socket.on('data', (data) => {
|
|
67
|
-
alldata = alldata + data.toString();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
socket.on('error', () => {
|
|
71
|
-
socket = false;
|
|
72
|
-
callback({});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
socket.on('end', () => {
|
|
76
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
77
|
-
alldata = alldata.substring(startbody + 4);
|
|
78
|
-
socket = false;
|
|
79
|
-
try {
|
|
80
|
-
data = JSON.parse(alldata);
|
|
81
|
-
callback(data);
|
|
82
|
-
} catch {
|
|
83
|
-
callback({});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
} catch {
|
|
87
|
-
callback({});
|
|
88
|
-
}
|
|
73
|
+
fetchJson(`http:/images/json${all ? '?all=1' : ''}`, callback);
|
|
89
74
|
}
|
|
90
75
|
|
|
91
76
|
inspectImage(id, callback) {
|
|
92
|
-
id = id || '';
|
|
93
77
|
if (id) {
|
|
94
|
-
|
|
95
|
-
let socket = net.createConnection({ path: socketPath });
|
|
96
|
-
let alldata = '';
|
|
97
|
-
let data;
|
|
98
|
-
|
|
99
|
-
socket.on('connect', () => {
|
|
100
|
-
socket.write('GET http:/images/' + id + '/json?stream=0 HTTP/1.0\r\n\r\n');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
socket.on('data', (data) => {
|
|
104
|
-
alldata = alldata + data.toString();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
socket.on('error', () => {
|
|
108
|
-
socket = false;
|
|
109
|
-
callback({});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
socket.on('end', () => {
|
|
113
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
114
|
-
alldata = alldata.substring(startbody + 4);
|
|
115
|
-
socket = false;
|
|
116
|
-
try {
|
|
117
|
-
data = JSON.parse(alldata);
|
|
118
|
-
callback(data);
|
|
119
|
-
} catch {
|
|
120
|
-
callback({});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
} catch {
|
|
124
|
-
callback({});
|
|
125
|
-
}
|
|
78
|
+
fetchJson(`http:/images/${id}/json?stream=0`, callback);
|
|
126
79
|
} else {
|
|
127
80
|
callback({});
|
|
128
81
|
}
|
|
129
82
|
}
|
|
130
83
|
|
|
131
84
|
listContainers(all, callback) {
|
|
132
|
-
|
|
133
|
-
let socket = net.createConnection({ path: socketPath });
|
|
134
|
-
let alldata = '';
|
|
135
|
-
let data;
|
|
136
|
-
|
|
137
|
-
socket.on('connect', () => {
|
|
138
|
-
socket.write('GET http:/containers/json' + (all ? '?all=1' : '') + ' HTTP/1.0\r\n\r\n');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
socket.on('data', (data) => {
|
|
142
|
-
alldata = alldata + data.toString();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
socket.on('error', () => {
|
|
146
|
-
socket = false;
|
|
147
|
-
callback({});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
socket.on('end', () => {
|
|
151
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
152
|
-
alldata = alldata.substring(startbody + 4);
|
|
153
|
-
socket = false;
|
|
154
|
-
try {
|
|
155
|
-
data = JSON.parse(alldata);
|
|
156
|
-
callback(data);
|
|
157
|
-
} catch {
|
|
158
|
-
callback({});
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
} catch {
|
|
162
|
-
callback({});
|
|
163
|
-
}
|
|
85
|
+
fetchJson(`http:/containers/json${all ? '?all=1' : ''}`, callback);
|
|
164
86
|
}
|
|
165
87
|
|
|
166
88
|
getStats(id, callback) {
|
|
167
|
-
id = id || '';
|
|
168
89
|
if (id) {
|
|
169
|
-
|
|
170
|
-
let socket = net.createConnection({ path: socketPath });
|
|
171
|
-
let alldata = '';
|
|
172
|
-
let data;
|
|
173
|
-
|
|
174
|
-
socket.on('connect', () => {
|
|
175
|
-
socket.write('GET http:/containers/' + id + '/stats?stream=0 HTTP/1.0\r\n\r\n');
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
socket.on('data', (data) => {
|
|
179
|
-
alldata = alldata + data.toString();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
socket.on('error', () => {
|
|
183
|
-
socket = false;
|
|
184
|
-
callback({});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
socket.on('end', () => {
|
|
188
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
189
|
-
alldata = alldata.substring(startbody + 4);
|
|
190
|
-
socket = false;
|
|
191
|
-
try {
|
|
192
|
-
data = JSON.parse(alldata);
|
|
193
|
-
callback(data);
|
|
194
|
-
} catch {
|
|
195
|
-
callback({});
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
} catch {
|
|
199
|
-
callback({});
|
|
200
|
-
}
|
|
90
|
+
fetchJson(`http:/containers/${id}/stats?stream=0`, callback);
|
|
201
91
|
} else {
|
|
202
92
|
callback({});
|
|
203
93
|
}
|
|
204
94
|
}
|
|
205
95
|
|
|
206
96
|
getInspect(id, callback) {
|
|
207
|
-
id = id || '';
|
|
208
97
|
if (id) {
|
|
209
|
-
|
|
210
|
-
let socket = net.createConnection({ path: socketPath });
|
|
211
|
-
let alldata = '';
|
|
212
|
-
let data;
|
|
213
|
-
|
|
214
|
-
socket.on('connect', () => {
|
|
215
|
-
socket.write('GET http:/containers/' + id + '/json?stream=0 HTTP/1.0\r\n\r\n');
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
socket.on('data', (data) => {
|
|
219
|
-
alldata = alldata + data.toString();
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
socket.on('error', () => {
|
|
223
|
-
socket = false;
|
|
224
|
-
callback({});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
socket.on('end', () => {
|
|
228
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
229
|
-
alldata = alldata.substring(startbody + 4);
|
|
230
|
-
socket = false;
|
|
231
|
-
try {
|
|
232
|
-
data = JSON.parse(alldata);
|
|
233
|
-
callback(data);
|
|
234
|
-
} catch {
|
|
235
|
-
callback({});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
} catch {
|
|
239
|
-
callback({});
|
|
240
|
-
}
|
|
98
|
+
fetchJson(`http:/containers/${id}/json?stream=0`, callback);
|
|
241
99
|
} else {
|
|
242
100
|
callback({});
|
|
243
101
|
}
|
|
244
102
|
}
|
|
245
103
|
|
|
246
104
|
getProcesses(id, callback) {
|
|
247
|
-
id = id || '';
|
|
248
105
|
if (id) {
|
|
249
|
-
|
|
250
|
-
let socket = net.createConnection({ path: socketPath });
|
|
251
|
-
let alldata = '';
|
|
252
|
-
let data;
|
|
253
|
-
|
|
254
|
-
socket.on('connect', () => {
|
|
255
|
-
socket.write('GET http:/containers/' + id + '/top?ps_args=-opid,ppid,pgid,vsz,time,etime,nice,ruser,user,rgroup,group,stat,rss,args HTTP/1.0\r\n\r\n');
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
socket.on('data', (data) => {
|
|
259
|
-
alldata = alldata + data.toString();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
socket.on('error', () => {
|
|
263
|
-
socket = false;
|
|
264
|
-
callback({});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
socket.on('end', () => {
|
|
268
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
269
|
-
alldata = alldata.substring(startbody + 4);
|
|
270
|
-
socket = false;
|
|
271
|
-
try {
|
|
272
|
-
data = JSON.parse(alldata);
|
|
273
|
-
callback(data);
|
|
274
|
-
} catch {
|
|
275
|
-
callback({});
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
} catch {
|
|
279
|
-
callback({});
|
|
280
|
-
}
|
|
106
|
+
fetchJson(`http:/containers/${id}/top?ps_args=-opid,ppid,pgid,vsz,time,etime,nice,ruser,user,rgroup,group,stat,rss,args`, callback);
|
|
281
107
|
} else {
|
|
282
108
|
callback({});
|
|
283
109
|
}
|
|
284
110
|
}
|
|
285
111
|
|
|
286
112
|
listVolumes(callback) {
|
|
287
|
-
|
|
288
|
-
let socket = net.createConnection({ path: socketPath });
|
|
289
|
-
let alldata = '';
|
|
290
|
-
let data;
|
|
291
|
-
|
|
292
|
-
socket.on('connect', () => {
|
|
293
|
-
socket.write('GET http:/volumes HTTP/1.0\r\n\r\n');
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
socket.on('data', (data) => {
|
|
297
|
-
alldata = alldata + data.toString();
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
socket.on('error', () => {
|
|
301
|
-
socket = false;
|
|
302
|
-
callback({});
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
socket.on('end', () => {
|
|
306
|
-
const startbody = alldata.indexOf('\r\n\r\n');
|
|
307
|
-
alldata = alldata.substring(startbody + 4);
|
|
308
|
-
socket = false;
|
|
309
|
-
try {
|
|
310
|
-
data = JSON.parse(alldata);
|
|
311
|
-
callback(data);
|
|
312
|
-
} catch {
|
|
313
|
-
callback({});
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
} catch {
|
|
317
|
-
callback({});
|
|
318
|
-
}
|
|
113
|
+
fetchJson('http:/volumes', callback);
|
|
319
114
|
}
|
|
320
115
|
}
|
|
321
116
|
|