Beispiel #1
0
 def publish_counter(counter):
     """Create a metering message for the counter and publish it."""
     ctxt = context.get_admin_context()
     publish.publish_counter(ctxt, counter,
                             cfg.CONF.metering_topic,
                             cfg.CONF.metering_secret,
                             cfg.CONF.counter_source)
Beispiel #2
0
 def setUp(self):
     super(TestPublish, self).setUp()
     self.notifications = []
     self.stubs.Set(rpc, 'cast', self.faux_notify)
     publish.publish_counter(None,
                             self.test_data,
                             'metering',
                             'not-so-secret',
                             'test',
                             )
Beispiel #3
0
 def periodic_tasks(self, context, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     for name, pollster in self.pollsters:
         try:
             LOG.info('polling %s', name)
             for c in pollster.get_counters(self, context):
                 LOG.info('COUNTER: %s', c)
                 publish.publish_counter(context, c)
         except Exception as err:
             LOG.warning('Continuing after error from %s: %s', name, err)
             LOG.exception(err)
Beispiel #4
0
 def periodic_tasks(self, context, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     for name, pollster in self.pollsters:
         try:
             LOG.info('polling %s', name)
             for c in pollster.get_counters(self, context):
                 LOG.info('COUNTER: %s', c)
                 publish.publish_counter(context, c)
         except Exception as err:
             LOG.warning('Continuing after error from %s: %s', name, err)
             LOG.exception(err)
Beispiel #5
0
 def poll_instance(self, context, instance):
     """Poll one instance."""
     for name, pollster in self.pollsters:
         try:
             LOG.info('polling %s', name)
             for c in pollster.get_counters(self, instance):
                 LOG.info('COUNTER: %s', c)
                 publish.publish_counter(context, c)
         except Exception as err:
             LOG.warning('Continuing after error from %s for %s: %s', name,
                         instance.name, err)
             LOG.exception(err)
Beispiel #6
0
 def poll_instance(self, context, instance):
     """Poll one instance."""
     for name, pollster in self.pollsters:
             try:
                 LOG.info('polling %s', name)
                 for c in pollster.get_counters(self, instance):
                     LOG.info('COUNTER: %s', c)
                     publish.publish_counter(context, c)
             except Exception as err:
                 LOG.warning('Continuing after error from %s for %s: %s',
                             name, instance.name, err)
                 LOG.exception(err)
    def publish_counter(env, bytes_received, bytes_sent):
        req = Request(env)
        version, account, container, obj = split_path(req.path, 1, 4, True)
        now = timeutils.utcnow().isoformat()

        if bytes_received:
            publish.publish_counter(context.get_admin_context(),
                                    counter.Counter(
                                        name='storage.objects.incoming.bytes',
                                        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={
                                            "path": req.path,
                                            "version": version,
                                            "container": container,
                                            "object": obj,
                                        },
                                    ),
                                    cfg.CONF.metering_topic,
                                    cfg.CONF.metering_secret,
                                    cfg.CONF.counter_source)

        if bytes_sent:
            publish.publish_counter(context.get_admin_context(),
                                    counter.Counter(
                                        name='storage.objects.outgoing.bytes',
                                        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={
                                            "path": req.path,
                                            "version": version,
                                            "container": container,
                                            "object": obj,
                                        }),
                                    cfg.CONF.metering_topic,
                                    cfg.CONF.metering_secret,
                                    cfg.CONF.counter_source)
Beispiel #8
0
 def periodic_tasks(self, context, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     # FIXME(dhellmann): How do we get a list of instances without
     # talking directly to the database?
     for instance in self.db.instance_get_all_by_host(context, self.host):
         for name, pollster in self.pollsters:
             try:
                 LOG.info('polling %s', name)
                 for c in pollster.get_counters(self, instance):
                     LOG.info('COUNTER: %s', c)
                     publish.publish_counter(context, c)
             except Exception as err:
                 LOG.warning('Continuing after error from %s for %s: %s',
                             name, instance.name, err)
                 LOG.exception(err)
Beispiel #9
0
 def publish_counters_from_one_pollster(ext, manager, context, instance):
     """Used to invoke the plugins loaded by the ExtensionManager.
     """
     try:
         LOG.info('polling %s', ext.name)
         for c in ext.obj.get_counters(manager, instance):
             LOG.info('COUNTER: %s', c)
             publish.publish_counter(context, c,
                                     cfg.CONF.metering_topic,
                                     cfg.CONF.metering_secret,
                                     cfg.CONF.counter_source,
                                     )
     except Exception as err:
         LOG.warning('Continuing after error from %s for %s: %s',
                     ext.name, instance.id, err)
         LOG.exception(err)
Beispiel #10
0
 def publish_counters_from_one_pollster(self, ext, manager, context,
                                        *args, **kwargs):
     """Used to invoke the plugins loaded by the ExtensionManager.
     """
     try:
         LOG.info('Polling %s', ext.name)
         for c in ext.obj.get_counters(manager, *args, **kwargs):
             LOG.debug('Publishing counter: %s', c)
             publish.publish_counter(context, c,
                                     cfg.CONF.metering_topic,
                                     cfg.CONF.metering_secret,
                                     cfg.CONF.counter_source,
                                     )
     except Exception as err:
         LOG.warning('Continuing after error from %s: %s',
                     ext.name, err)
         LOG.exception(err)
Beispiel #11
0
 def setUp(self):
     super(TestPublish, self).setUp()
     self.notifications = []
     self.stubs.Set(rpc, 'cast', self.faux_notify)
     publish.publish_counter(None, self.test_data)
Beispiel #12
0
 def _publish_counter(self, counter):
     """Create a metering message for the counter and publish it."""
     ctxt = context.get_admin_context()
     publish.publish_counter(ctxt, counter)
Beispiel #13
0
 def setUp(self):
     super(TestPublish, self).setUp()
     self.notifications = []
     self.stubs.Set(rpc, 'cast', self.faux_notify)
     self.ctx = context.RequestContext("user", "project")
     publish.publish_counter(self.ctx, self.test_data)
Beispiel #14
0
 def _publish_counter(self, counter):
     """Create a metering message for the counter and publish it."""
     ctxt = context.get_admin_context()
     publish.publish_counter(ctxt, counter)
Beispiel #15
0
    def publish_counter(self, counter):
        """Create a metering message for the counter and publish it."""

        ctx = context.get_admin_context()
        publish.publish_counter(ctx, counter, self.topic)