~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/compute/pollsters/disk.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-02-19 14:59:07 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20150219145907-9jojybdsl64zcn14
Tags: 2015.1~b2-0ubuntu1
[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/p/skip-test.patch: Rebased.

[ James Page ]
* d/rules,d/p/skip-gabbi.patch: Skip tests that rely on python-gabbi until
  packaging and MIR is complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
# Copyright 2012 Red Hat, Inc
4
4
# Copyright 2014 Cisco Systems, Inc
5
5
#
6
 
# Author: Julien Danjou <julien@danjou.info>
7
 
# Author: Eoghan Glynn <eglynn@redhat.com>
8
 
# Author: Pradeep Kilambi <pkilambi@cisco.com>
9
 
#
10
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
11
7
# not use this file except in compliance with the License. You may obtain
12
8
# a copy of the License at
27
23
from ceilometer.compute import pollsters
28
24
from ceilometer.compute.pollsters import util
29
25
from ceilometer.compute.virt import inspector as virt_inspector
30
 
from ceilometer.i18n import _
 
26
from ceilometer.i18n import _, _LW
31
27
from ceilometer.openstack.common import log
32
28
from ceilometer import sample
33
29
 
46
42
                                       'write_requests_rate',
47
43
                                       'per_disk_rate'])
48
44
 
 
45
DiskLatencyData = collections.namedtuple('DiskLatencyData',
 
46
                                         ['disk_latency',
 
47
                                          'per_disk_latency'])
 
48
 
49
49
 
50
50
@six.add_metaclass(abc.ABCMeta)
51
51
class _Base(pollsters.BaseComputePollster):
119
119
            except virt_inspector.InstanceNotFoundException as err:
120
120
                # Instance was deleted while getting samples. Ignore it.
121
121
                LOG.debug(_('Exception while getting samples %s'), err)
 
122
            except virt_inspector.InstanceShutOffException as e:
 
123
                LOG.warn(_LW('Instance %(instance_id)s was shut off while '
 
124
                             'getting samples of %(pollster)s: %(exc)s'),
 
125
                         {'instance_id': instance.id,
 
126
                          'pollster': self.__class__.__name__, 'exc': e})
122
127
            except ceilometer.NotImplementedError:
123
128
                # Selected inspector does not implement this pollster.
124
129
                LOG.debug(_('%(inspector)s does not provide data for '
462
467
                resource_id="%s-%s" % (instance.id, disk),
463
468
            ))
464
469
        return samples
 
470
 
 
471
 
 
472
@six.add_metaclass(abc.ABCMeta)
 
473
class _DiskLatencyPollsterBase(pollsters.BaseComputePollster):
 
474
 
 
475
    CACHE_KEY_DISK_LATENCY = 'disk-latency'
 
476
 
 
477
    def _populate_cache(self, inspector, cache, instance):
 
478
        i_cache = cache.setdefault(self.CACHE_KEY_DISK_LATENCY, {})
 
479
        if instance.id not in i_cache:
 
480
            latency = 0
 
481
            per_device_latency = {}
 
482
            disk_rates = inspector.inspect_disk_latency(instance)
 
483
            for disk, stats in disk_rates:
 
484
                latency += stats.disk_latency
 
485
                per_device_latency[disk.device] = (
 
486
                    stats.disk_latency)
 
487
            per_disk_latency = {
 
488
                'disk_latency': per_device_latency
 
489
            }
 
490
            i_cache[instance.id] = DiskLatencyData(
 
491
                latency,
 
492
                per_disk_latency
 
493
            )
 
494
        return i_cache[instance.id]
 
495
 
 
496
    @abc.abstractmethod
 
497
    def _get_samples(self, instance, disk_rates_info):
 
498
        """Return one or more Sample."""
 
499
 
 
500
    def get_samples(self, manager, cache, resources):
 
501
        for instance in resources:
 
502
            try:
 
503
                disk_latency_info = self._populate_cache(
 
504
                    self.inspector,
 
505
                    cache,
 
506
                    instance,
 
507
                )
 
508
                for disk_latency in self._get_samples(instance,
 
509
                                                      disk_latency_info):
 
510
                    yield disk_latency
 
511
            except virt_inspector.InstanceNotFoundException as err:
 
512
                # Instance was deleted while getting samples. Ignore it.
 
513
                LOG.debug(_('Exception while getting samples %s'), err)
 
514
            except ceilometer.NotImplementedError:
 
515
                # Selected inspector does not implement this pollster.
 
516
                LOG.debug(_('%(inspector)s does not provide data for '
 
517
                            ' %(pollster)s'),
 
518
                          {'inspector': self.inspector.__class__.__name__,
 
519
                           'pollster': self.__class__.__name__})
 
520
            except Exception as err:
 
521
                instance_name = util.instance_name(instance)
 
522
                LOG.exception(_('Ignoring instance %(name)s: %(error)s'),
 
523
                              {'name': instance_name, 'error': err})
 
524
 
 
525
 
 
526
class DiskLatencyPollster(_DiskLatencyPollsterBase):
 
527
 
 
528
    def _get_samples(self, instance, disk_latency_info):
 
529
        return [util.make_sample_from_instance(
 
530
            instance,
 
531
            name='disk.latency',
 
532
            type=sample.TYPE_GAUGE,
 
533
            unit='ms',
 
534
            volume=disk_latency_info.disk_latency / 1000
 
535
        )]
 
536
 
 
537
 
 
538
class PerDeviceDiskLatencyPollster(_DiskLatencyPollsterBase):
 
539
 
 
540
    def _get_samples(self, instance, disk_latency_info):
 
541
        samples = []
 
542
        for disk, value in six.iteritems(disk_latency_info.per_disk_latency[
 
543
                'disk_latency']):
 
544
            samples.append(util.make_sample_from_instance(
 
545
                instance,
 
546
                name='disk.device.latency',
 
547
                type=sample.TYPE_GAUGE,
 
548
                unit='ms',
 
549
                volume=value / 1000,
 
550
                resource_id="%s-%s" % (instance.id, disk)
 
551
            ))
 
552
        return samples