Friday, December 13, 2013

Python version of iostat.c

Ok, so I have a problem. I'm trying to create metrics for a Linux system, an insert them into a local database. Constraints:
  • Runs on lots of machines;
  • machines may be heavily loaded;
  • Sometimes the kick-off time is delayed beyond a 1-minute standard (typically due to load);
  • I don't like having long-running subprocesses: they might stop/fail and I'd have to restart, they use memory, etc.;
  • I'm doing this in Python;
  • I can store state between runs in a pickle file;
  • I want to replicate the existing fields coming out of vmstat -s and iostat -x -D n (where n is number of seconds of sample size);
  • I want the values of these fields to match likewise.
So, I need to replicate iostat.c in python. I can get absolute numbers from iostat and vmstat and stat, and do the math myself, storing state from the last time I ran it and subtracting to get a diff.

Problem 1: Where is the source code for iostat.c ? In ubuntu at least (hoping RHEL / CENTOS is similar) it turns out it's in the sysstat package. I found systat source at:

Inside this package, there's source code for iostat as a file named iostat.c. I have yet to find it online, so here it is:
General plan:
  1. Read current values from /proc/stats, /proc/diskstats, and vmstat -s
  2. read values from previous run from disk
  3. find diffs
  4. use diffs to compute values needed
  5. write current values to disk for next time.
This will involve significant coding, don't know if I'll have space to post it all here...