'Checks that stats collection works.'

def testReturnsAllDataByDefault(self):

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