diff options
| author | Alex Manuskin <amanusk@protonmail.com> | 2018-10-01 15:50:04 +0300 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2018-10-01 14:50:04 +0200 |
| commit | 13ef73cd5c41155b6cb6cd5b51cd5d6c100b4d47 (patch) | |
| tree | e60a49495c199aecd56c563b10f42e831b10216c /psutil/_pslinux.py | |
| parent | 1d7516c10cc89c60b8b5607ff9656d2f817b22b1 (diff) | |
| download | psutil-13ef73cd5c41155b6cb6cd5b51cd5d6c100b4d47.tar.gz | |
Add parsing for /sys/class/thermal (#1345)
Add parsing for /sys/class/thermal
Diffstat (limited to 'psutil/_pslinux.py')
| -rw-r--r-- | psutil/_pslinux.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 1575dad9..a69b1d66 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1213,6 +1213,50 @@ def sensors_temperatures(): ret[unit_name].append((label, current, high, critical)) + # Indication that no sensors were detected in /sys/class/hwmon/ + if not basenames: + basenames = glob.glob('/sys/class/thermal/thermal_zone*') + basenames = sorted(set(basenames)) + + for base in basenames: + try: + path = os.path.join(base, 'temp') + current = float(cat(path)) / 1000.0 + path = os.path.join(base, 'type') + unit_name = cat(path, binary=False) + except (IOError, OSError, ValueError) as err: + warnings.warn("ignoring %r for file %r" % (err, path), + RuntimeWarning) + continue + + trip_paths = glob.glob(base + '/trip_point*') + trip_points = set(['_'.join( + os.path.basename(p).split('_')[0:3]) for p in trip_paths]) + critical = None + high = None + for trip_point in trip_points: + path = os.path.join(base, trip_point + "_type") + trip_type = cat(path, fallback='', binary=False) + if trip_type == 'critical': + critical = cat(os.path.join(base, trip_point + "_temp"), + fallback=None) + elif trip_type == 'high': + high = cat(os.path.join(base, trip_point + "_temp"), + fallback=None) + + if high is not None: + try: + high = float(high) / 1000.0 + except ValueError: + high = None + if critical is not None: + try: + critical = float(critical) / 1000.0 + except ValueError: + critical = None + + ret[unit_name].append(('', current, high, critical)) + return ret |
