in postgresql_metrics/localhost_postgres_stats.py [0:0]
def get_amount_of_wal_files(data_dir):
amount_of_wal_files = 0
try:
if data_dir and os.path.isdir(data_dir):
wal_dir = os.path.join(data_dir, 'pg_wal')
if not os.path.isdir(wal_dir):
wal_dir = os.path.join(data_dir, 'pg_xlog')
# each WAL file is named as 24-character hexadecimal number
for possible_wal_file_name in os.listdir(wal_dir):
if re.match('^[0-9A-F]{24}$', possible_wal_file_name):
amount_of_wal_files += 1
except OSError:
LOG.exception('Failed accessing WAL files. Is data dir readable by user?')
return amount_of_wal_files