diff options
-rw-r--r-- | CREDITS | 4 | ||||
-rw-r--r-- | HISTORY.rst | 4 | ||||
-rw-r--r-- | README.rst | 17 | ||||
-rw-r--r-- | docs/index.rst | 17 | ||||
-rw-r--r-- | psutil/__init__.py | 2 | ||||
-rw-r--r-- | psutil/_common.py | 2 | ||||
-rw-r--r-- | psutil/_pslinux.py | 4 | ||||
-rwxr-xr-x | psutil/tests/test_misc.py | 7 | ||||
-rwxr-xr-x | scripts/fans.py | 35 |
9 files changed, 76 insertions, 16 deletions
@@ -429,3 +429,7 @@ I: 950 N: Thiago Borges Abdnur W: https://github.com/bolaum I: 959 + +N: Nicolas Hennion +W: https://github.com/nicolargo +I: 974 diff --git a/HISTORY.rst b/HISTORY.rst index 457003df..603bc1c0 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,12 +2,12 @@ *2017-02-07* -5.1.4 +5.2.0 ===== **Enhancements** -- 971_: [Linux] Add sensors_fans method. +- 971_: [Linux] Add psutil.sensors_fans() function. (patch by Nicolas Hennion) 5.1.3 ===== @@ -41,12 +41,14 @@ Summary psutil (process and system utilities) is a cross-platform library for retrieving information on **running processes** and **system utilization** -(CPU, memory, disks, network) in Python. It is useful mainly for **system -monitoring**, **profiling and limiting process resources** and **management of -running processes**. It implements many functionalities offered by command line -tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, -ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports -**Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD** and **NetBSD**, +(CPU, memory, disks, networkm sensors) in Python. +It is useful mainly for **system monitoring**, **profiling and limiting process +resources** and **management of running processes**. +It implements many functionalities offered by command line tools such as: +ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, +iotop, uptime, pidof, tty, taskset, pmap. +It currently supports **Linux**, **Windows**, **OSX**, **Sun Solaris**, +**FreeBSD**, **OpenBSD** and **NetBSD**, both **32-bit** and **64-bit** architectures, with Python versions from **2.6 to 3.5** (users of Python 2.4 and 2.5 may use `2.1.3 <https://pypi.python.org/pypi?name=psutil&version=2.1.3&:action=files>`__ version). @@ -201,6 +203,9 @@ Sensors shwtemp(label='Core 2', current=45.0, high=100.0, critical=100.0), shwtemp(label='Core 3', current=47.0, high=100.0, critical=100.0)]} >>> + >>> psutil.sensors_fans() + {'asus': [sfan(label='cpu_fan', current=3200)]} + >>> >>> psutil.sensors_battery() sbattery(percent=93, secsleft=16628, power_plugged=False) >>> diff --git a/docs/index.rst b/docs/index.rst index d8e1af80..7186893b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -626,8 +626,8 @@ Sensors .. function:: sensors_temperatures(fahrenheit=False) Return hardware temperatures. Each entry is a named tuple representing a - certain hardware sensor (it may be a CPU, an hard disk or something - else, depending on the OS and its configuration). + certain hardware temperature sensor (it may be a CPU, an hard disk or + something else, depending on the OS and its configuration). All temperatures are expressed in celsius unless *fahrenheit* is set to ``True``. Example:: @@ -656,16 +656,19 @@ Sensors .. function:: sensors_fans() Return hardware fans speed. Each entry is a named tuple representing a - certain hardware sensor. + certain hardware sensor fan. All speed is expressed in RPM (round per minut). Example:: >>> import psutil >>> psutil.sensors_fans() - defaultdict(<type 'list'>, {'dell_smm': [('Processor Fan', 3028)]}) + {'asus': [sfan(label='cpu_fan', current=3200)]} + + See also `fans.py <https://github.com/giampaolo/psutil/blob/master/scripts/fans.py>`__ + for an example application. Availability: Linux - .. versionadded:: 5.1.4 + .. versionadded:: 5.2.0 .. warning:: @@ -709,6 +712,10 @@ Sensors .. versionadded:: 5.1.0 + .. warning:: + + This API is experimental. Backward incompatible changes may occur if + deemed necessary. Other system info ----------------- diff --git a/psutil/__init__.py b/psutil/__init__.py index 244e6fca..c72b7a7d 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -192,7 +192,7 @@ __all__ = [ ] __all__.extend(_psplatform.__extra__all__) __author__ = "Giampaolo Rodola'" -__version__ = "5.1.3" +__version__ = "5.2.0" version_info = tuple([int(num) for num in __version__.split('.')]) AF_LINK = _psplatform.AF_LINK POWER_TIME_UNLIMITED = _common.POWER_TIME_UNLIMITED diff --git a/psutil/_common.py b/psutil/_common.py index 3b68b6d3..2497226a 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -174,6 +174,8 @@ shwtemp = namedtuple( 'shwtemp', ['label', 'current', 'high', 'critical']) # psutil.sensors_battery() sbattery = namedtuple('sbattery', ['percent', 'secsleft', 'power_plugged']) +# psutil.sensors_battery() +sfan = namedtuple('sfan', ['label', 'current']) # --- for Process methods diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index ce20e8a0..52c67302 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1142,9 +1142,9 @@ def sensors_fans(): label = cat(base + '_label', fallback='', binary=False) current = int(cat(base + '_input')) - ret[unit_name].append((label, current)) + ret[unit_name].append(_common.sfan(label, current)) - return ret + return dict(ret) def sensors_battery(): diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py index 571c03a3..615f18a1 100755 --- a/psutil/tests/test_misc.py +++ b/psutil/tests/test_misc.py @@ -477,6 +477,13 @@ class TestScripts(unittest.TestCase): else: self.assert_syntax('temperatures.py') + @unittest.skipIf(TRAVIS, "unreliable on travis") + def test_fans(self): + if hasattr(psutil, "sensors_fans") and psutil.sensors_fans(): + self.assert_stdout('fans.py') + else: + self.assert_syntax('fans.py') + def test_battery(self): if hasattr(psutil, "sensors_battery") and \ psutil.sensors_battery() is not None: diff --git a/scripts/fans.py b/scripts/fans.py new file mode 100755 index 00000000..e302aec5 --- /dev/null +++ b/scripts/fans.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +Show fans information. + +$ python fans.py +asus + cpu_fan 3200 RPM +""" + +from __future__ import print_function +import sys + +import psutil + + +def main(): + if not hasattr(psutil, "sensors_fans"): + return sys.exit("platform not supported") + fans = psutil.sensors_fans() + if not fans: + return sys.exit("no fans detected") + for name, entries in fans.items(): + print(name) + for entry in entries: + print(" %-20s %s RPM" % (entry.label or name, entry.current)) + print() + + +if __name__ == '__main__': + main() |