Example #1
0
 def verify_metrics(self, cache, expected_metrics):
     infos = cache.get_monitoring_infos()
     # Reconstruct metrics dictionary from monitoring infos
     metrics = {
         info.urn.rsplit(':', 1)[1]:
         monitoring_infos.extract_gauge_value(info)[1]
         for info in infos if "_total" not in info.urn
         and info.type == monitoring_infos.LATEST_INT64_TYPE
     }
     self.assertDictEqual(metrics, expected_metrics)
     # Metrics and total metrics should be identical for a single bundle.
     # The following two gauges are not part of the total metrics:
     try:
         del metrics['capacity']
         del metrics['size']
     except KeyError:
         pass
     total_metrics = {
         info.urn.rsplit(':', 1)[1].rsplit("_total")[0]:
         monitoring_infos.extract_counter_value(info)
         for info in infos if "_total" in info.urn
         and info.type == monitoring_infos.SUM_INT64_TYPE
     }
     self.assertDictEqual(metrics, total_metrics)
 def test_int64_user_gauge(self):
     metric = GaugeCell().get_cumulative()
     result = monitoring_infos.int64_user_gauge('gaugenamespace',
                                                'gaugename', metric)
     _, gauge_value = monitoring_infos.extract_gauge_value(result)
     self.assertEqual(0, gauge_value)