Example Of Capturing IOStat With Python

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

The below Example captures IOStat output with Python

#!/bin/python

import subprocess
import csv

io_c = subprocess.Popen(['iostat', '-xnsMr', '1', '2'], stdout=subprocess.PIPE, shell=False, stderr=subprocess.PIPE)
stdout = io_c.communicate()[0]
lc = len(stdout.split('\n'))
it_lc = lc / 2 + 2
reader = csv.reader(stdout.split('\n')[it_lc:], delimiter=',')
for row in reader:
    if any(row):
       #print row
       print row[0],row[1],row[2],row[3],row[7],row[8],row[9],row[10]

Output would look like

0.0 0.0 0.0 0.0 0.0 0 0 c3t3d0
0.0 0.0 0.0 0.0 0.0 0 0 c3t0d0
0.0 0.0 0.0 0.0 0.0 0 0 c3t1d0
0.0 0.0 0.0 0.0 0.0 0 0 c3t2d0
0.0 0.0 0.0 0.0 0.0 0 0 nas-srv:/export/sys-admin/unix
0.0 0.0 0.0 0.0 0.0 0 0 10.10.10.11:/export/shares

2
Leave a Reply

avatar
3000
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Eli Kleinmancaptainstarlifter Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
captainstarlifter
Guest
captainstarlifter

Hi Eli, have you extended this since 2016?