From fd37d8c47d9fa56ae12afe6621f6d3b90b666019 Mon Sep 17 00:00:00 2001 From: erthalion <9erthalion6@gmail.com> Date: Sat, 10 Jun 2017 21:50:34 +0200 Subject: [PATCH] Add property `wal_directory` Add property `wal_directory` to find a proper place of wal files based on Postgesql version. --- pg_view/__init__.py | 2 +- pg_view/collectors/partition_collector.py | 27 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pg_view/__init__.py b/pg_view/__init__.py index c971d0d..f34f370 100644 --- a/pg_view/__init__.py +++ b/pg_view/__init__.py @@ -250,7 +250,7 @@ def main(): # initialize the disks stat collector process and create an exchange queue q = JoinableQueue(1) work_directories = [cl['wd'] for cl in clusters if 'wd' in cl] - collector = DetachedDiskStatCollector(q, work_directories) + collector = DetachedDiskStatCollector(q, work_directories, dbver) collector.start() consumer = DiskCollectorConsumer(q) diff --git a/pg_view/collectors/partition_collector.py b/pg_view/collectors/partition_collector.py index c79e929..c0802be 100644 --- a/pg_view/collectors/partition_collector.py +++ b/pg_view/collectors/partition_collector.py @@ -20,7 +20,6 @@ class PartitionStatCollector(StatCollector): DISK_STAT_FILE = '/proc/diskstats' DATA_NAME = 'data' XLOG_NAME = 'xlog' - XLOG_SUBDIR = 'pg_xlog/' BLOCK_SIZE = 1024 def __init__(self, dbname, dbversion, work_directory, consumer): @@ -206,13 +205,29 @@ def output(self, method): class DetachedDiskStatCollector(Process): """ This class runs in a separate process and runs du and df """ - def __init__(self, q, work_directories): + OLD_WAL_SUBDIR = '/pg_xlog/' + WAL_SUBDIR = '/pg_wal/' + + NEW_WAL_SINCE = 10.0 + + def __init__(self, q, work_directories, db_version): super(DetachedDiskStatCollector, self).__init__() self.work_directories = work_directories self.q = q self.daemon = True + self.db_version = db_version self.df_cache = {} + @property + def wal_directory(self): + """ Since Postgresql 10.0 wal directory was renamed, so we need to + choose actual wal directory based on a db_version. + """ + if self.db_version < DetachedDiskStatCollector.NEW_WAL_SINCE: + return DetachedDiskStatCollector.OLD_WAL_SUBDIR + else: + return DetachedDiskStatCollector.WAL_SUBDIR + def run(self): while True: # wait until the previous data is consumed @@ -233,14 +248,14 @@ def get_du_data(self, wd): result = {'data': [], 'xlog': []} try: data_size = self.run_du(wd, BLOCK_SIZE) - xlog_size = self.run_du(wd + '/pg_xlog/', BLOCK_SIZE) + xlog_size = self.run_du(wd + self.wal_directory, BLOCK_SIZE) except Exception as e: logger.error('Unable to read free space information for the pg_xlog and data directories for the directory\ {0}: {1}'.format(wd, e)) else: # XXX: why do we pass the block size there? result['data'] = str(data_size), wd - result['xlog'] = str(xlog_size), wd + '/pg_xlog' + result['xlog'] = str(xlog_size), wd + self.wal_directory return result @staticmethod @@ -276,7 +291,7 @@ def get_df_data(self, work_directory): result = {'data': [], 'xlog': []} # obtain the device names data_dev = self.get_mounted_device(self.get_mount_point(work_directory)) - xlog_dev = self.get_mounted_device(self.get_mount_point(work_directory + '/pg_xlog/')) + xlog_dev = self.get_mounted_device(self.get_mount_point(work_directory + self.wal_directory)) if data_dev not in self.df_cache: data_vfs = os.statvfs(work_directory) self.df_cache[data_dev] = data_vfs @@ -284,7 +299,7 @@ def get_df_data(self, work_directory): data_vfs = self.df_cache[data_dev] if xlog_dev not in self.df_cache: - xlog_vfs = os.statvfs(work_directory + '/pg_xlog/') + xlog_vfs = os.statvfs(work_directory + self.wal_directory) self.df_cache[xlog_dev] = xlog_vfs else: xlog_vfs = self.df_cache[xlog_dev]