summaryrefslogtreecommitdiff
path: root/psutil/_pslinux.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-02-01 16:54:43 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-02-01 16:54:43 +0100
commit3fb929dbb61f1437c5876de723978f98006a6511 (patch)
tree3bbdc3d86e3ef16725c1228c10587a06559670da /psutil/_pslinux.py
parent0f7d22656de9a6c51da3a22d52ab876c36bf74ed (diff)
parented0975dec40434b0e40bf8681325ffdaa8c5858d (diff)
downloadpsutil-3fb929dbb61f1437c5876de723978f98006a6511.tar.gz
merge from master
Diffstat (limited to 'psutil/_pslinux.py')
-rw-r--r--psutil/_pslinux.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 4e834497..0d5f6ecb 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -7,6 +7,7 @@
from __future__ import division
import base64
+import collections
import errno
import functools
import glob
@@ -65,6 +66,7 @@ POWER_SUPPLY_PATH = "/sys/class/power_supply"
HAS_SMAPS = os.path.exists('/proc/%s/smaps' % os.getpid())
HAS_PRLIMIT = hasattr(cext, "linux_prlimit")
+_DEFAULT = object()
# RLIMIT_* constants, not guaranteed to be present on all kernels
if HAS_PRLIMIT:
@@ -1065,6 +1067,42 @@ def disk_partitions(all=False):
# =====================================================================
+if os.path.exists('/sys/class/hwmon'):
+
+ def sensors_temperatures():
+ """Return hardware (CPU and others) temperatures as a dict
+ including hardware name, label, current, max and critical
+ temperatures.
+
+ Implementation notes:
+ - /sys/class/hwmon looks like the most recent interface to
+ retrieve this info, and this implementation relies on it
+ only (old distros will probably use something else)
+ - lm-sensors on Ubuntu 16.04 relies on /sys/class/hwmon
+ - /sys/class/thermal/thermal_zone* is another one but it's more
+ difficult to parse
+ """
+ ret = collections.defaultdict(list)
+ basenames = sorted(set(
+ [x.split('_')[0] for x in
+ glob.glob('/sys/class/hwmon/hwmon*/temp*_*')]))
+ for base in basenames:
+ unit_name = cat(os.path.join(os.path.dirname(base), 'name'))
+ label = cat(base + '_label', fallback='')
+ current = float(cat(base + '_input')) / 1000.0
+ high = cat(base + '_max', fallback=None)
+ critical = cat(base + '_crit', fallback=None)
+
+ if high is not None:
+ high = float(high) / 1000.0
+ if critical is not None:
+ critical = float(critical) / 1000.0
+
+ ret[unit_name].append((label, current, high, critical))
+
+ return ret
+
+
def sensors_battery():
root = os.path.join(POWER_SUPPLY_PATH, "BAT0")
if not os.path.exists(root):