There are no Node.js packages with C / C ++ submodules to check the GPU temperature, but you can use the CLI for this.
Advantages and disadvantages:
- 👍 Easy
- 👍 You only need to know the CLI command for your OS.
- 👎 performance may be slow
- Maybe you need to run the application using
sudo
For Ubuntu, the CLI command looks like this:
nvidia-smi --query-gpu = temperature .gpu --format = csv, noheader
Running any CLI command is asynchronous, so you need callbacks or promises or generators. I prefer the async / wait approach.
Example with async / await for 8.9.x Node.js:
const { exec } = require('child_process'); const { promisify } = require('util'); const execAsync = promisify(exec); const gpuTempeturyCommand = 'nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader'; // change it for your OS async function getGPUTemperature() { try { const result = await execAsync(gpuTempeturyCommand); return result.stdout; } catch (error) { console.log('Error during getting GPU temperature'); return 'unknown'; } }
source share