def processMessage(self, device_id, message, value): if value['device'] != device_id: log.error("While expecting a message for %s, received a message regarding %s instead!" % (device_id, value['device'])) return if value['type'] == 'meter': # Message is a json-serialized version of a ceilometer.storage.models.Sample object # (http://docs.openstack.org/developer/ceilometer/_modules/ceilometer/storage/models.html#Sample) # pull the information we are interested in out of the raw # ceilometer Sample data structure. resourceId = value['data']['resource_id'] meter = value['data']['counter_name'] meter_value = value['data']['counter_volume'] timestamp = amqp_timestamp_to_int(value['data']['timestamp']) now = time.time() if timestamp > now: log.debug("[%s/%s] Timestamp (%s) appears to be in the future. Using now instead." % (resourceId, meter, value['data']['timestamp'])) if timestamp < now - CACHE_EXPIRE_TIME: log.debug("[%s/%s] Timestamp (%s) is already %d seconds old- discarding message." % (resourceId, meter, value['data']['timestamp'], now - timestamp)) else: cache[device_id].add_perf(resourceId, meter, meter_value, timestamp) else: log.error("Discarding unrecognized message type: %s" % value['type'])
def processMessage(self, device_id, message, value): if value['device'] != device_id: log.error("While expecting a message for %s, received a message regarding %s instead!" % (device_id, value['device'])) return if value['type'] == 'event': # Message is a json-serialized version of a ceilometer.storage.models.Event object # (http://docs.openstack.org/developer/ceilometer/_modules/ceilometer/storage/models.html#Event) timestamp = amqp_timestamp_to_int(value['data']['generated']) log.debug("Incoming event (%s) %s" % (timestamp, value['data'])) cache[device_id].add(value['data'], timestamp) else: log.error("Discarding unrecognized message type: %s" % value['type'])
class CeilometerV1Samples(Resource): """ /ceilometer/v1/samples/<device id> : accept metrics from ceilometer """ isLeaf = True future_warning = set() def render_POST(self, request): if len(request.postpath) != 1: return NoResource().render(request) device_id = request.postpath[0] if not REGISTRY.has_device(device_id): return NoResource(message="Unrecognized device '%s'" % device_id).render(request) content_type = request.requestHeaders.getRawHeaders('content-type', [None])[0] if content_type != 'application/json': return ErrorPage(415, "Unsupported Media Type", "Unsupported Media Type").render(request) try: payload = json.loads(request.content.getvalue()) except Exception, e: log.error("%s: Error [%s] while parsing JSON data: %s", device_id, e, request.content.getvalue()) return ErrorPage(400, "Bad Request", "Error parsing JSON data: %s" % e).render(request) samples = [] now = time.time() try: for sample in payload: if 'event_type' in sample and 'volume' not in sample: return ErrorPage(422, "Unprocessable Entity", "Misconfigured- sending event data to metric URL").render(request) resourceId = sample['resource_id'] meter = sample['name'] value = sample['volume'] timestamp = amqp_timestamp_to_int(sample['timestamp']) if timestamp > now: if device_id not in self.future_warning: log.debug("%s: [%s/%s] Timestamp (%s) appears to be in the future. Using now instead.", device_id, resourceId, meter, timestamp) self.future_warning.add(device_id) timestamp = now samples.append((resourceId, meter, value, timestamp)) except Exception, e: log.exception("%s: Error processing sample data", device_id) return ErrorPage(422, "Unprocessable Entity", "Error processing data: %s" % e).render(request)
def processMessage(self, device_id, message, value): if value['device'] != device_id: log.error( "While expecting a message for %s, received a message regarding %s instead!" % (device_id, value['device'])) return if value['type'] == 'event': # Message is a json-serialized version of a ceilometer.storage.models.Event object # (http://docs.openstack.org/developer/ceilometer/_modules/ceilometer/storage/models.html#Event) timestamp = amqp_timestamp_to_int(value['data']['generated']) log.debug("Incoming event (%s) %s" % (timestamp, value['data'])) cache[device_id].add(value['data'], timestamp) else: log.error("Discarding unrecognized message type: %s" % value['type'])
def processMessage(self, device_id, message, value): if value['device'] != device_id: log.error( "While expecting a message for %s, received a message regarding %s instead!" % (device_id, value['device'])) return if value['type'] == 'meter': # Message is a json-serialized version of a ceilometer.storage.models.Sample object # (http://docs.openstack.org/developer/ceilometer/_modules/ceilometer/storage/models.html#Sample) # pull the information we are interested in out of the raw # ceilometer Sample data structure. resourceId = value['data']['resource_id'] meter = value['data']['counter_name'] meter_value = value['data']['counter_volume'] timestamp = amqp_timestamp_to_int(value['data']['timestamp']) now = time.time() if timestamp > now: log.debug( "[%s/%s] Timestamp (%s) appears to be in the future. Using now instead." % (resourceId, meter, value['data']['timestamp'])) if timestamp < now - CACHE_EXPIRE_TIME: log.debug( "[%s/%s] Timestamp (%s) is already %d seconds old- discarding message." % (resourceId, meter, value['data']['timestamp'], now - timestamp)) else: cache[device_id].add_perf(resourceId, meter, meter_value, timestamp) else: log.error("Discarding unrecognized message type: %s" % value['type'])