"""
return self.data['status']['message']
+ @property
+ def tag(self):
+ return 'application-%s' % self.name
+
async def add_relation(self, local_relation, remote_relation):
"""Add a relation to another application.
"""
pass
+
+ async def get_metrics(self):
+ return await self.model.get_metrics(self.tag)
def charmstore(self):
return self._charmstore
+ async def get_metrics(self, *tags):
+ """Retrieve metrics.
+
+ :param str \*tags: Tags of entities from which to retrieve metrics.
+ No tags retrieves the metrics of all units in the model.
+ """
+ log.debug("Retrieving metrics for %s",
+ ', '.join(tags) if tags else "all units")
+
+ metrics_facade = client.MetricsDebugFacade()
+ metrics_facade.connect(self.connection)
+
+ entities = [client.Entity(tag) for tag in tags]
+ metrics_result = await metrics_facade.GetMetrics(entities)
+
+ metrics = collections.defaultdict(list)
+
+ for entity_metrics in metrics_result.results:
+ error = entity_metrics.error
+ if error:
+ if "is not a valid tag" in error:
+ raise ValueError(error.message)
+ else:
+ raise Exception(error.message)
+
+ for metric in entity_metrics.metrics:
+ metrics[metric.unit].append(metric.to_json())
+
+ return metrics
+
class BundleHandler(object):
"""
# that case, we simply return False, as a destroyed unit
# is not a leader.
return False
+
+ async def get_metrics(self):
+ metrics = await self.model.get_metrics(self.tag)
+ return metrics[self.name]