Esempio n. 1
0
    def _stats_lookup(self):
        """
        Grab the disk stats from /proc
        """

        now = int(time.time())
        interval = now - self.timestamp
        self.timestamp = now

        for perf_entry in freadlines('/proc/diskstats'):

            field = perf_entry.split()
            dev_name = field[2]

            if dev_name in self.osd.keys():
                new_stats = field[3:]
                device = self.osd[dev_name]
                if device.perf._current:
                    device.perf._previous = device.perf._current
                    device.perf._current = new_stats
                else:
                    device.perf._current = new_stats

                device.perf.compute(interval)
                device.refresh()
Esempio n. 2
0
    def _stats_lookup(self):
        """
        Grab the disk stats from /proc
        """

        now = time.time()
        interval = int(now) - self.timestamp
        self.timestamp = int(now)

        for perf_entry in freadlines('/proc/diskstats'):

            field = perf_entry.split()
            dev_name = field[2]

            if dev_name in self.osd.keys():
                new_stats = field[3:]
                device = self.osd[dev_name]
                if device.perf._current:
                    device.perf._previous = device.perf._current
                    device.perf._current = new_stats
                else:
                    device.perf._current = new_stats

                device.perf.compute(interval)
                device.refresh()

        end = time.time()
        self.elapsed_log_msg("disk performance stats generation", (end - now))
Esempio n. 3
0
    def _dev_to_osd(self):
        """
        Look at the system to determine which disks are acting as OSD's
        """

        osd_indicators = {'var', 'lib', 'osd'}

        for mnt in freadlines('/proc/mounts'):
            items = mnt.split(' ')
            dev_path, path_name = items[:2]
            if path_name.startswith('/var/lib'):
                # take a close look since this is where ceph osds usually
                # get mounted
                dirs = set(path_name.split('/'))
                if dirs.issuperset(osd_indicators):
                    osd_id = path_name.split('-')[-1]

                    device = filter(lambda ch: ch.isalpha(),
                                    dev_path.split('/')[-1])

                    if device not in self.osd:
                        disk = Disk()
                        disk._name = device
                        disk._path_name = path_name
                        disk.osd_id = osd_id
                        disk.rotational = disk._get_rota()
                        disk.perf = IOstat()
                        disk.disk_size = disk._get_size()
                        disk.refresh()
                        self.osd[device] = disk
Esempio n. 4
0
    def probe(self):
        """
        set up which collector(s) to use, based on what types of sockets we
        find in /var/run/ceph
        """

        mon_socket = '/var/run/ceph/{}-mon.{}.asok'.format(
            self.cluster_name, self.host_name)
        if os.path.exists(mon_socket):
            self.mon_socket = mon_socket
            self.mon = Mon(self.cluster_name, admin_socket=mon_socket)

        rgw_socket_list = glob.glob('/var/run/ceph/{}-client.rgw.{}.'
                                    '*.asok'.format(self.cluster_name,
                                                    self.host_name))
        if rgw_socket_list:
            rgw_socket = rgw_socket_list[0]
            self.rgw = RGW(self.cluster_name, admin_socket=rgw_socket)

        osd_socket_list = glob.glob('/var/run/ceph/{}-osd.*'
                                    '.asok'.format(self.cluster_name))
        mounted = freadlines('/proc/mounts')
        osds_mounted = [
            mnt for mnt in mounted
            if mnt.split()[1].startswith('/var/lib/ceph')
        ]
        if osd_socket_list or osds_mounted:
            self.osd = OSDs(self.cluster_name)

        collectd.info("{}: Roles detected - mon:{} "
                      "osd:{} rgw:{}".format(__name__,
                                             isinstance(self.mon, Mon),
                                             isinstance(self.osd, OSDs),
                                             isinstance(self.rgw, RGW)))
Esempio n. 5
0
    def _stats_lookup(self):
        """
        Grab the disk stats from /proc/diskstats, and the key osd perf dump
        counters
        """

        now = time.time()
        interval = int(now) - self.timestamp
        self.timestamp = int(now)

        # Fetch diskstats from the OS
        for perf_entry in freadlines('/proc/diskstats'):

            field = perf_entry.split()
            dev_name = field[2]

            device = None
            if self.dev_lookup.get(dev_name, None) == 'osd':
                device = self.osd[dev_name]
            elif self.dev_lookup.get(dev_name, None) == 'jrnl':
                device = self.jrnl[dev_name]

            if device:
                new_stats = field[3:]

                if device.perf._current:
                    device.perf._previous = device.perf._current
                    device.perf._current = new_stats
                else:
                    device.perf._current = new_stats

                device.perf.compute(interval)

        end = time.time()
        self.logger.debug("OS disk stats calculated in "
                          "{:.4f}s".format(end - now))

        # fetch stats from each osd daemon
        osd_stats_start = time.time()
        for osd_id in self.osd_id_list:

            osd_type = self.osd[osd_id]._osd_type

            if osd_type in OSDs.supported_object_stores:

                osd_stats = self._fetch_osd_stats(osd_id, osd_type)
                osd_device = self.osd[osd_id]
                osd_device.update(osd_stats)

            else:
                self.logger.warning("Unknown OSD type encountered for "
                                    "osd.{}".format(osd_id))

        osd_stats_end = time.time()
        self.logger.debug(
            "OSD perf dump stats collected for {} OSDs "
            "in {:.3f}s".format(len(self.osd_id_list),
                                (osd_stats_end - osd_stats_start)))
Esempio n. 6
0
    def _dev_to_osd(self):
        """
        Look at the system to determine which disks are acting as OSD's
        """

        # the logic here uses the mount points to determine which OSD's are
        # in the system - so the focus is on filestore (XFS) OSD's. Another
        # approach could be to go directly to the admin socket (status cmd)
        # to get the osd_fsid, and then lookup that in /dev/disk/by-partuuid
        # to derive the osd device name...

        osd_indicators = {'var', 'lib', 'osd'}

        for mnt in freadlines('/proc/mounts'):
            items = mnt.split(' ')
            dev_path, path_name = items[:2]
            if path_name.startswith('/var/lib'):
                # take a close look since this is where ceph osds usually
                # get mounted
                dirs = set(path_name.split('/'))
                if dirs.issuperset(osd_indicators):
                    osd_id = path_name.split('-')[-1]

                    osd_device = dev_path.split('/')[-1]

                    if osd_device not in self.osd:
                        self.osd[osd_device] = Disk(osd_device,
                                                    path_name=path_name,
                                                    osd_id=osd_id)
                        self.dev_lookup[osd_device] = 'osd'

                    if osd_id not in self.osd:
                        self.osd[osd_id] = OSDstats()
                        self.osd_id_list.append(osd_id)

                    journal_link = os.path.join(path_name, 'journal')
                    if os.path.exists(journal_link):
                        # this is a filestore based OSD
                        jrnl_path = os.path.realpath(journal_link)
                        jrnl_dev = jrnl_path.split('/')[-1]

                        if jrnl_dev not in self.osd:
                            self.jrnl[jrnl_dev] = Disk(jrnl_dev,
                                                       osd_id=osd_id)

                            self.dev_lookup[jrnl_dev] = 'jrnl'

                    else:
                        # No journal..?
                        pass
Esempio n. 7
0
    def _stats_lookup(self):
        """
        Grab the disk stats from /proc
        """

        now = time.time()
        interval = int(now) - self.timestamp
        self.timestamp = int(now)

        # Fetch diskstats from the OS
        for perf_entry in freadlines('/proc/diskstats'):

            field = perf_entry.split()
            dev_name = field[2]

            device = None
            if self.dev_lookup.get(dev_name, None) == 'osd':
                device = self.osd[dev_name]
            elif self.dev_lookup.get(dev_name, None) == 'jrnl':
                device = self.jrnl[dev_name]

            if device:
                new_stats = field[3:]

                if device.perf._current:
                    device.perf._previous = device.perf._current
                    device.perf._current = new_stats
                else:
                    device.perf._current = new_stats
                
                device.perf.compute(interval)
                device.refresh()

        # fetch stats from each osd daemon
        for osd_id in self.osd_id_list:
            osd_stats = self._fetch_osd_stats(osd_id)
            self.logger.debug('stats : {}'.format(osd_stats))
            osd_device = self.osd[osd_id]
            osd_device.update(osd_stats)

        end = time.time()
        self.elapsed_log_msg("disk performance stats generation", (end - now))
Esempio n. 8
0
    def _dev_to_osd(self):
        """
        Look at the system to determine which disks are acting as OSD's
        """

        # the logic here uses the mount points to determine which OSD's are
        # in the system. The encryption state is determine just by the use
        # devicemapper (i.e. /dev/mapper prefixed devices) - since at this time
        # this is all dm is used for.

        osd_indicators = {'var', 'lib', 'osd'}

        for mnt in freadlines('/proc/mounts'):
            items = mnt.split(' ')
            dev_path, path_name = items[:2]
            if path_name.startswith('/var/lib'):
                # take a close look since this is where ceph osds usually
                # get mounted
                dirs = set(path_name.split('/'))
                if dirs.issuperset(osd_indicators):

                    # get the osd_id from the name is the most simple way
                    # to get the id, due to naming conventions. If this fails
                    # though, plan 'b' is the whoami file
                    osd_id = path_name.split('-')[-1]
                    if not osd_id.isdigit():
                        osd_id = fread(os.path.join(path_name, 'whoami'))

                    if osd_id not in self.osd:
                        osd_type = OSDs.get_osd_type(path_name)
                        self.osd[osd_id] = OSDstats(osd_type=osd_type)
                        self.osd_id_list.append(osd_id)

                        osd_type = self.osd[osd_id]._osd_type
                        if osd_type == 'filestore':
                            if dev_path.startswith('/dev/mapper'):
                                encrypted = 1
                                uuid = dev_path.split('/')[-1]
                                partuuid = '/dev/disk/by-partuuid/{}'.format(
                                    uuid)
                                dev_path = os.path.realpath(partuuid)
                                osd_device = dev_path.split('/')[-1]
                            else:
                                encrypted = 0
                                osd_device = dev_path.split('/')[-1]

                        elif osd_type == 'bluestore':
                            block_link = os.path.join(path_name, 'block')
                            osd_path = os.path.realpath(block_link)
                            osd_device = osd_path.split('/')[-1]
                            encrypted = 0
                        else:
                            raise ValueError("Unknown OSD type encountered")

                        # if the osd_id hasn't been seem neither has the
                        # disk
                        self.osd[osd_device] = Disk(osd_device,
                                                    path_name=path_name,
                                                    osd_id=osd_id,
                                                    in_osd_type=osd_type,
                                                    encrypted=encrypted)
                        self.dev_lookup[osd_device] = 'osd'
                        self.osd_count += 1

                        if osd_type == 'filestore':
                            journal_link = os.path.join(path_name, 'journal')
                        else:
                            journal_link = os.path.join(path_name, 'block.wal')

                        if os.path.exists(journal_link):
                            link_tgt = os.readlink(journal_link)
                            if link_tgt.startswith('/dev/mapper'):
                                encrypted = 1
                            else:
                                encrypted = 0

                            partuuid_path = os.path.join(
                                '/dev/disk/by-partuuid',
                                link_tgt.split('/')[-1])
                            jrnl_path = os.path.realpath(partuuid_path)
                            jrnl_dev = jrnl_path.split('/')[-1]

                            if jrnl_dev not in self.osd:
                                self.jrnl[jrnl_dev] = Disk(
                                    jrnl_dev,
                                    osd_id=osd_id,
                                    in_osd_type=osd_type,
                                    encrypted=encrypted)

                                self.dev_lookup[jrnl_dev] = 'jrnl'

                        else:
                            # No journal or WAL link..?
                            pass