Reputation: 61
I'm trying to get gpu temperature using nodeJS.
I found one package on npm called "systeminformation" but I cant get gpu temperature from it.
If there is no package/module for it I would like to know a way how to do it from NodeJS.
Upvotes: 6
Views: 3864
Reputation: 5519
There are not Node.js packages with C/C++ submodules for checking GPU temperature, but you can use CLI for that.
Pros and cons:
sudo
For Ubuntu the CLI command looks like:
nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader
Any CLI command execution is async operation so you need callbacks or promises or generators. I prefer async/await 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';
}
}
Upvotes: 10