#NEWLINE# def collect( self ) : #NEWLINE# #INDENT# if self . config [ 'enable_dispersion_report' ] : #NEWLINE# #INDENT# p = Popen ( [ 'swift-dispersion-report' , '-j' ] , stdout = PIPE , stderr = PIPE ) #NEWLINE# ( stdout , stderr ) = p . communicate ( ) #NEWLINE# self . publish ( 'dispersion.errors' , ( len ( stderr . split ( '\n' ) ) - 1 ) ) #NEWLINE# data = json . loads ( stdout ) #NEWLINE# for t in ( 'object' , 'container' ) : #NEWLINE# #INDENT# for ( k , v ) in data [ t ] . items ( ) : #NEWLINE# #INDENT# self . publish ( ( 'dispersion.%s.%s' % ( t , k ) ) , v ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if self . config [ 'enable_container_metrics' ] : #NEWLINE# #INDENT# account = ( '%s:%s' % ( self . config [ 'account' ] , self . config [ 'user' ] ) ) #NEWLINE# for container in self . config [ 'containers' ] . split ( ',' ) : #NEWLINE# #INDENT# cmd = [ 'swift' , '-A' , self . config [ 'auth_url' ] , '-U' , account , '-K' , self . config [ 'password' ] , 'stat' , container ] #NEWLINE# p = Popen ( cmd , stdout = PIPE , stderr = PIPE ) #NEWLINE# ( stdout , stderr ) = p . communicate ( ) #NEWLINE# stats = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for line in stdout . split ( '\n' ) : #NEWLINE# #INDENT# if line : #NEWLINE# #INDENT# line = line . split ( ':' , 2 ) #NEWLINE# stats [ line [ 0 ] . strip ( ) ] = line [ 1 ] . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# key = ( 'container_metrics.%s.%s' % ( self . config [ 'account' ] , container ) ) #NEWLINE# self . publish ( ( '%s.objects' % key ) , stats [ 'Objects' ] ) #NEWLINE# self . publish ( ( '%s.bytes' % key ) , stats [ 'Bytes' ] ) #NEWLINE# self . publish ( ( '%s.x_timestamp' % key ) , container [ 'X-Timestamp' ] )