#NEWLINE# def main( ) : #NEWLINE# #INDENT# 'iostats main loop.' #NEWLINE# f_diskstats = open ( '/proc/diskstats' , 'r' ) #NEWLINE# while True : #NEWLINE# #INDENT# if ( os . getppid ( ) == 1 ) : #NEWLINE# #INDENT# sys . exit ( 1 ) #NEWLINE# #UNINDENT# f_diskstats . seek ( 0 ) #NEWLINE# ts = int ( time . time ( ) ) #NEWLINE# for line in f_diskstats : #NEWLINE# #INDENT# values = line . split ( None ) #NEWLINE# if ( values [ 3 ] == '0' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( ( ( int ( values [ 1 ] ) % 16 ) == 0 ) and ( int ( values [ 0 ] ) > 1 ) ) : #NEWLINE# #INDENT# metric = 'iostat.disk.' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# metric = 'iostat.part.' #NEWLINE# #UNINDENT# device = values [ 2 ] . replace ( '/' , '_' ) #NEWLINE# if ( len ( values ) == 14 ) : #NEWLINE# #INDENT# for i in range ( 11 ) : #NEWLINE# #INDENT# print ( ( '%s%s %d %s dev=%s' % ( metric , FIELDS_DISK [ i ] , ts , values [ ( i + 3 ) ] , device ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( values ) == 7 ) : #NEWLINE# #INDENT# for i in range ( 4 ) : #NEWLINE# #INDENT# print ( ( '%s%s %d %s dev=%s' % ( metric , FIELDS_PART [ i ] , ts , values [ ( i + 3 ) ] , device ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ( ( print >> sys . stderr ) , 'Cannot parse /proc/diskstats line: ' , line ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# sys . stdout . flush ( ) #NEWLINE# time . sleep ( COLLECTION_INTERVAL )