From 2e8641ad18648cef14916cdca7932a6075c495de Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Mon, 27 Mar 2023 22:34:00 +0200 Subject: [PATCH] Smooth out old data to avoid false positives in disk full prediction --- process_queue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/process_queue b/process_queue index 28b73bd..3510ae2 100644 --- a/process_queue +++ b/process_queue @@ -4,6 +4,7 @@ import logging import logging.config import os import socket +import statistics import time from ltsdb_json import LTS @@ -44,12 +45,13 @@ class DiskFullPredictor: current_used_bytes = lts.data[-1][1] current_usable_bytes = usable_lts.data[-1][1] tuf = 1E9 - for d in reversed(lts.data): - if d[1] < current_usable_bytes * 0.1: + for i in reversed(range(len(lts.data))): + m = statistics.mean(x[1] for x in lts.data[max(0, i - 2) : min(len(lts.data), i + 3)]) + if m < current_usable_bytes * 0.1: continue # for sanity - if current_used_bytes ** 2 / d[1] > current_usable_bytes: - log.info("d = %s, current_used_bytes = %s, current_usable_bytes = %s", d, current_used_bytes, current_usable_bytes) - tuf = now - d[0] + if current_used_bytes ** 2 / m > current_usable_bytes: + log.info("d = %s, current_used_bytes = %s, current_usable_bytes = %s", m, current_used_bytes, current_usable_bytes) + tuf = now - lts.data[i][0] break desc = {**lts.description, "measure": "time_until_disk_full",