Skip to content

Commit 9371e45

Browse files
committed
Split getContainerLogs and getContainerStats into additional functions dedicated to streaming the result
1 parent 00c2ac9 commit 9371e45

File tree

5 files changed

+172
-255
lines changed

5 files changed

+172
-255
lines changed

README.md

Lines changed: 30 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -12,174 +12,42 @@ JavaScript:
1212
```javascript
1313
const Docker = require('lup-docker');
1414

15-
Docker..getCpuInfo().then(cpuInfo => console.log("CPU Info: " + cpuInfo));
15+
// List of all containers
16+
const containers = await Docker.getContainers().then(result => result.success || []);
17+
console.log(containers);
18+
19+
// Stream of a containers utilization stats
20+
const statsStream = await Docker.getContainerStatsStream('busybox').then(result => result.success);
21+
if(statsStream){
22+
const statsReader = statsStream.getReader();
23+
while(true){
24+
const { done, value } = await statsReader.read();
25+
if(done) break;
26+
27+
// Process the stats data
28+
console.log(value);
29+
}
30+
}
1631
```
1732

1833
TypeScript:
1934
```typescript
2035
import lupSystem from 'lup-docker';
2136

22-
(async () => {
23-
console.log("CPU Info: ", await lupSystem.getCpuInfo());
24-
console.log("Drives: ", await lupSystem.getDrives()); // Array of drive objects
25-
console.log("GPU Info: ", await lupSystem.getGPUs());
26-
console.log("Memory Info: ", await lupSystem.getMemoryInfo());
27-
console.log("Network Interfaces: ", await lupSystem.getNetworkInterfaces());
28-
console.log("OS Info: ", await lupSystem.getOSInfo());
29-
console.log("Temperatures: ", await lupSystem.getTemperatures());
30-
})();
31-
```
37+
// List of all containers
38+
const containers = await Docker.getContainers().then(result => result.success || []);
39+
console.log(containers);
3240

33-
Output:
34-
```
35-
CPU Info: {
36-
architecture: 'x64',
37-
coreCount: 12,
38-
endian: 'LE',
39-
name: '11th Gen Intel(R) Core(TM) i5-11600K @ 3.90GHz',
40-
speed: 3912,
41-
utilization: {
42-
overall: 0.20021299254526093,
43-
cores: [
44-
0.20253164556962025,
45-
0.19230769230769232,
46-
0.6025641025641025,
47-
0,
48-
0.3974358974358974,
49-
0.20253164556962025,
50-
0,
51-
0,
52-
0.20253164556962025,
53-
0,
54-
0.19480519480519481,
55-
0.4050632911392405
56-
]
57-
}
58-
}
59-
Drives: [
60-
{
61-
filesystem: 'C:',
62-
mount: 'C:',
63-
type: 'ntfs',
64-
total: 1999519543296,
65-
utilization: {
66-
free: 470568960000,
67-
used: 1528950583296,
68-
percentage: 0.7646589844156682
69-
}
70-
},
71-
{
72-
filesystem: 'D:',
73-
mount: 'D:',
74-
type: 'ntfs',
75-
total: 1000203087872,
76-
utilization: {
77-
free: 917100240896,
78-
used: 83102846976,
79-
percentage: 0.08308597322250519
80-
}
81-
}
82-
]
83-
GPU Info: [
84-
{
85-
name: 'NVIDIA GeForce RTX 3060 Ti',
86-
status: 'ok',
87-
id: 'PCI\\VEN_10DE&DEV_2489&SUBSYS_884F1043&REV_A1\\4&2130FF93&0&0008',
88-
processor: 'NVIDIA GeForce RTX 3060 Ti',
89-
memory: 8589934592,
90-
driverDate: '14.05.2025 02:00:00',
91-
driverVersion: '32.0.15.7652',
92-
displayAttached: true,
93-
displayActive: true,
94-
utilization: {
95-
fanSpeed: 0.56,
96-
processing: 0.01,
97-
memory: 0,
98-
temperature: 51,
99-
powerDraw: 46.65
100-
}
101-
}
102-
]
103-
Memory Info: {
104-
size: 34249633792,
105-
utilization: {
106-
used: 22643089408,
107-
free: 11606544384,
108-
percentage: 0.6611191683249166
109-
},
110-
devices: [
111-
{
112-
manufacturer: 'Kingston',
113-
model: 'KF3200C16D4/16GX',
114-
bankName: 'BANK 0',
115-
size: 17179869184,
116-
busWidth: 64,
117-
maxClockSpeed: 2400,
118-
clockSpeed: 2400,
119-
voltage: 1.2,
120-
locator: 'Controller0-ChannelA-DIMM1',
121-
type: 'DDR4',
122-
transfersPerClockCycle: 2,
123-
bandwidth: 38400000000
124-
},
125-
{
126-
manufacturer: 'Kingston',
127-
model: 'KF3200C16D4/16GX',
128-
bankName: 'BANK 1',
129-
size: 17179869184,
130-
busWidth: 64,
131-
maxClockSpeed: 2400,
132-
clockSpeed: 2400,
133-
voltage: 1.2,
134-
locator: 'Controller0-ChannelB-DIMM1',
135-
type: 'DDR4',
136-
transfersPerClockCycle: 2,
137-
bandwidth: 38400000000
138-
}
139-
],
140-
bandwidth: 76800000000
141-
}
142-
Network Interfaces: [
143-
{
144-
name: 'Loopback Pseudo-Interface 1',
145-
addresses: [ [Object], [Object] ],
146-
status: { operational: 'unknown', admin: true, cable: false },
147-
physical: true
148-
},
149-
{
150-
name: 'Ethernet',
151-
addresses: [],
152-
status: { operational: 'up', admin: true, cable: true },
153-
physical: true,
154-
speed: { bits: 1000000000, bytes: 125000000 },
155-
utilization: {
156-
receive: 0.000003003690036900369,
157-
transmit: 4.723247232472324e-7
158-
}
41+
// Stream of a containers utilization stats
42+
const statsStream = await Docker.getContainerStatsStream('busybox').then(result => result.success);
43+
if(statsStream){
44+
const statsReader = statsStream.getReader();
45+
while(true){
46+
const { done, value } = await statsReader.read();
47+
if(done) break;
48+
49+
// Process the stats data
50+
console.log(value);
15951
}
160-
]
161-
OS Info: {
162-
name: 'Windows',
163-
version: '10.0.26100',
164-
architecture: 'x64',
165-
machine: 'x86_64',
166-
platform: 'win32',
167-
bits: 64,
168-
hostname: 'my-pc',
169-
uptime: 2025-07-25T09:38:27.126Z
17052
}
171-
Temperatures: {
172-
cpu: 45.2,
173-
gpu: 60.8,
174-
}
175-
```
176-
177-
178-
## Considerations
179-
180-
### GPU Readings
181-
For more detailed information on GPUs it is recommended to
182-
install the [nvidia-smi](https://developer.nvidia.com/nvidia-system-management-interface) tool.
183-
184-
### Docker
185-
For [Docker](https://www.docker.com/) support, ensure that the Docker daemon is running and accessible.
53+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lup-docker",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "NodeJS library to interact with the Docker engine.",
55
"main": "./lib/index",
66
"types": "./lib/index.d.ts",

0 commit comments

Comments
 (0)