def test_agent_memory_info(self): collector = self.get_collector() metrics = collector.object.statsd.current assert_that(metrics, has_key('gauge')) assert_that( metrics['gauge'], has_entries('amplify.agent.mem.rss', collected_metric(greater_than(0)))) assert_that( metrics['gauge'], has_entries('amplify.agent.mem.vms', collected_metric(greater_than(0))))
def test_collect(self): collector = self.get_collector() metrics = collector.object.statsd.current # check counters assert_that(metrics, has_key('counter')) for counter in ('system.net.bytes_rcvd', 'system.net.bytes_sent', 'system.net.drops_in.count', 'system.net.drops_out.count', 'system.net.listen_overflows', 'system.net.packets_in.count', 'system.net.packets_in.error', 'system.net.packets_out.count', 'system.net.packets_out.error', starts_with('system.io.iops_r|'), starts_with('system.io.iops_w|'), starts_with('system.io.kbs_r|'), starts_with('system.io.kbs_w|'), starts_with('system.net.bytes_rcvd|'), starts_with('system.net.bytes_sent|'), starts_with('system.net.drops_in.count|'), starts_with('system.net.drops_out.count|'), starts_with('system.net.packets_in.count|'), starts_with('system.net.packets_in.error|'), starts_with('system.net.packets_out.count|'), starts_with('system.net.packets_out.error|')): assert_that(metrics['counter'], has_entry(counter, collected_metric())) # check gauges assert_that(metrics, has_key('gauge')) for gauge in ('controller.agent.cpu.system', 'controller.agent.cpu.user', 'controller.agent.mem.rss', 'controller.agent.mem.vms', 'controller.agent.status', 'system.cpu.idle', 'system.cpu.iowait', 'system.cpu.stolen', 'system.cpu.system', 'system.cpu.user', 'system.disk.free', 'system.disk.in_use', 'system.disk.total', 'system.disk.used', 'system.load.1', 'system.load.15', 'system.load.5', 'system.mem.available', 'system.mem.buffered', 'system.mem.cached', 'system.mem.free', 'system.mem.pct_used', 'system.mem.total', 'system.mem.used', 'system.mem.used.all', 'system.swap.free', 'system.swap.pct_free', 'system.swap.total', 'system.swap.used', starts_with('system.disk.total|'), starts_with('system.disk.used|'), starts_with('system.disk.free|'), starts_with('system.disk.in_use|'), starts_with('system.io.wait_r|'), starts_with('system.io.wait_w|')): assert_that(metrics['gauge'], has_entry(gauge, collected_metric()))
def test_http_status_discarded(self): line_template = ( '127.0.0.1 - - [02/Jul/2015:14:49:48 +0000] "GET /basic_status HTTP/1.1" %d 110 "-" ' '"python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-48-generic"') # collect requests with $status 400 to 498 lines = [line_template % x for x in xrange(400, 499)] NginxAccessLogsCollector(object=self.fake_object, tail=lines).collect() counter = self.fake_object.statsd.flush()['metrics']['counter'] assert_that( counter, has_entries('C|nginx.http.status.4xx', collected_metric(99), 'C|nginx.http.status.discarded', collected_metric(0))) # collect single request with $status 499 tail = [line_template % 499] NginxAccessLogsCollector(object=self.fake_object, tail=tail).collect() counter = self.fake_object.statsd.flush()['metrics']['counter'] assert_that( counter, has_entries('C|nginx.http.status.4xx', collected_metric(1), 'C|nginx.http.status.discarded', collected_metric(1)))
def test_agent_memory_info(self): gauges = self.metrics['gauge'] assert_that(gauges['amplify.agent.mem.rss'], collected_metric(greater_than(0))) assert_that(gauges['amplify.agent.mem.vms'], collected_metric(greater_than(0)))
def test_collect(self): # check counters assert_that(self.metrics, has_key('counter')) counters = self.metrics['counter'] assert_that(counters, has_entry('system.net.bytes_rcvd', collected_metric())) assert_that(counters, has_entry('system.net.bytes_sent', collected_metric())) assert_that(counters, has_entry('system.net.drops_in.count', collected_metric())) assert_that(counters, has_entry('system.net.drops_out.count', collected_metric())) assert_that(counters, has_entry('system.net.listen_overflows', collected_metric())) assert_that(counters, has_entry('system.net.packets_in.count', collected_metric())) assert_that(counters, has_entry('system.net.packets_in.error', collected_metric())) assert_that(counters, has_entry('system.net.packets_out.count', collected_metric())) assert_that(counters, has_entry('system.net.packets_out.error', collected_metric())) assert_that(counters, has_entry(starts_with('system.io.iops_r|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.io.iops_w|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.io.kbs_r|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.io.kbs_w|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.bytes_rcvd|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.bytes_sent|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.drops_in.count|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.drops_out.count|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.packets_in.count|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.packets_in.error|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.packets_out.count|'), collected_metric())) assert_that(counters, has_entry(starts_with('system.net.packets_out.error|'), collected_metric())) # check gauges assert_that(self.metrics, has_key('gauge')) gauges = self.metrics['gauge'] assert_that(gauges, has_entry('amplify.agent.cpu.system', collected_metric())) assert_that(gauges, has_entry('amplify.agent.cpu.user', collected_metric())) assert_that(gauges, has_entry('amplify.agent.mem.rss', collected_metric())) assert_that(gauges, has_entry('amplify.agent.mem.vms', collected_metric())) assert_that(gauges, has_entry('amplify.agent.status', collected_metric())) assert_that(gauges, has_entry('system.cpu.idle', collected_metric())) assert_that(gauges, has_entry('system.cpu.iowait', collected_metric())) assert_that(gauges, has_entry('system.cpu.stolen', collected_metric())) assert_that(gauges, has_entry('system.cpu.system', collected_metric())) assert_that(gauges, has_entry('system.cpu.user', collected_metric())) assert_that(gauges, has_entry('system.disk.free', collected_metric())) assert_that(gauges, has_entry('system.disk.in_use', collected_metric())) assert_that(gauges, has_entry('system.disk.total', collected_metric())) assert_that(gauges, has_entry('system.disk.used', collected_metric())) assert_that(gauges, has_entry('system.load.1', collected_metric())) assert_that(gauges, has_entry('system.load.15', collected_metric())) assert_that(gauges, has_entry('system.load.5', collected_metric())) assert_that(gauges, has_entry('system.mem.available', collected_metric())) assert_that(gauges, has_entry('system.mem.buffered', collected_metric())) assert_that(gauges, has_entry('system.mem.cached', collected_metric())) assert_that(gauges, has_entry('system.mem.free', collected_metric())) assert_that(gauges, has_entry('system.mem.pct_used', collected_metric())) assert_that(gauges, has_entry('system.mem.total', collected_metric())) assert_that(gauges, has_entry('system.mem.used', collected_metric())) assert_that(gauges, has_entry('system.swap.free', collected_metric())) assert_that(gauges, has_entry('system.swap.pct_free', collected_metric())) assert_that(gauges, has_entry('system.swap.total', collected_metric())) assert_that(gauges, has_entry('system.swap.used', collected_metric())) assert_that(gauges, has_entry(starts_with('system.disk.total|'), collected_metric())) assert_that(gauges, has_entry(starts_with('system.disk.used|'), collected_metric())) assert_that(gauges, has_entry(starts_with('system.disk.free|'), collected_metric())) assert_that(gauges, has_entry(starts_with('system.disk.in_use|'), collected_metric())) assert_that(gauges, has_entry(starts_with('system.io.wait_r|'), collected_metric())) assert_that(gauges, has_entry(starts_with('system.io.wait_w|'), collected_metric()))