From: Michael Tremer Date: Tue, 5 Aug 2025 14:18:15 +0000 (+0100) Subject: suricata-reporter: Create a couple of worker processes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a90715ba353fd6f4de7444b56236275b79f5ae8;p=ipfire-2.x.git suricata-reporter: Create a couple of worker processes Signed-off-by: Michael Tremer --- diff --git a/config/suricata/suricata-reporter b/config/suricata/suricata-reporter index b23f7e5d8..0e8d89b65 100644 --- a/config/suricata/suricata-reporter +++ b/config/suricata/suricata-reporter @@ -23,8 +23,10 @@ import argparse import asyncio import logging import logging.handlers +import multiprocessing import signal import sys +import time log = logging.getLogger("suricata-reporter") log.setLevel(logging.DEBUG) @@ -34,7 +36,13 @@ class Reporter(object): This is the main class that handles all the things... """ def __init__(self): - pass + # Fetch CPU count + cpu_count = multiprocessing.cpu_count() + + # Create as many workers as we have processors + self.workers = [ + Worker(reporter=self) for _ in range(cpu_count) + ] async def run(self): """ @@ -42,13 +50,45 @@ class Reporter(object): """ log.debug("Starting reporter...") + # Start all workers + for worker in self.workers: + worker.start() + # Sleep for forever while True: await asyncio.sleep(1) + # Terminate all workers + for worker in self.workers: + worker.terminate() + + # Wait until all workers have terminated + for worker in self.workers: + worker.join() + log.debug("Reporter has exited") +class Worker(multiprocessing.Process): + def __init__(self, reporter): + super().__init__() + + # Store the reporter + self.reporter = reporter + + def run(self): + """ + This is the main entry point for workers... + """ + log.debug("Worker %s launched" % self.pid) + + # Sleep for forever + while True: + time.sleep(1) + + log.debug("Worker %s terminated" % self.pid) + + def setup_logging(loglevel=logging.INFO): log.setLevel(loglevel)