Get NODEJS GPU Temperature

I am trying to get gpu temperature using nodeJS.

I found one package on npm called "systeminformation", but I cannot get gpu temperature from it.

If there is no package / module for it, I would like to know how to do it from NodeJS.

+5
source share
1 answer

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'; } } 
+2
source

Source: https://habr.com/ru/post/1273814/


All Articles