def publish_counter(self, env, bytes_received, bytes_sent): req = REQUEST.Request(env) version, account, container, obj = split_path(req.path, 1, 4, True) now = timeutils.utcnow().isoformat() resource_metadata = { "path": req.path, "version": version, "container": container, "object": obj, } for header in self.metadata_headers: if header.upper() in req.headers: resource_metadata['http_header_%s' % header] = req.headers.get( header.upper()) with pipeline.PublishContext( context.get_admin_context(), cfg.CONF.counter_source, self.pipeline_manager.pipelines, ) as publisher: if bytes_received: publisher([counter.Counter( name='storage.objects.incoming.bytes', type=counter.TYPE_DELTA, unit='B', volume=bytes_received, user_id=env.get('HTTP_X_USER_ID'), project_id=env.get('HTTP_X_TENANT_ID'), resource_id=account.partition('AUTH_')[2], timestamp=now, resource_metadata=resource_metadata)]) if bytes_sent: publisher([counter.Counter( name='storage.objects.outgoing.bytes', type=counter.TYPE_DELTA, unit='B', volume=bytes_sent, user_id=env.get('HTTP_X_USER_ID'), project_id=env.get('HTTP_X_TENANT_ID'), resource_id=account.partition('AUTH_')[2], timestamp=now, resource_metadata=resource_metadata)]) # publish the event for each request # request method will be recorded in the metadata resource_metadata['method'] = req.method.lower() publisher([counter.Counter( name='storage.api.request', type=counter.TYPE_DELTA, unit='request', volume=1, user_id=env.get('HTTP_X_USER_ID'), project_id=env.get('HTTP_X_TENANT_ID'), resource_id=account.partition('AUTH_')[2], timestamp=now, resource_metadata=resource_metadata)])
def __init__(self, agent_manager): self.manager = agent_manager self.pollsters = set() # Resource definitions are indexed by the pollster # Use dict of set here to remove the duplicated resource definitions # for each pollster. self.resources = collections.defaultdict(set) self.publish_context = pipeline.PublishContext(agent_manager.context)
def add(self, pollster, pipeline): if pipeline.source.name not in self.publishers: publish_context = publish_pipeline.PublishContext( self.manager.context) self.publishers[pipeline.source.name] = publish_context self.publishers[pipeline.source.name].add_pipelines([pipeline]) self.pollster_matches[pipeline.source.name].add(pollster) key = Resources.key(pipeline.source.name, pollster) self.resources[key].setup(pipeline)
def __init__(self, agent_manager): self.manager = agent_manager self.pollsters = set() # we extend the amalgamation of all static resources for this # set of pollsters with a common interval, so as to also # include any dynamically discovered resources specific to # the matching pipelines (if either is present, the per-agent # default discovery is overridden) resource_factory = lambda: Resources(agent_manager) self.resources = collections.defaultdict(resource_factory) self.publish_context = pipeline.PublishContext(agent_manager.context)
def post(self, body): """Post a list of new Samples to Ceilometer. :param body: a list of samples within the request body. """ # Note: # 1) the above validate decorator seems to do nothing. # 2) the mandatory options seems to also do nothing. # 3) the body should already be in a list of Sample's def get_consistent_source(): '''Find a source that can be applied across the sample group or raise InvalidInput if the sources are inconsistent. If all are None - use the configured counter_source If any sample has source set then the others must be the same or None. ''' source = None for s in samples: if source and s.source: if source != s.source: raise wsme.exc.InvalidInput('source', s.source, 'can not post Samples %s' % 'with different sources') if s.source and not source: source = s.source return source or pecan.request.cfg.counter_source samples = [Sample(**b) for b in body] now = timeutils.utcnow() auth_project = acl.get_limited_to_project(pecan.request.headers) source = get_consistent_source() for s in samples: if self._id != s.counter_name: raise wsme.exc.InvalidInput('counter_name', s.counter_name, 'should be %s' % self._id) if auth_project and auth_project != s.project_id: # non admin user trying to cross post to another project_id auth_msg = 'can not post samples to other projects' raise wsme.exc.InvalidInput('project_id', s.project_id, auth_msg) if s.timestamp is None or s.timestamp is wsme.Unset: s.timestamp = now s.source = '%s:%s' % (s.project_id, source) with pipeline.PublishContext( context.get_admin_context(), source, pecan.request.pipeline_manager.pipelines, ) as publisher: publisher([counter.Counter( name=s.counter_name, type=s.counter_type, unit=s.counter_unit, volume=s.counter_volume, user_id=s.user_id, project_id=s.project_id, resource_id=s.resource_id, timestamp=s.timestamp.isoformat(), resource_metadata=s.resource_metadata) for s in samples]) # TODO(asalkeld) this is not ideal, it would be nice if the publisher # returned the created sample message with message id (or at least the # a list of message_ids). return samples
def __init__(self, agent_manager): self.manager = agent_manager self.pollsters = set() self.publish_context = pipeline.PublishContext( agent_manager.context, cfg.CONF.counter_source)
def __init__(self, agent_manager): self.manager = agent_manager self.pollsters = set() self.publish_context = pipeline.PublishContext( agent_manager.context)