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, project_id, namespace, metric_name, dimensions): dimensions = utils.pack_dimensions(dimensions) expr_list = [ pycassa.create_index_expression("project_id", project_id), pycassa.create_index_expression("name", metric_name), pycassa.create_index_expression("namespace", namespace), pycassa.create_index_expression("dimensions", dimensions) ] index_clause = pycassa.create_index_clause(expr_list) items = self.cf_metric.get_indexed_slices(index_clause) for k, v in items: return k else: return None