Exemple #1
0
class FloatingIPPollster(plugin.PollsterBase):

    LOG = log.getLogger(__name__ + '.floatingip')

    def get_counters(self, manager, context):
        try:
            ips = manager.db.floating_ip_get_all_by_host(context, manager.host)
        except exception.FloatingIpNotFoundForHost:
            pass
        else:
            for ip in ips:
                self.LOG.info("FLOATING IP USAGE: %s" % ip.address)
                yield counter.Counter(source='?',
                                      name='floating_ip',
                                      type='delta',
                                      volume=1,
                                      user_id=None,
                                      project_id=ip.project_id,
                                      resource_id=ip.id,
                                      timestamp=None,
                                      duration=None,
                                      resource_metadata={
                                          'address': ip.address,
                                          'fixed_ip_id': ip.fixed_ip_id,
                                          'host': ip.host,
                                          'pool': ip.pool,
                                          'auto_assigned': ip.auto_assigned
                                      })
Exemple #2
0
class CPUPollster(plugin.PollsterBase):

    LOG = log.getLogger(__name__ + '.cpu')

    def get_counters(self, manager, context):
        conn = nova.virt.connection.get_connection(read_only=True)
        # FIXME(dhellmann): How do we get a list of instances without
        # talking directly to the database?
        for instance in manager.db.instance_get_all_by_host(
                context, manager.host):
            self.LOG.info('checking instance %s', instance.uuid)
            try:
                cpu_info = conn.get_info(instance)
                self.LOG.info("CPUTIME USAGE: %s %d", instance,
                              cpu_info['cpu_time'])
                yield make_counter_from_instance(
                    instance,
                    name='cpu',
                    type='cumulative',
                    volume=cpu_info['cpu_time'],
                )
            except Exception as err:
                self.LOG.error('could not get CPU time for %s: %s',
                               instance.uuid, err)
                self.LOG.exception(err)
Exemple #3
0
class DiskIOPollster(plugin.PollsterBase):

    LOG = log.getLogger(__name__ + '.diskio')

    def _get_disks(self, conn, instance):
        """Get disks of an instance, only used to bypass bug#998089."""
        domain = conn._conn.lookupByName(instance)
        tree = etree.fromstring(domain.XMLDesc(0))
        return filter(bool, [
            target.get('dev') for target in tree.findall('devices/disk/target')
        ])

    def get_counters(self, manager, context):
        if FLAGS.connection_type == 'libvirt':
            conn = nova.virt.connection.get_connection(read_only=True)
            for instance in manager.db.instance_get_all_by_host(
                    context, manager.host):
                # TODO(jd) This does not work see bug#998089
                # for disk in conn.get_disks(instance.name):
                try:
                    disks = self._get_disks(conn, instance.name)
                except Exception as err:
                    self.LOG.warning('Ignoring instance %s: %s', instance.name,
                                     err)
                    self.LOG.exception(err)
                    continue
                bytes = 0
                for disk in disks:
                    stats = conn.block_stats(instance.name, disk)
                    self.LOG.info(
                        "DISKIO USAGE: %s %s:"
                        "read-requests=%d read-bytes=%d write-requests=%d write-bytes=%d errors=%d",
                        instance, disk, stats[0], stats[1], stats[2], stats[3],
                        stats[4])
                    bytes += stats[1] + stats[3]  # combine read and write
                yield make_counter_from_instance(
                    instance,
                    name='disk',
                    type='cumulative',
                    volume=bytes / MIB,
                )
Exemple #4
0
from ceilometer import rpc
from ceilometer.collector import dispatcher
from ceilometer import storage
from ceilometer.openstack.common import cfg
from ceilometer.openstack.common.rpc import dispatcher as rpc_dispatcher

# FIXME(dhellmann): There must be another way to do this.
# Import rabbit_notifier to register notification_topics flag
import nova.notifier.rabbit_notifier
try:
    import nova.openstack.common.rpc as nova_rpc
except ImportError:
    # For Essex
    import nova.rpc as nova_rpc

LOG = log.getLogger(__name__)


COMPUTE_COLLECTOR_NAMESPACE = 'ceilometer.collector.compute'


class CollectorManager(manager.Manager):

    def init_host(self):
        # Use the nova configuration flags to get
        # a connection to the RPC mechanism nova
        # is using.
        self.connection = nova_rpc.create_connection()

        storage.register_opts(cfg.CONF)
        self.storage_engine = storage.get_engine(cfg.CONF)
Exemple #5
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Given an incoming message, process it through the registered converters
and publish the results.
"""

import pkg_resources

from ceilometer import log

LOG = log.getLogger(__name__)


class NotificationDispatcher(object):
    """Manages invoking plugins to convert notification messages to counters.
    """
    def __init__(self, plugin_namespace, publish_func):
        self.plugin_namespace = plugin_namespace
        self.publish_func = publish_func
        self.handlers = {}
        self._load_plugins()

    def _load_plugins(self):
        # Listen for notifications from nova
        for ep in pkg_resources.iter_entry_points(self.plugin_namespace):
            LOG.info('attempting to load notification handler for %s:%s',
Exemple #6
0
 def test_child_log_level(self):
     cfg.CONF.log_level = "info"
     log.setup()
     self.assertEqual(logging.INFO, log.getLogger('ceilometer.foobar').getEffectiveLevel())
Exemple #7
0
 def setUp(self):
     super(LoggerTestCase, self).setUp()
     self.log = log.getLogger()
Exemple #8
0
 def test_child_log_level(self):
     cfg.CONF.log_level = "info"
     log.setup()
     self.assertEqual(
         logging.INFO,
         log.getLogger('ceilometer.foobar').getEffectiveLevel())
Exemple #9
0
 def setUp(self):
     super(LoggerTestCase, self).setUp()
     self.log = log.getLogger()