node-lxc 1.0.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/LICENSE +201 -0
- package/README.md +328 -0
- package/bin/x86_64-linux-gnu/node-lxc.node +0 -0
- package/examples/attach/index.ts +29 -0
- package/examples/attach-streams/index.ts +34 -0
- package/examples/checkpoint/index.ts +34 -0
- package/examples/clone/index.ts +34 -0
- package/examples/concurrent_create/index.ts +30 -0
- package/examples/concurrent_destroy/index.ts +23 -0
- package/examples/concurrent_shutdown/index.ts +28 -0
- package/examples/concurrent_start/index.ts +28 -0
- package/examples/concurrent_stop/index.ts +28 -0
- package/examples/config/index.ts +18 -0
- package/examples/console/index.ts +17 -0
- package/examples/console_async/index.ts +101 -0
- package/examples/create/index.ts +12 -0
- package/examples/create_snapshot/index.ts +10 -0
- package/examples/destroy/index.ts +10 -0
- package/examples/destroy_snapshots/index.ts +10 -0
- package/examples/device_add_remove/index.ts +11 -0
- package/examples/execute/index.ts +10 -0
- package/examples/freeze/index.ts +11 -0
- package/examples/images/index.ts +10 -0
- package/examples/interfaces/index.ts +10 -0
- package/examples/ipaddress/index.ts +12 -0
- package/examples/limit/index.ts +15 -0
- package/examples/list/index.ts +12 -0
- package/examples/list_keys/index.ts +10 -0
- package/examples/list_snapshots/index.ts +9 -0
- package/examples/reboot/index.ts +11 -0
- package/examples/rename/index.ts +11 -0
- package/examples/restore_snapshot/index.ts +11 -0
- package/examples/shutdown/index.ts +19 -0
- package/examples/start/index.ts +11 -0
- package/examples/stats/index.ts +48 -0
- package/examples/stop/index.ts +11 -0
- package/examples/unfreeze/index.ts +11 -0
- package/lib/binding.d.ts +6 -0
- package/lib/binding.js +32 -0
- package/lib/binding.js.map +1 -0
- package/lib/index.d.ts +612 -0
- package/lib/index.js +73 -0
- package/lib/index.js.map +1 -0
- package/lib/types/Image.d.ts +22 -0
- package/lib/types/Image.js +3 -0
- package/lib/types/Image.js.map +1 -0
- package/lib/types/LXC_ATTACH.d.ts +67 -0
- package/lib/types/LXC_ATTACH.js +72 -0
- package/lib/types/LXC_ATTACH.js.map +1 -0
- package/lib/types/LXC_CLONE.d.ts +34 -0
- package/lib/types/LXC_CLONE.js +39 -0
- package/lib/types/LXC_CLONE.js.map +1 -0
- package/lib/types/LXC_CREATE.d.ts +8 -0
- package/lib/types/LXC_CREATE.js +13 -0
- package/lib/types/LXC_CREATE.js.map +1 -0
- package/lib/types/LXC_LOGLEVEL.d.ts +15 -0
- package/lib/types/LXC_LOGLEVEL.js +20 -0
- package/lib/types/LXC_LOGLEVEL.js.map +1 -0
- package/lib/types/LXC_MIGRATE.d.ts +10 -0
- package/lib/types/LXC_MIGRATE.js +15 -0
- package/lib/types/LXC_MIGRATE.js.map +1 -0
- package/lib/types/LXC_MOUNT.d.ts +42 -0
- package/lib/types/LXC_MOUNT.js +45 -0
- package/lib/types/LXC_MOUNT.js.map +1 -0
- package/lib/types/Personality.d.ts +14 -0
- package/lib/types/Personality.js +19 -0
- package/lib/types/Personality.js.map +1 -0
- package/lib/types/bdev_specs.d.ts +48 -0
- package/lib/types/bdev_specs.js +3 -0
- package/lib/types/bdev_specs.js.map +1 -0
- package/lib/types/custom/ConsoleSession.d.ts +23 -0
- package/lib/types/custom/ConsoleSession.js +3 -0
- package/lib/types/custom/ConsoleSession.js.map +1 -0
- package/lib/types/custom/index.d.ts +1 -0
- package/lib/types/custom/index.js +18 -0
- package/lib/types/custom/index.js.map +1 -0
- package/lib/types/index.d.ts +20 -0
- package/lib/types/index.js +37 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/lxc_attach_env_policy.d.ts +8 -0
- package/lib/types/lxc_attach_env_policy.js +13 -0
- package/lib/types/lxc_attach_env_policy.js.map +1 -0
- package/lib/types/lxc_attach_options.d.ts +99 -0
- package/lib/types/lxc_attach_options.js +30 -0
- package/lib/types/lxc_attach_options.js.map +1 -0
- package/lib/types/lxc_clone_options.d.ts +52 -0
- package/lib/types/lxc_clone_options.js +7 -0
- package/lib/types/lxc_clone_options.js.map +1 -0
- package/lib/types/lxc_console_log.d.ts +10 -0
- package/lib/types/lxc_console_log.js +7 -0
- package/lib/types/lxc_console_log.js.map +1 -0
- package/lib/types/lxc_snapshot.d.ts +10 -0
- package/lib/types/lxc_snapshot.js +7 -0
- package/lib/types/lxc_snapshot.js.map +1 -0
- package/lib/types/migrate_opts.d.ts +17 -0
- package/lib/types/migrate_opts.js +7 -0
- package/lib/types/migrate_opts.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "test-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
|
|
10
|
+
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
+
const c = new Container(name + i);
|
|
12
|
+
if(!c.defined) {
|
|
13
|
+
await c.create({
|
|
14
|
+
template: "download", argv: ["--dist", "ubuntu", "--release", "lunar", "--arch", "amd64"]
|
|
15
|
+
});
|
|
16
|
+
console.log(`Created ${c.name}`);
|
|
17
|
+
}else{
|
|
18
|
+
console.warn(`Container ${c.name} already defined`);
|
|
19
|
+
}
|
|
20
|
+
return c;
|
|
21
|
+
}
|
|
22
|
+
));
|
|
23
|
+
|
|
24
|
+
console.table(containers.map((c) => {
|
|
25
|
+
return {name: c.name, state: c.state}
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "test-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
|
|
10
|
+
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
+
let c = new Container(name + i);
|
|
12
|
+
if (c.defined) {
|
|
13
|
+
console.log(`Destroying ${c.name}`);
|
|
14
|
+
await c.destroy();
|
|
15
|
+
} else {
|
|
16
|
+
console.warn(`Container ${c.name} not defined`);
|
|
17
|
+
}
|
|
18
|
+
return c;
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "test-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
|
|
10
|
+
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
+
let c = new Container(name + i);
|
|
12
|
+
if (c.defined) {
|
|
13
|
+
console.log(`Shutting down ${c.name}`);
|
|
14
|
+
await c.shutdown();
|
|
15
|
+
} else {
|
|
16
|
+
console.warn(`Container ${c.name} not defined`);
|
|
17
|
+
}
|
|
18
|
+
return c;
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
|
|
22
|
+
console.table(containers.map((c) => {
|
|
23
|
+
return {name: c.name, state: c.state}
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "test-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
|
|
10
|
+
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
+
const c = new Container(name + i);
|
|
12
|
+
if (!c.running) {
|
|
13
|
+
await c.start();
|
|
14
|
+
console.log(`Started ${c.name}`);
|
|
15
|
+
} else {
|
|
16
|
+
console.warn(`Container ${c.name} already running`);
|
|
17
|
+
}
|
|
18
|
+
return c;
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
|
|
22
|
+
console.table(containers.map((c) => {
|
|
23
|
+
return {name: c.name, state: c.state}
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "test-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
|
|
10
|
+
const containers = await Promise.all([...Array(10).keys()].map(async (i) => {
|
|
11
|
+
const c = new Container(name + i);
|
|
12
|
+
if (c.running) {
|
|
13
|
+
await c.stop();
|
|
14
|
+
console.log(`Stopped ${c.name}`);
|
|
15
|
+
} else {
|
|
16
|
+
console.warn(`Container ${c.name} already stopped`);
|
|
17
|
+
}
|
|
18
|
+
return c;
|
|
19
|
+
}
|
|
20
|
+
));
|
|
21
|
+
|
|
22
|
+
console.table(containers.map((c) => {
|
|
23
|
+
return {name: c.name, state: c.state}
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "test-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
|
|
10
|
+
const c = new Container(name);
|
|
11
|
+
c.setConfigItem("lxc.utsname", "test-host1");
|
|
12
|
+
|
|
13
|
+
const rootfs = c.getConfigItem("lxc.rootfs");
|
|
14
|
+
console.log("Root FS: ", rootfs);
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const name = "node-ct"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In this example, a container is created and the calling process stdio is attached.
|
|
7
|
+
*/
|
|
8
|
+
async function main() {
|
|
9
|
+
const c = new Container(name);
|
|
10
|
+
if (c.defined && c.running) {
|
|
11
|
+
await c.console(0, [process.stdin.fd, process.stdout.fd, process.stderr.fd], 1);
|
|
12
|
+
} else {
|
|
13
|
+
console.warn(`Container '${name}' not defined or not running`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
const containerName = 'node-ct'; // Change to your container name
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
const container = new Container(containerName);
|
|
7
|
+
container.setConfigItem('lxc.log.file', `./${containerName}/container.log`)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
if (!container.defined || !container.running) {
|
|
11
|
+
console.error(`Container '${containerName}' is not defined or not running.`);
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
console.log(`📎 Attaching to console of container '${containerName}' (TTY 0)`);
|
|
16
|
+
console.log(`💡 Type commands, press Ctrl+C or Ctrl+D to exit.\n`);
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
|
|
20
|
+
// console.log(container.initPIDFd())
|
|
21
|
+
|
|
22
|
+
// Open console
|
|
23
|
+
const session = await container.consoleAsync(0);
|
|
24
|
+
|
|
25
|
+
// Ensure we're in raw mode
|
|
26
|
+
if (!process.stdin.isTTY) {
|
|
27
|
+
console.error('Stdin is not a TTY');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
process.stdin.setRawMode(true);
|
|
32
|
+
process.stdin.setEncoding('utf8');
|
|
33
|
+
|
|
34
|
+
// Disable line buffering
|
|
35
|
+
process.stdin.resume();
|
|
36
|
+
|
|
37
|
+
// Handle data from container → stdout
|
|
38
|
+
session.on('data', (chunk) => {
|
|
39
|
+
process.stdout.write(chunk);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
session.on('close', () => {
|
|
43
|
+
process.exit(0);
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Handle input from user → container
|
|
47
|
+
process.stdin.on('data', (data) => {
|
|
48
|
+
if (data.toString() === '\x04') {
|
|
49
|
+
// Ctrl+D
|
|
50
|
+
session.close();
|
|
51
|
+
process.exit(0);
|
|
52
|
+
} else {
|
|
53
|
+
session.write(data);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Handle terminal resize
|
|
59
|
+
function handleResize() {
|
|
60
|
+
const cols = process.stdout.columns || 80;
|
|
61
|
+
const rows = process.stdout.rows || 24;
|
|
62
|
+
try {
|
|
63
|
+
session.resize(cols, rows);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// Ignore resize errors
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Initial resize
|
|
70
|
+
handleResize();
|
|
71
|
+
|
|
72
|
+
// Watch for resize events
|
|
73
|
+
process.stdout.on('resize', handleResize);
|
|
74
|
+
|
|
75
|
+
// Optional: send SIGWINCH on SIGHUP, SIGTERM
|
|
76
|
+
process.on('SIGINT', () => session.close());
|
|
77
|
+
process.on('SIGTERM', () => session.close());
|
|
78
|
+
|
|
79
|
+
// Cleanup on exit
|
|
80
|
+
const cleanup = () => {
|
|
81
|
+
session.close();
|
|
82
|
+
process.stdin.setRawMode(false);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
process.on('exit', cleanup);
|
|
87
|
+
process.on('SIGINT', cleanup);
|
|
88
|
+
process.on('SIGTERM', cleanup);
|
|
89
|
+
|
|
90
|
+
console.log('✅ Connected. You can now type inside the container.\n');
|
|
91
|
+
} catch (err) {
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
console.error('❌ Console error:', err?.message || err);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
main().catch(err => {
|
|
99
|
+
console.error('❌ Unexpected error:', err);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const c = new Container("node-ct");
|
|
5
|
+
if (!c.defined) {
|
|
6
|
+
console.log("Container creating...")
|
|
7
|
+
await c.create({template: "download", argv: ["--dist", "ubuntu", "--release", "jammy", "--arch", "amd64"]});
|
|
8
|
+
console.log("Done")
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
main().catch(console.error)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const c = new Container("node-ct");
|
|
5
|
+
if (c.defined && c.running) {
|
|
6
|
+
await c.addDeviceNode("/dev/network_latency");
|
|
7
|
+
await c.removeDeviceNode("/dev/network_latency");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
main().catch(console.error)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const c = new Container("node-ct");
|
|
5
|
+
if (c.defined) {
|
|
6
|
+
console.table(Promise.all((await c.getInterfaces()).map(async (inf) => {
|
|
7
|
+
return {interface: inf, ipv4: await c.getIPs(inf, "inet"), ipv6: await c.getIPs(inf, "inet6", 0)}
|
|
8
|
+
})));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
main().catch(console.error)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const c = new Container("node-ct");
|
|
5
|
+
const limitInBytes = Number(c.getCGroupItem("memory.limit_in_bytes"));
|
|
6
|
+
console.log(`current limitInBytes ${limitInBytes}`);
|
|
7
|
+
const swapMemoryLimitInBytes = Number(c.getCGroupItem("memory.memsw.limit_in_bytes"));
|
|
8
|
+
console.log(`current swapMemoryLimitInBytes ${swapMemoryLimitInBytes}`);
|
|
9
|
+
|
|
10
|
+
c.setCGroupItem("memory.limit_in_bytes", (limitInBytes/4).toString())
|
|
11
|
+
c.setCGroupItem("memory.memsw.limit_in_bytes", (swapMemoryLimitInBytes/4).toString())
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
main().catch(console.error)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {LXC} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
console.log("===== ACTIVE =====");
|
|
5
|
+
LXC.ListAllActiveContainers().forEach(console.log)
|
|
6
|
+
console.log("===== DEFINED =====");
|
|
7
|
+
LXC.ListAllDefinedContainers().forEach(console.log)
|
|
8
|
+
console.log("===== ALL =====");
|
|
9
|
+
LXC.ListAllContainers().forEach(console.log)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
main().catch(console.error)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const c = new Container("node-ct");
|
|
5
|
+
if (!c.defined) {
|
|
6
|
+
throw "Container not defined"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
console.log("Shutting down the container...\n")
|
|
10
|
+
await c.shutdown(30).then(
|
|
11
|
+
() =>
|
|
12
|
+
console.log("Container shutdown"),
|
|
13
|
+
(reason) => {
|
|
14
|
+
console.warn("Failed to shutdown container reason:", reason);
|
|
15
|
+
return c.stop();
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
main().catch(console.error)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {Container} from "../../lib";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const c = new Container("node-ct");
|
|
5
|
+
if (!c.defined) {
|
|
6
|
+
throw "Container not defined"
|
|
7
|
+
}
|
|
8
|
+
const memUsed = c.getCGroupItem("memory.usage_in_bytes");
|
|
9
|
+
console.log("MemoryUsage:", memUsed);
|
|
10
|
+
|
|
11
|
+
const memLimit = c.getConfigItem("memory.limit_in_bytes");
|
|
12
|
+
console.log("MemoryLimit:", memLimit);
|
|
13
|
+
|
|
14
|
+
const kmemUsed = c.getConfigItem("memory.kmem.usage_in_bytes");
|
|
15
|
+
console.log("KernelMemoryUsage:", kmemUsed);
|
|
16
|
+
|
|
17
|
+
const kmemLimit = c.getConfigItem("memory.kmem.limit_in_bytes");
|
|
18
|
+
console.log("KernelMemoryLimit:", kmemLimit);
|
|
19
|
+
|
|
20
|
+
const swapUsed = c.getConfigItem("memory.memsw.usage_in_bytes");
|
|
21
|
+
console.log("MemorySwapUsage:", swapUsed);
|
|
22
|
+
|
|
23
|
+
const swapLimit = c.getConfigItem("memory.memsw.limit_in_bytes");
|
|
24
|
+
console.log("MemorySwapLimit:", swapUsed);
|
|
25
|
+
|
|
26
|
+
const blkioUsage = c.getConfigItem("blkio.throttle.io_service_bytes"); //TODO: Go bindings more complex on nested items and io services
|
|
27
|
+
console.log("BlkioUsage:", blkioUsage);
|
|
28
|
+
|
|
29
|
+
const cpuTime = c.getConfigItem("cpuacct.usage");
|
|
30
|
+
console.log("cpuacct.usage:", cpuTime);
|
|
31
|
+
|
|
32
|
+
const cpuTimePerCPU = c.getConfigItem("cpuacct.usage_percpu"); //TODO: Go bindings more complex on nested cpuTimes
|
|
33
|
+
console.log("cpuacct.usage_percpu:", cpuTimePerCPU);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const cpuStats = c.getConfigItem("cpuacct.usage_percpu"); //TODO: CPUStats returns the number of CPU cycles (in the units defined by USER_HZ on the system)
|
|
37
|
+
//TODO: consumed by tasks in this cgroup and its children in both user mode and system (kernel) mode.
|
|
38
|
+
console.log("cpuacct.stat:", cpuStats);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const interfaceStats = c.getConfigItem("cpuacct.usage"); //TODO: InterfaceStats returns the stats about container's network interfaces
|
|
42
|
+
// @see https://github.com/lxc/go-lxc/blob/v2/container.go#L1707
|
|
43
|
+
console.log("InterfaceStats:", interfaceStats);
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
main().catch(console.error)
|
package/lib/binding.d.ts
ADDED
package/lib/binding.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author A.P.A. Slaa (a.p.a.slaa@projectsource.nl) ProjectSource V.O.F.
|
|
4
|
+
* @date 03-07-2024
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const platform = process.platform;
|
|
12
|
+
const arch = process.arch;
|
|
13
|
+
const base_name = "node-lxc";
|
|
14
|
+
const is_package = __dirname.includes("node_modules");
|
|
15
|
+
let addonPath;
|
|
16
|
+
if (!is_package) {
|
|
17
|
+
const mode = process.env["NODE_ENV"] === "development" ? "Debug" : "Release";
|
|
18
|
+
if (mode === "Debug") {
|
|
19
|
+
console.warn("!!!RUNNING IN DEVELOPMENT MODE!!!");
|
|
20
|
+
}
|
|
21
|
+
addonPath = path_1.default.join(__dirname, '..', 'build', mode, `${base_name}.node`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (platform === 'linux' && arch === 'x64') {
|
|
25
|
+
addonPath = path_1.default.join(__dirname, '..', 'bin', 'x86_64-linux-gnu', `${base_name}.node`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error(`Unsupported platform or architecture: ${platform}-${arch}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.default = require(addonPath);
|
|
32
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../lib/binding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;AAEH,gDAAwB;AAExB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;AAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAE1B,MAAM,SAAS,GAAG,UAAU,CAAA;AAC5B,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACtD,IAAI,SAAS,CAAC;AACd,IAAI,CAAC,UAAU,EAAE,CAAC;IACd,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7E,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;IACtD,CAAC;IACD,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAC,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,OAAO,CAAC,CAAC;AAC9E,CAAC;KAAM,CAAC;IACJ,IAAI,QAAQ,KAAK,OAAO,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACzC,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,EAAE,GAAG,SAAS,OAAO,CAAC,CAAC;IAC3F,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,IAAI,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;AACL,CAAC;AAGD,kBAAe,OAAO,CAAC,SAAS,CAAC,CAAA"}
|