Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get GPU temperature NODEJS

Tags:

node.js

gpu

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.

like image 470
Josip Reh Avatar asked Dec 02 '17 19:12

Josip Reh


People also ask

How do I check CPU temp in 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.

CAN node js use GPU?

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.

What is Nvidia node JS?

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.


1 Answers

There are not Node.js packages with C/C++ submodules for checking GPU temperature, but you can use CLI for that.

Pros and cons:

  • 👍 Easy
  • 👍 You need to know only the CLI command for your OS
  • 👎 performance can be slow
  • 👎 maybe you need run your app with 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';
  }
}
like image 112
galkin Avatar answered Oct 04 '22 12:10

galkin