mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-18 06:11:49 -05:00
Put an upper bound on the QueueHandler queue
This patch overrides the base QueueHandler class from logging to ensure that the queue doesn't grow infinitely. That can be a problem when there is no consumer pulling items out of the queue. the queue is now capped at 200 entries max.
This commit is contained in:
parent
cb2a3441b4
commit
93a9cce0c0
@ -4,6 +4,7 @@ CHANGES
|
|||||||
v3.4.0
|
v3.4.0
|
||||||
------
|
------
|
||||||
|
|
||||||
|
* Updated Changelog for 3.4.0
|
||||||
* Change setup.h
|
* Change setup.h
|
||||||
* Fixed docker setup.sh comparison
|
* Fixed docker setup.sh comparison
|
||||||
* Fixed unit tests failing with WatchList
|
* Fixed unit tests failing with WatchList
|
||||||
|
@ -12,7 +12,22 @@ from aprsd.conf import log as conf_log
|
|||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
# LOG = logging.getLogger("APRSD")
|
# LOG = logging.getLogger("APRSD")
|
||||||
LOG = logger
|
LOG = logger
|
||||||
logging_queue = queue.Queue()
|
|
||||||
|
|
||||||
|
class QueueLatest(queue.Queue):
|
||||||
|
"""Custom Queue to keep only the latest N items.
|
||||||
|
|
||||||
|
This prevents the queue from blowing up in size.
|
||||||
|
"""
|
||||||
|
def put(self, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
super().put(*args, **kwargs)
|
||||||
|
except queue.Full:
|
||||||
|
self.queue.popleft()
|
||||||
|
super().put(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
logging_queue = QueueLatest(maxsize=200)
|
||||||
|
|
||||||
|
|
||||||
class InterceptHandler(logging.Handler):
|
class InterceptHandler(logging.Handler):
|
||||||
@ -59,6 +74,10 @@ def setup_logging(loglevel=None, quiet=False):
|
|||||||
"werkzeug._internal",
|
"werkzeug._internal",
|
||||||
"socketio",
|
"socketio",
|
||||||
"urllib3.connectionpool",
|
"urllib3.connectionpool",
|
||||||
|
"chardet",
|
||||||
|
"chardet.charsetgroupprober",
|
||||||
|
"chardet.eucjpprober",
|
||||||
|
"chardet.mbcharsetprober",
|
||||||
]
|
]
|
||||||
|
|
||||||
# We don't really want to see the aprslib parsing debug output.
|
# We don't really want to see the aprslib parsing debug output.
|
||||||
|
@ -5,6 +5,7 @@ from oslo_config import cfg
|
|||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import utils
|
from aprsd import utils
|
||||||
|
from aprsd.log import log as aprsd_log
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
@ -32,6 +33,7 @@ class APRSDStats:
|
|||||||
def stats(self, serializable=False) -> dict:
|
def stats(self, serializable=False) -> dict:
|
||||||
current, peak = tracemalloc.get_traced_memory()
|
current, peak = tracemalloc.get_traced_memory()
|
||||||
uptime = self.uptime()
|
uptime = self.uptime()
|
||||||
|
qsize = aprsd_log.logging_queue.qsize()
|
||||||
if serializable:
|
if serializable:
|
||||||
uptime = str(uptime)
|
uptime = str(uptime)
|
||||||
stats = {
|
stats = {
|
||||||
@ -42,5 +44,6 @@ class APRSDStats:
|
|||||||
"memory_current_str": utils.human_size(current),
|
"memory_current_str": utils.human_size(current),
|
||||||
"memory_peak": int(peak),
|
"memory_peak": int(peak),
|
||||||
"memory_peak_str": utils.human_size(peak),
|
"memory_peak_str": utils.human_size(peak),
|
||||||
|
"loging_queue": qsize,
|
||||||
}
|
}
|
||||||
return stats
|
return stats
|
||||||
|
@ -6,6 +6,7 @@ import tracemalloc
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import client, packets, utils
|
from aprsd import client, packets, utils
|
||||||
|
from aprsd.log import log as aprsd_log
|
||||||
from aprsd.stats import collector
|
from aprsd.stats import collector
|
||||||
from aprsd.threads import APRSDThread, APRSDThreadList
|
from aprsd.threads import APRSDThread, APRSDThreadList
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ class KeepAliveThread(APRSDThread):
|
|||||||
|
|
||||||
keepalive = (
|
keepalive = (
|
||||||
"{} - Uptime {} RX:{} TX:{} Tracker:{} Msgs TX:{} RX:{} "
|
"{} - Uptime {} RX:{} TX:{} Tracker:{} Msgs TX:{} RX:{} "
|
||||||
"Last:{} Email: {} - RAM Current:{} Peak:{} Threads:{}"
|
"Last:{} Email: {} - RAM Current:{} Peak:{} Threads:{} LoggingQueue:{}"
|
||||||
).format(
|
).format(
|
||||||
stats_json["APRSDStats"]["callsign"],
|
stats_json["APRSDStats"]["callsign"],
|
||||||
stats_json["APRSDStats"]["uptime"],
|
stats_json["APRSDStats"]["uptime"],
|
||||||
@ -73,6 +74,7 @@ class KeepAliveThread(APRSDThread):
|
|||||||
stats_json["APRSDStats"]["memory_current_str"],
|
stats_json["APRSDStats"]["memory_current_str"],
|
||||||
stats_json["APRSDStats"]["memory_peak_str"],
|
stats_json["APRSDStats"]["memory_peak_str"],
|
||||||
len(thread_list),
|
len(thread_list),
|
||||||
|
aprsd_log.logging_queue.qsize(),
|
||||||
)
|
)
|
||||||
LOG.info(keepalive)
|
LOG.info(keepalive)
|
||||||
if "APRSDThreadList" in stats_json:
|
if "APRSDThreadList" in stats_json:
|
||||||
|
Loading…
Reference in New Issue
Block a user