class: center, middle, lblue # psutils and friends ## My Favorite Python tool ### 14.07.2015, Oz Tiram, Python Users Munich --- class: lblue # What is it? * psutil is a crosss platfrom library for retrieving information on running processes and system utilization * It implements many functionalities offered by command line tools such as: `ps`, `top`, `lsof`, `netstat`, etc ... --- class: lblue # Why ? * We still need to know stuff about systems * `It works! On my laptop!`
TM
(Dev's with Windows laptops) * Replace tools like `ps`, `netstat` etc. where they are not available * Use, don't parse! --- class: lblue .left-column[ ## Example ### - With UNIX tools ] .right-column[ * Get the number of hosts CPUs: ```shell $ cat /proc/cpuinfo ``` ] --- class: lblue .left-column[ ## Example ### - With UNIX tools ### - Parsing? ] .right-column[ * Get the number of hosts CPUs: ```shell $ cat /proc/cpuinfo ``` * Parse that output with Python? ```python In [11]: f = open('/proc/cpuinfo') In [12]: [f for f in f.readlines() if f.startswith('processor')] Out[12]: ['processor\t: 0\n', ... 'processor\t: 6\n', 'processor\t: 7\n'] ``` ] --- class: lblue .left-column[ ## Example ### - With UNIX tools ### - Parsing? ### - Using! ] .right-column[ * Get the number of hosts CPUs: ```shell $ cat /proc/cpuinfo ``` * Parse that output with Python? ```python In [11]: f = open('/proc/cpuinfo') In [12]: [f for f in f.readlines() if f.startswith('processor')] Out[12]: ['processor\t: 0\n', ... 'processor\t: 6\n', 'processor\t: 7\n'] ``` * With `psutil` ```python >>> import psutil >>> psutil.cpu_count() 8 >>> psutil.cpu_count(logical=False) 4 ``` *
It works! On their laptop too!
] --- class: lblue # Friends * [PSDash](https://github.com/Jahaja/psdash/)  A Flask based real time monitoring for a single or multiple hosts. --- class: lblue # Friends * [Glances](https://github.com/nicolargo/glances)  Cureses based real time monitoring with an optional responsive web UI. --- class: lblue # and more ... * [Excellent documentaion for psutils](http://pythonhosted.org/psutil/) * [ptop](http://github.com/black-perl/ptop/)  * [GRR Rapid Response: remote live forensics for incident response](https://github.com/google/grr)