#NEWLINE# def testReturnsAllDataByDefault( self ) : #NEWLINE# #INDENT# 'Checks that stats collection works.' #NEWLINE# stats . STATS . RegisterCounterMetric ( 'grr_client_received_bytes' ) #NEWLINE# stats . STATS . IncrementCounter ( 'grr_client_received_bytes' , 1566 ) #NEWLINE# stats . STATS . RegisterCounterMetric ( 'grr_client_sent_bytes' ) #NEWLINE# stats . STATS . IncrementCounter ( 'grr_client_sent_bytes' , 2000 ) #NEWLINE# results = self . RunAction ( 'GetClientStats' , grr_worker = MockClientWorker ( ) , arg = rdf_client . GetClientStatsRequest ( ) ) #NEWLINE# response = results [ 0 ] #NEWLINE# self . assertEqual ( response . bytes_received , 1566 ) #NEWLINE# self . assertEqual ( response . bytes_sent , 2000 ) #NEWLINE# self . assertEqual ( len ( response . cpu_samples ) , 3 ) #NEWLINE# for i in range ( 3 ) : #NEWLINE# #INDENT# self . assertEqual ( response . cpu_samples [ i ] . timestamp , rdfvalue . RDFDatetime ( ) . FromSecondsFromEpoch ( ( 100 + ( i * 10 ) ) ) ) #NEWLINE# self . assertAlmostEqual ( response . cpu_samples [ i ] . user_cpu_time , 0.1 ) #NEWLINE# self . assertAlmostEqual ( response . cpu_samples [ i ] . system_cpu_time , ( 0.1 * ( i + 1 ) ) ) #NEWLINE# self . assertAlmostEqual ( response . cpu_samples [ i ] . cpu_percent , ( 10.0 + ( 5 * i ) ) ) #NEWLINE# #UNINDENT# self . assertEqual ( len ( response . io_samples ) , 3 ) #NEWLINE# for i in range ( 3 ) : #NEWLINE# #INDENT# self . assertEqual ( response . io_samples [ i ] . timestamp , rdfvalue . RDFDatetime ( ) . FromSecondsFromEpoch ( ( 100 + ( i * 10 ) ) ) ) #NEWLINE# self . assertEqual ( response . io_samples [ i ] . read_bytes , ( 100 * ( i + 1 ) ) ) #NEWLINE# self . assertEqual ( response . io_samples [ i ] . write_bytes , ( 100 * ( i + 1 ) ) ) #NEWLINE# #UNINDENT# self . assertEqual ( response . boot_time , long ( ( 100 * 1000000.0 ) ) )