mirror of
https://github.com/PegaProx/project-pegaprox.git
synced 2026-08-12 15:27:47 +08:00
We were using a plain logging.FileHandler with no rotation, so on busy clusters (20+ nodes) the per-cluster .log can grow ~100 MB/h until disk runs out — the supplied VM image hit this in #348. New CappedTimedFileHandler in pegaprox/utils/log_handler.py: rotates every 6h and discards the rotated content (we don't need historical operational logs, audit log is separate). Disk use bounded at ~one hour-bucket of writes, regardless of cluster size or activity. Wired in for both PegaProxManager and XcpngManager. log_handler.py added to update_files so update.sh actually pulls it.
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""Bounded file log handler.
|
|
|
|
Keeps the active .log file from growing unbounded on busy clusters
|
|
(20+ nodes can produce ~100 MB/h, see #345 / #348).
|
|
"""
|
|
import os
|
|
import time
|
|
from logging.handlers import TimedRotatingFileHandler
|
|
|
|
|
|
class CappedTimedFileHandler(TimedRotatingFileHandler):
|
|
"""TimedRotatingFileHandler that drops the rotated file instead of archiving.
|
|
|
|
Use when only the most recent N hours of operational logs matter and you
|
|
want a strict upper bound on disk use. Audit logs go through a separate
|
|
pipeline (see utils/audit.py), this only affects /opt/PegaProx/logs/<cluster>.log.
|
|
"""
|
|
|
|
def doRollover(self):
|
|
if self.stream:
|
|
self.stream.close()
|
|
self.stream = None
|
|
try:
|
|
os.remove(self.baseFilename)
|
|
except FileNotFoundError:
|
|
pass
|
|
# recompute next rollover (mirrors parent logic)
|
|
current = int(time.time())
|
|
new_at = self.computeRollover(current)
|
|
while new_at <= current:
|
|
new_at += self.interval
|
|
self.rolloverAt = new_at
|
|
if not self.delay:
|
|
self.stream = self._open()
|