Get GPU temperature NODEJS

感情迁移 提交于 2020-08-27 06:37:42

问题


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.


回答1:


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';
  }
}


来源:https://stackoverflow.com/questions/47611904/get-gpu-temperature-nodejs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!