def get_metric_key_or_create(self, project_id, namespace, metric_name, dimensions, unit='None'): # get metric key key = None try: key = self.get_metric_key(project_id, namespace, metric_name, dimensions) except Exception as e: LOG.exception(e) # or create metric if not key: json_dim = utils.pack_dimensions(dimensions) key = utils.generate_metric_key(project_id, namespace, metric_name, dimensions) columns = {'project_id': project_id, 'namespace': namespace, 'name': metric_name, 'dimensions': json_dim, 'unit': unit or 'None', 'updated_timestamp': datetime.utcnow(), 'created_timestamp': datetime.utcnow()} self.cf_metric.insert(key=key, columns=columns) LOG.info("New metric is created (%s, %s)" % (key, columns)) return key
def get_metric_key_or_create(self, project_id, namespace, metric_name, dimensions, unit='None'): # get metric key key = None try: key = self.get_metric_key(project_id, namespace, metric_name, dimensions) except Exception as e: LOG.exception(e) # or create metric if not key: json_dim = utils.pack_dimensions(dimensions) key = utils.generate_metric_key(project_id, namespace, metric_name, dimensions) columns = { 'project_id': project_id, 'namespace': namespace, 'name': metric_name, 'dimensions': json_dim, 'unit': unit or 'None', 'updated_timestamp': datetime.utcnow(), 'created_timestamp': datetime.utcnow() } self.cf_metric.insert(key=key, columns=columns) LOG.info("New metric is created (%s, %s)" % (key, columns)) return key
def get_metric_key(self, message): project_id = message['project_id'] namespace = message['namespace'] metric_name = message['metric_name'] dimensions = message['dimensions'] unit = message['unit'] key = utils.generate_metric_key(project_id, namespace, metric_name, dimensions) memory_key = "metric_%s" % str(key) metric_key = self.mc.get(memory_key) if not metric_key: metric_key = self.cass.get_metric_key_or_create(project_id, namespace, metric_name, dimensions, unit) self.mc.set(memory_key, metric_key, 3000) return metric_key
def get_metric_key(self, message): project_id = message['project_id'] namespace = message['namespace'] metric_name = message['metric_name'] dimensions = message['dimensions'] unit = message['unit'] key = utils.generate_metric_key(project_id, namespace, metric_name, dimensions) memory_key = "metric_%s" % str(key) metric_key = self.mc.get(memory_key) if not metric_key: metric_key = self.cass.get_metric_key_or_create( project_id, namespace, metric_name, dimensions, unit) self.mc.set(memory_key, metric_key, 3000) return metric_key