My favorites | Sign in
Project Home Downloads Source
Project Information
Members
Featured
Downloads
Links

linux-metrics

Python Package - System Metrics/Stats for Linux
Copyright © 2010-2011 Corey Goldberg (http://goldb.org)

Open Source License : MIT

Description

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.
Only basic stats for major subsystems are provided (Processor/CPU, Disk, Memory, Network). Hopefully, more are coming.

Download


Installation

Quick Install (from PyPI)

  • pip install linux-metrics
or
  • easy_install linux-metrics

Manual Install

The linux-metrics package distribution ships with a Disutils setup script (setup.py) for installation:
  • $ python setup.py install (as root)

The full set of command line steps to download/unarchive/install:
  • $ wget http://linux-metrics.googlecode.com/files/linux-metrics-0.1.2.tar.gz
  • $ tar -zxvf linux-metrics-0.1.2.tar.gz
  • $ cd linux-metrics-0.1.2
  • $ sudo python setup.py install


Requirements

  • Python 2.6+
  • Linux 2.6+

Example Usage

script: print number of processes running

#!/usr/bin/env python

from linux_metrics import cpu_stat

print cpu_stat.procs_running()

python shell: 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%

Unit Tests

The linux-metrics package distribution ships with a suite of unit tests: tests.py
You can run the tests and verify all cases pass in your environment:
  • $ python tests.py
Note: you may need to adjust the configuration of the unit tests to match your environment. They are set by default to use:
# configuration  
DISK_DEVICE = 'sda'
NETWORK_INTERFACE = 'eth0'

View Source Code (Git)


Modules / Functions

  • 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_reads_writes_persec(device, sample_duration=1)
    • mem_stat
      • mem_stats()
    • net_stat
      • rx_tx_bytes(interface)
      • rx_tx_bits(interface)

More Examples

The linux-metrics package distribution ships with a simple example script: example.py
For more complete examples, see the module source files:

Python Package Index (PyPI)

Classifiers:

  • Intended Audience :: Developers
  • Intended Audience :: System Administrators
  • License :: OSI Approved :: MIT License
  • Operating System :: POSIX :: Linux
  • Programming Language :: Python :: 2.6
  • Programming Language :: Python :: 2.7
  • Topic :: Software Development :: Libraries :: Python Modules
  • Topic :: System :: Monitoring

Powered by Google Project Hosting