class CTXPerfDataRegistry(CTXPropRegistry): """In charge of ctx perfdata properties. """ __datatype__ = 'perfdata' #: default datatype name def __init__(self, *args, **kwargs): super(CTXPerfDataRegistry, self).__init__(*args, **kwargs) self.manager = PerfData() def _do(self, cmd, ids, *args, **kwargs): result = [] if ids is None: metrics = self.manager.context.find(_type='metric') ids = [metric['_id'] for metric in metrics] entity_id_field = self._entity_id_field() for entity_id in ids: cmdresult = cmd(metric_id=entity_id, **kwargs) if isinstance(cmdresult, list): result += [ {entity_id_field: entity_id, 'point': point} for point in cmdresult ] else: item = {entity_id_field: entity_id, 'result': cmdresult} result.append(item) return result def _get(self, ids, query, *args, **kwargs): return self._do(cmd=self.manager.get, ids=ids, with_tags=False) def _count(self, ids, query, *args, **kwargs): return self._do(cmd=self.manager.count, ids=ids) def _delete(self, ids, query, *args, **kwargs): return self._do(cmd=self.manager.remove, ids=ids) def ids(self, query=None): result = self.manager.get_metrics(query=query) return result