This small library captures CPU temperature on macOS (Apple silicon processors), all values are in degree Celsius. This library is intended to be used server side (not within a browser) and is designed to work on ARM based systems.
This library is a replacement for our old osx-temperature-sensor package (which was designed to work on intel based machines).
Installation
$ npm install macos-temperature-sensor
Using this library with Deno:
Make sure, that your deno.json has set the following:
Here a small example how to use this library index.js:
const macosTemp = require("macos-temperature-sensor");let temperature = macosTemp.temperature();console.log("CPU temperature:");console.log(temperature);
Then run it with node index.js
In Deno it would be index.ts:
import * as macosTemp from "macos-temperature-sensor";let temperature = macosTemp.temperature();console.log("CPU temperature:");console.log(temperature);
CPU temperature (if sensors is installed) in Celsius
- cpu
cpu max temperature
- soc
soc avg temperature
- gpu
max gpu temperature
- cpuDieTemps
array of all cpu die temperature points
- probeGroupsTemps
array of all probe groups temperature points
- gpuDieTemps
array of all gpu die temperature points
macosTemp.fans()
array of fans (empty if the machine has no fans)
- label
fan label e.g. Fan 1
- rpm
This library is supposed to only work on macOS, apple silicon processors
GPU die temperatures are read via IOHID (PMU tdev* sensors, up to M4) or via SMC (Tg* keys) on chips like the M5 that no longer expose GPU sensors through IOHID.
Fan speeds are read via the SMC keys FNum, F<n>Ac, F<n>Mn and F<n>Mx. pwm is not exposed by the SMC and is derived from the fan's min/max range. Machines without fans (e.g. MacBook Air) return an empty array.
Known Issues
I am happy to discuss any comments and suggestions. Please feel free to contact me if you see any possibility of improvement!
Comments
If you have ideas or comments, please do not hesitate to contact me.
Apple and macOS are registered trademarks of Apple Inc., Node.js is a trademark of OpenJS Foundation.
All other trademarks are the property of their respective owners.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.