System Metrics/Stats Library for Linux
- 2010-2012 Corey Goldberg
- Dev Home: https://github.com/cgoldberg/linux-metrics
- PyPI: http://pypi.python.org/pypi/linux-metrics
- Free Open Source : MIT License
linux-metrics is a Python package containing modules for getting OS metrics on systems running the Linux kernel. It is a pure python library with no external dependencies.
Basic stats for major subsystems are provided (Processor/CPU, Disk, Memory, Network).
- pip install linux-metrics
- Python 2.6+
- Linux 2.6+
print number of processes running:
from linux_metrics import cpu_stat
print cpu_stat.procs_running()
print CPU utilization every 5 secs:
>>> from linux_metrics import cpu_stat
>>>
>>> while True:
... cpu_pcts = cpu_stat.cpu_percents(5)
... print 'cpu utilization: %.2f%%' % (100 - cpu_pcts['idle'])
...
cpu utilization: 0.70%
cpu utilization: 0.50%
cpu utilization: 24.80%
cpu utilization: 20.89%
cpu utilization: 40.04%
* linux_metrics
* cpu_stat
* cpu_times()
* cpu_percents(sample_duration=1)
* procs_running()
* procs_blocked()
* load_avg()
* cpu_info()
* disk_stat
* disk_busy(device, sample_duration=1)
* disk_reads_writes(device)
* disk_usage(path)
* disk_reads_writes_persec(device, sample_duration=1)
* mem_stat
* mem_stats()
* mem_info()
* net_stat
* rx_tx_bytes(interface)
* rx_tx_bits(interface)
* rx_tx_dump(interface)
linux-metrics package contains an example script:
You can run the included unit tests and verify all cases pass in your environment:
Note: you may need to adjust the configuration of the unit tests to match your environment. They are set by default to use:
DISK_DEVICE = 'sda1'
NETWORK_INTERFACE = 'eth0'