4
# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
5
# Use of this source code is governed by a BSD-style license that can be
6
# found in the LICENSE file.
8
"""A clone of 'sensors' utility on Linux printing hardware temperatures,
9
fans speed and battery info.
11
$ python3 scripts/sensors.py
14
asus 57.0°C (high=None°C, critical=None°C)
19
acpitz 57.0°C (high=108.0°C, critical=108.0°C)
22
Physical id 0 61.0°C (high=87.0°C, critical=105.0°C)
23
Core 0 61.0°C (high=87.0°C, critical=105.0°C)
24
Core 1 59.0°C (high=87.0°C, critical=105.0°C)
31
from __future__ import print_function
37
mm, ss = divmod(secs, 60)
38
hh, mm = divmod(mm, 60)
39
return "%d:%02d:%02d" % (hh, mm, ss)
43
if hasattr(psutil, "sensors_temperatures"):
44
temps = psutil.sensors_temperatures()
47
fans = psutil.sensors_fans() if hasattr(psutil, "sensors_fans") else {}
48
if hasattr(psutil, "sensors_battery"):
49
battery = psutil.sensors_battery()
53
if not any((temps, fans, battery)):
54
print("can't read any temperature, fans or battery info")
57
names = set(list(temps.keys()) + list(fans.keys()))
62
print(" Temperatures:")
63
for entry in temps[name]:
64
s = " %-20s %s°C (high=%s°C, critical=%s°C)" % (
74
for entry in fans[name]:
77
% (entry.label or name, entry.current)
83
print(" charge: %s%%" % round(battery.percent, 2))
84
if battery.power_plugged:
87
% ("charging" if battery.percent < 100 else "fully charged")
89
print(" plugged in: yes")
91
print(" left: %s" % secs2hours(battery.secsleft))
92
print(" status: %s" % "discharging")
93
print(" plugged in: no")
96
if __name__ == '__main__':