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.
Case you are running linux you may have something like that: cat /sys/class/thermal/thermal_zone0/temp . Divide the result by 1000 and you get the CPU temperature.
In short, GPU. js is a JavaScript acceleration library that can be used for general-purpose computations on GPUs using JavaScript. It supports browsers, Node. js and TypeScript.
If you are not familiar with Node. js, it is an open-source, cross-platform runtime environment based on C/C++ that executes JavaScript code outside of a web browser. Over 1 Million Node. js downloads occur per day. Node Package Manager (NPM) is the default JavaScript package manager and Microsoft owns it.
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';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With