Skip to content

Commit a3b2737

Browse files
committed
Added memory support
1 parent 2c83b7a commit a3b2737

File tree

9 files changed

+334
-67
lines changed

9 files changed

+334
-67
lines changed

README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,22 @@ Drives: [
6666
mount: 'C:',
6767
type: 'ntfs',
6868
total: 1999519543296,
69-
free: 479322533888,
70-
used: 1520197009408,
71-
utilization: 0.7602811457907099
69+
utilization: {
70+
free: 470568960000,
71+
used: 1528950583296,
72+
percentage: 0.7646589844156682
73+
}
7274
},
7375
{
7476
filesystem: 'D:',
7577
mount: 'D:',
7678
type: 'ntfs',
7779
total: 1000203087872,
78-
free: 917103894528,
79-
used: 83099193344,
80-
utilization: 0.08308232033236287
80+
utilization: {
81+
free: 917100240896,
82+
used: 83102846976,
83+
percentage: 0.08308597322250519
84+
}
8185
}
8286
]
8387
GPU Info: [
@@ -91,11 +95,13 @@ GPU Info: [
9195
driverVersion: '32.0.15.7652',
9296
displayAttached: true,
9397
displayActive: true,
94-
fanSpeed: 0.53,
95-
utilization: 0.03,
96-
memoryUtilization: 0.01,
97-
temperature: 52,
98-
powerDraw: 48.32
98+
utilization: {
99+
fanSpeed: 0.56,
100+
processing: 0.01,
101+
memory: 0,
102+
temperature: 51,
103+
powerDraw: 46.65
104+
}
99105
}
100106
]
101107
Network Interfaces: [
@@ -138,4 +144,7 @@ Temperatures: {
138144

139145
### GPU Readings
140146
For more detailed information on GPUs it is recommended to
141-
install the [nvidia-smi](https://developer.nvidia.com/nvidia-system-management-interface) tool.
147+
install the [nvidia-smi](https://developer.nvidia.com/nvidia-system-management-interface) tool.
148+
149+
### Docker
150+
For [Docker](https://www.docker.com/) support, ensure that the Docker daemon is running and accessible.

TODO.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
memory.ts
2+
- Keep 'SMBIOSMemoryType' mapping up to date

src/__tests__/Memory.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { getMemory } from '../memory';
2+
3+
test('getMemory', async () => {
4+
const memory = await getMemory();
5+
console.log(memory); // TODO REMOVE
6+
});

src/docker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export type DockerContainer = {
2+
3+
};

src/drive.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ const VIRTUAL_DRIVE_TYPES = [
66
'overlay', // Overlay filesystem
77
];
88

9+
export type DriveUtilization = {
10+
11+
/** The total amount of unused drive space in bytes. */
12+
free: number;
13+
14+
/** The amount of drive space used in bytes. */
15+
used: number;
16+
17+
/** The current drive utilization as a percentage (0-1). */
18+
percentage: number;
19+
};
20+
21+
922
export type DriveInfo = {
1023
/** The device name of the drive (e.g., /dev/sda1) */
1124
filesystem: string;
@@ -16,19 +29,14 @@ export type DriveInfo = {
1629
/** The filesystem type (e.g., ext4, ntfs) */
1730
type: 'btrfs' | 'devtmpfs' | 'ext4' | 'ntfs' | 'overlay' | 'tmpfs' | 'vfat' | 'xfs' | string;
1831

19-
/** The total amount of unused drive space in bytes. */
20-
free: number;
21-
22-
/** The amount of drive space used in bytes. */
23-
used: number;
24-
2532
/** The total size of the drive in bytes. */
2633
total: number;
2734

28-
/** The current drive utilization as a percentage (0-1). */
29-
utilization: number;
35+
/** Usage of the drive. */
36+
utilization: DriveUtilization;
3037
};
3138

39+
3240
/**
3341
* Returns information about the drives on the system (in Windows the logical drives are returned).
3442
*
@@ -56,10 +64,12 @@ export async function getDrives(includeVirtual: boolean = false): Promise<DriveI
5664
filesystem: parts[0] as string,
5765
type,
5866
total,
59-
used,
60-
free: parseInt(parts[4], 10) || 0,
61-
utilization: total !== 0 ? used / total : 0,
6267
mount: (parts[6] || parts[0]) as string,
68+
utilization: {
69+
used,
70+
free: parseInt(parts[4], 10) || 0,
71+
percentage: total !== 0 ? used / total : 0,
72+
}
6373
});
6474
}
6575
break;
@@ -78,9 +88,11 @@ export async function getDrives(includeVirtual: boolean = false): Promise<DriveI
7888
mount: drive.VolumeName || drive.Caption,
7989
type: (drive.FileSystem || 'unknown').toLowerCase(),
8090
total,
81-
free,
82-
used: total - free,
83-
utilization: total !== 0 ? (total - free) / total : 0,
91+
utilization: {
92+
free,
93+
used: total - free,
94+
percentage: total !== 0 ? (total - free) / total : 0,
95+
}
8496
});
8597
}
8698
break;

src/gpu.ts

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
import { execCommand } from './utils';
22

3+
4+
export type GPUUtilization = {
5+
/** GPU memory utilization as a percentage (0.0-1.0). */
6+
memory?: number;
7+
8+
/** GPU memory temperature in Celsius. */
9+
memoryTemperature?: number;
10+
11+
/** GPU processing utilization as a percentage (0.0-1.0). */
12+
processing?: number;
13+
14+
/** GPU temperature in Celsius. */
15+
temperature?: number;
16+
17+
/** Fan speed in percentage (0.0-1.0). */
18+
fanSpeed?: number;
19+
20+
/** GPU power draw in watts. */
21+
powerDraw?: number;
22+
};
23+
24+
325
export type GPU = {
426
/** Unique ID of the GPU device. */
527
id: string;
@@ -22,15 +44,6 @@ export type GPU = {
2244
/** Memory size of the GPU in bytes. */
2345
memory?: number;
2446

25-
/** Memory utilization of the GPU in percentage (0.0-1.0) */
26-
memoryUtilization?: number;
27-
28-
/** Temperature of the memory in Celsius. */
29-
memoryTemperature?: number;
30-
31-
/** GPU processing utilization in percentage (0.0-1.0) */
32-
utilization?: number;
33-
3447
/** Index of the GPU device. */
3548
index?: number;
3649

@@ -40,14 +53,8 @@ export type GPU = {
4053
/** If memory is allocated inside the GPU for display purposes. Can be true even if no physical display is attached. */
4154
displayActive?: boolean;
4255

43-
/** Fan speed in percentage (0.0-1.0). */
44-
fanSpeed?: number;
45-
46-
/** Temperature of the GPU in Celsius. */
47-
temperature?: number;
48-
49-
/** Power draw of the GPU in watts. */
50-
powerDraw?: number;
56+
/** Utilization data of the GPU. */
57+
utilization?: GPUUtilization;
5158
};
5259

5360
export async function getGPUs(): Promise<GPU[]> {
@@ -159,17 +166,32 @@ export async function getGPUs(): Promise<GPU[]> {
159166
}
160167
if (displayAttached) currGpu.displayAttached = ['yes', 'enabled', '1'].includes(displayAttached.toLowerCase());
161168
if (displayActive) currGpu.displayActive = ['yes', 'enabled', '1'].includes(displayActive.toLowerCase());
162-
if (fanSpeed && !Number.isNaN(parseFloat(fanSpeed))) currGpu.fanSpeed = parseFloat(fanSpeed) / 100;
169+
if (fanSpeed && !Number.isNaN(parseFloat(fanSpeed))){
170+
if(!currGpu.utilization) currGpu.utilization = {} as GPUUtilization;
171+
currGpu.utilization.fanSpeed = parseFloat(fanSpeed) / 100;
172+
}
163173
if (memoryTotal && !Number.isNaN(parseInt(memoryTotal, 10)))
164174
currGpu.memory = parseInt(memoryTotal, 10) * 1024 * 1024; // convert MiB to bytes
165-
if (utilizationGPU && !Number.isNaN(parseFloat(utilizationGPU)))
166-
currGpu.utilization = parseFloat(utilizationGPU) / 100;
167-
if (utilizationMemory && !Number.isNaN(parseFloat(utilizationMemory)))
168-
currGpu.memoryUtilization = parseFloat(utilizationMemory) / 100;
169-
if (temperatureGPU && !Number.isNaN(parseFloat(temperatureGPU))) currGpu.temperature = parseFloat(temperatureGPU);
170-
if (temperatureMemory && !Number.isNaN(parseFloat(temperatureMemory)))
171-
currGpu.memoryTemperature = parseFloat(temperatureMemory);
172-
if (powerDraw && !Number.isNaN(parseFloat(powerDraw))) currGpu.powerDraw = parseFloat(powerDraw);
175+
if (utilizationGPU && !Number.isNaN(parseFloat(utilizationGPU))){
176+
if(!currGpu.utilization) currGpu.utilization = {} as GPUUtilization;
177+
currGpu.utilization.processing = parseFloat(utilizationGPU) / 100;
178+
}
179+
if (utilizationMemory && !Number.isNaN(parseFloat(utilizationMemory))){
180+
if(!currGpu.utilization) currGpu.utilization = {} as GPUUtilization;
181+
currGpu.utilization.memory = parseFloat(utilizationMemory) / 100;
182+
}
183+
if (temperatureGPU && !Number.isNaN(parseFloat(temperatureGPU))) {
184+
if(!currGpu.utilization) currGpu.utilization = {} as GPUUtilization;
185+
currGpu.utilization.temperature = parseFloat(temperatureGPU);
186+
}
187+
if (temperatureMemory && !Number.isNaN(parseFloat(temperatureMemory))) {
188+
if(!currGpu.utilization) currGpu.utilization = {} as GPUUtilization;
189+
currGpu.utilization.memoryTemperature = parseFloat(temperatureMemory);
190+
}
191+
if (powerDraw && !Number.isNaN(parseFloat(powerDraw))) {
192+
if(!currGpu.utilization) currGpu.utilization = {} as GPUUtilization;
193+
currGpu.utilization.powerDraw = parseFloat(powerDraw);
194+
}
173195
gpus[currIdx] = currGpu;
174196
}
175197
}

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
export * from './cpu';
2+
export * from './docker';
23
export * from './drive';
34
export * from './gpu';
5+
export * from './memory';
46
export * from './net';
57
export * from './os';
68
export * from './temperature';
79
export * from './utils';
810

911
import * as cpu from './cpu';
12+
import * as docker from './docker';
1013
import * as drive from './drive';
1114
import * as gpu from './gpu';
15+
import * as memory from './memory';
1216
import * as net from './net';
1317
import * as os from './os';
1418
import * as temperatures from './temperature';
@@ -19,8 +23,10 @@ import * as utils from './utils';
1923
*/
2024
const lupSystem = {
2125
...cpu,
26+
...docker,
2227
...drive,
2328
...gpu,
29+
...memory,
2430
...net,
2531
...os,
2632
...temperatures,

0 commit comments

Comments
 (0)