-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-import Queue as queue
import datetime
import multiprocessing
+import queue
import rrdtool
import signal
import threading
import time
-import bus
-import plugins
+from . import bus
+from . import plugins
-from constants import *
-from i18n import _
+from .constants import *
+from .i18n import _
import logging
log = logging.getLogger("collecty")
# Register signal handlers.
self.register_signal_handler()
+ # Cannot do anything if no plugins have been initialised
+ if not self.plugins:
+ log.critical(_("No plugins have been initialised"))
+ return
+
# Start the bus
self.bus.start()
Creates a number of worker threads
"""
# If no number of threads is given, we will create as many as we have
- # active processor cores but never less than four.
+ # active processor cores but never less than two.
if num is None:
- num = max(multiprocessing.cpu_count(), 4)
+ num = max(multiprocessing.cpu_count(), 2)
worker_threads = []
def shutdown(self):
self.running = False
- # Wait until all data has been written.
- self.join()
-
class WriteQueue(threading.Thread):
def __init__(self, collecty, submit_interval):
results[result.file] = [result]
# Write the collected data to disk
- for filename, results in results.items():
+ for filename, results in list(results.items()):
self._commit_file(filename, results)
duration = time.time() - time_start
def __str__(self):
return "%s:%s" % (self.time.strftime("%s"), self.data)
- def __cmp__(self, other):
- return cmp(self.time, other.time)
+ def __lt__(self, other):
+ return self.time < other.time
class PluginTimer(object):
def __repr__(self):
return "<%s %s>" % (self.__class__.__name__, self.deadline)
- def __cmp__(self, other):
- return cmp(self.deadline, other.deadline)
+ def __lt__(self, other):
+ return self.deadline < other.deadline
def reset_deadline(self):
self.deadline = datetime.datetime.utcnow() \