Mac smc_exporter with temperatures for Prometheus

14 Jun 2024

We have built our own dashboard for monitoring our Macs in data centers.  After a couple of more manual processes, we have moved to collecting all the data in Prometheus and feeding that to Grafana and our own dashboard.  One of the data points we want to get notified about is temperature of the computers (especially in relation to the environment).   We have used some other solutions with various level of success, but were not happy with the full experience, so we wrote our own.

smc_exporter is a swift command line tool for collecting smc details and hosting them on a small web server for Prometheus to consume.  The tool is designed to be run by a launch daemon to start when the computer boots.  It takes arguments for what port to run on (defaults to 9101), and what smc data to expose (defaults to just temperatures).  Possible types are temperature(s), voltage(s), current(s), power(s), and fan(s).   Something like 

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
<plist version="1.0">  
<dict>  
    <key>Label</key>  
    <string>org.rskgroup.smc_exporter</string>  
    <key>RunAtLoad</key>  
    <true/>  
    <key>KeepAlive</key>  
    <true/>  
    <key>ProgramArguments</key>  
    <array>  
        <string>/usr/local/bin/smc_exporter</string>  
        <string>9119</string>  
        <string>temperature</string>  
        <string>fans</string>  
        <string>power</string>  
    </array>  
</dict>  
</plist>  

The above will run on port 9119 and report on temperature, fans, and power and look like:

rsk_sensor{computername="admin-MBP",sensorid="TB1T",name="Battery",type="Temperature",value="31.00"} 31.00
rsk_sensor{computername="admin-MBP",sensorid="TB2T",name="Battery 2",type="Temperature",value="31.50"} 31.50
rsk_sensor{computername="admin-MBP",sensorid="TG0H",name="GPU heatsink",type="Temperature",value="0.00"} 0.00
rsk_sensor{computername="admin-MBP",sensorid="TH0x",name="NAND",type="Temperature",value="34.06"} 34.06
rsk_sensor{computername="admin-MBP",sensorid="TW0P",name="Airport",type="Temperature",value="40.55"} 40.55
rsk_sensor{computername="admin-MBP",sensorid="TaLP",name="Airflow left",type="Temperature",value="40.23"} 40.23
rsk_sensor{computername="admin-MBP",sensorid="TaRF",name="Airflow right",type="Temperature",value="39.24"} 39.24
rsk_sensor{computername="admin-MBP",sensorid="Tg05",name="GPU 1",type="Temperature",value="52.94"} 52.94
rsk_sensor{computername="admin-MBP",sensorid="Tg0D",name="GPU 2",type="Temperature",value="50.52"} 50.52
rsk_sensor{computername="admin-MBP",sensorid="Tm02",name="Memory 1",type="Temperature",value="42.88"} 42.88
rsk_sensor{computername="admin-MBP",sensorid="Tm06",name="Memory 2",type="Temperature",value="43.81"} 43.81
rsk_sensor{computername="admin-MBP",sensorid="Tp01",name="CPU performance core 1",type="Temperature",value="52.51"} 52.51
rsk_sensor{computername="admin-MBP",sensorid="Tp05",name="CPU performance core 2",type="Temperature",value="52.94"} 52.94
rsk_sensor{computername="admin-MBP",sensorid="Tp09",name="CPU efficiency core 1",type="Temperature",value="50.25"} 50.25
rsk_sensor{computername="admin-MBP",sensorid="Tp0D",name="CPU performance core 3",type="Temperature",value="50.54"} 50.54
rsk_sensor{computername="admin-MBP",sensorid="Tp0H",name="CPU performance core 4",type="Temperature",value="51.76"} 51.76
rsk_sensor{computername="admin-MBP",sensorid="Tp0L",name="CPU performance core 5",type="Temperature",value="49.54"} 49.54
rsk_sensor{computername="admin-MBP",sensorid="Tp0P",name="Powerboard",type="Temperature",value="51.51"} 51.51
rsk_sensor{computername="admin-MBP",sensorid="Tp0T",name="CPU efficiency core 2",type="Temperature",value="50.81"} 50.81
rsk_sensor{computername="admin-MBP",sensorid="Tp0X",name="CPU performance core 7",type="Temperature",value="50.88"} 50.88
rsk_sensor{computername="admin-MBP",sensorid="Tp0b",name="CPU performance core 8",type="Temperature",value="50.24"} 50.24
rsk_sensor{computername="admin-MBP",sensorid="PDBR",name="Power Delivery Brightness",type="Power",value="1.59"} 1.59
rsk_sensor{computername="admin-MBP",sensorid="PDTR",name="DC In",type="Power",value="27.08"} 27.08
rsk_sensor{computername="admin-MBP",sensorid="PPBR",name="Battery",type="Power",value="0.89"} 0.89
rsk_sensor{computername="admin-MBP",sensorid="PSTR",name="System Total",type="Power",value="25.70"} 25.70
rsk_sensor{computername="admin-MBP",sensorid="F0ID",name="Left fan",type="Fan",min_speed="1499.0",max_speed="4296.0",value="1528.4417724609375"} 1528.4417724609375
rsk_sensor{computername="admin-MBP",sensorid="F1ID",name="Right fan",type="Fan",min_speed="1499.0",max_speed="4744.0",value="1647.770751953125"} 1647.770751953125

For testing, the above command would be: smc_exporter 9119 temperature fans power

The GitHub repo includes a launchd plist and Packages project to create an installer for the tool.

Much of the smc information comes from the stats project on GitHub, and the web server is using the Apple created swift package Swift-NIO.

Share

Eric Hemmeter