From: Paul Cuzner Date: Thu, 6 Jul 2017 23:29:06 +0000 (+1200) Subject: common: changes to the Disk class X-Git-Tag: v1.0~44^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c14e68e3db878dfc0d78be21bc10718b213cc5cb;p=cephmetrics.git common: changes to the Disk class Two main things; 1. Disk instances are now initialized here, instead of with the caller devices simplying code in the osd class 2. get_real_dev function added to convert a device name of an OSD to the name we'll use as a metric. this now provides initial support for nvme and intelcas based osd --- diff --git a/collectors/common.py b/collectors/common.py index f0072bb..24b1af0 100644 --- a/collectors/common.py +++ b/collectors/common.py @@ -188,6 +188,21 @@ class Disk(object): "osd_id": ("osd_id", "gauge") } + def __init__(self, device_name, path_name=None, osd_id=None): + + self._name = device_name + self._path_name = path_name + self.osd_id = osd_id + + self.rotational = self._get_rota() + self.disk_size = self._get_size() + self.perf = IOstat() + self.fs_size = 0 + self.fs_percent_used = 0 + self.fs_used = 0 + + self.refresh() + def _get_size(self): return int(fread("/sys/block/{}/size".format(self._name))) * 512 @@ -202,7 +217,20 @@ class Disk(object): return fs_size, fs_used, fs_percent_used def refresh(self): - self.fs_size, self.fs_used, self.fs_percent_used = self._get_fssize() + # only run the fs size update, if the _path_name is set. + if self._path_name: + self.fs_size, self.fs_used, self.fs_percent_used = self._get_fssize() + + @staticmethod + def get_real_dev(dev_name): + # for nvme and intelcas devices, just use the device name as is, but + # for sdX type devices, strip of the partition id + if dev_name.startswith(('nvme', 'intelcas')): + device = dev_name + else: + # default strip any numeric ie. sdaa1 -> sdaa + device = filter(lambda ch: ch.isalpha(), dev_name) + return device class CollectorLog(object):