AC_PATH_PROG([XSLTPROC], [xsltproc])
# Python
-AM_PATH_PYTHON([2.7])
+AM_PATH_PYTHON([3.2])
PKG_CHECK_MODULES([PYTHON], [python-${PYTHON_VERSION}])
# libatasmart
if (self->path)
free(self->path);
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static int BlockDevice_get_identity(BlockDevice* device) {
static PyObject* BlockDevice_get_path(PyObject* self) {
BlockDevice* device = (BlockDevice*)self;
- return PyString_FromString(device->path);
+ return PyUnicode_FromString(device->path);
}
static void clean_string(char *s) {
char model[MODEL_SIZE + 1];
copy_string(model, device->identity.model, sizeof(model));
- return PyString_FromString(model);
+ return PyUnicode_FromString(model);
}
static PyObject* BlockDevice_get_serial(PyObject* self) {
char serial[SERIAL_SIZE + 1];
copy_string(serial, device->identity.serial_no, sizeof(serial));
- return PyString_FromString(serial);
+ return PyUnicode_FromString(serial);
}
static PyObject* BlockDevice_is_smart_supported(PyObject* self) {
};
static PyTypeObject BlockDeviceType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT(NULL, 0)
"_collecty.BlockDevice", /*tp_name*/
sizeof(BlockDevice), /*tp_basicsize*/
0, /*tp_itemsize*/
} SensorObject;
static void Sensor_dealloc(SensorObject* self) {
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject* Sensor_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
char* label = sensors_get_label(self->chip, self->feature);
if (label) {
- PyObject* string = PyString_FromString(label);
+ PyObject* string = PyUnicode_FromString(label);
free(label);
return string;
return NULL;
}
- return PyString_FromString(chip_name);
+ return PyUnicode_FromString(chip_name);
}
static PyObject* Sensor_get_type(SensorObject* self) {
}
if (type)
- return PyString_FromString(type);
+ return PyUnicode_FromString(type);
Py_RETURN_NONE;
}
}
if (type)
- return PyString_FromString(type);
+ return PyUnicode_FromString(type);
Py_RETURN_NONE;
}
static PyTypeObject SensorType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
"_collecty.Sensor", /*tp_name*/
sizeof(SensorObject), /*tp_basicsize*/
0, /*tp_itemsize*/
{NULL},
};
-void init_collecty(void) {
+static struct PyModuleDef collecty_module = {
+ PyModuleDef_HEAD_INIT,
+ "_collecty", /* m_name */
+ "_collecty module", /* m_doc */
+ -1, /* m_size */
+ collecty_module_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
+};
+
+PyMODINIT_FUNC PyInit__collecty(void) {
if (PyType_Ready(&BlockDeviceType) < 0)
- return;
+ return NULL;
if (PyType_Ready(&SensorType) < 0)
- return;
+ return NULL;
- PyObject* m = Py_InitModule("_collecty", collecty_module_methods);
+ PyObject* m = PyModule_Create(&collecty_module);
+ Py_INCREF(&BlockDeviceType);
PyModule_AddObject(m, "BlockDevice", (PyObject*)&BlockDeviceType);
+
+ Py_INCREF(&SensorType);
PyModule_AddObject(m, "Sensor", (PyObject*)&SensorType);
+
+ return m;
}
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
###############################################################################
# Initialize logging.
-import logger
+from . import logger
-from client import CollectyClient
-from daemon import Collecty
+from .client import CollectyClient
+from .daemon import Collecty
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import dbus
import dbus.mainloop.glib
import dbus.service
-import gobject
+import gi.repository.GLib
+import gi.repository.GObject
import threading
-from constants import *
-from i18n import _
+from .constants import *
+from .i18n import _
import logging
log = logging.getLogger("collecty.bus")
log.propagate = 1
-# Initialise the glib main loop
-dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-dbus.mainloop.glib.threads_init()
-
class Bus(threading.Thread):
def __init__(self, collecty):
threading.Thread.__init__(self)
self.collecty = collecty
# Initialise the main loop
- gobject.threads_init()
- self.loop = gobject.MainLoop()
+ gi.repository.GObject.threads_init()
+ dbus.mainloop.glib.threads_init()
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ self.loop = gi.repository.GLib.MainLoop()
# Register the GraphGenerator interface
self.generator = GraphGenerator(self.collecty)
log.debug(_("Bus thread has started"))
# Run the main loop
- self.loop.run()
+ try:
+ self.loop.run()
+ except KeyboardInterrupt:
+ self.collecty.shutdown()
+
+ log.debug(_("Bus thread has ended"))
def shutdown(self):
log.debug(_("Stopping bus thread"))
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import dbus
import sys
-from constants import *
-from i18n import _
+from .constants import *
+from .i18n import _
import logging
log = logging.getLogger("collectly.client")
templates = self.list_templates()
for t in sorted(templates):
- print t
+ print(t)
def generate_graph(self, template_name, **kwargs):
byte_array = self.proxy.GenerateGraph(template_name, kwargs,
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-from i18n import _
+from .i18n import _
DATABASE_DIR = "/var/lib/collecty"
-#!/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()
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() \
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
-#!/usr/bin/python
-
-from __future__ import division
+#!/usr/bin/python3
import array
import math
# Send the packet.
try:
s.sendto(packet, (self.destination, 0))
- except socket.error, (errno, msg):
- if errno == 1: # Operation not permitted
+ except socket.error as e:
+ if e.errno == 1: # Operation not permitted
# The packet could not be sent, probably because of
# wrong firewall settings.
return
Unpack tghe raw received IP and ICMP header informations to a dict
"""
unpacked_data = struct.unpack(struct_format, data)
- return dict(zip(names, unpacked_data))
+ return dict(list(zip(names, unpacked_data)))
def _calculate_checksum(self, source_string):
if len(source_string) % 2:
p = Ping("ping.ipfire.org")
p.run(count=5)
- print "Min/Avg/Max/Stddev: %.2f/%.2f/%.2f/%.2f" % \
- (p.min_time, p.avg_time, p.max_time, p.stddev)
- print "Sent/Recv/Loss: %d/%d/%.2f" % (p.send_count, p.receive_count, p.loss)
+ print("Min/Avg/Max/Stddev: %.2f/%.2f/%.2f/%.2f" % \
+ (p.min_time, p.avg_time, p.max_time, p.stddev))
+ print("Sent/Recv/Loss: %d/%d/%.2f" % (p.send_count, p.receive_count, p.loss))
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-from base import Timer, get
+from .base import Timer, get
-import base
-import conntrack
-import cpu
-import cpufreq
-import disk
-import entropy
-import interface
-import latency
-import loadavg
-import memory
-import sensors
+from . import base
+from . import conntrack
+from . import cpu
+from . import cpufreq
+from . import disk
+from . import entropy
+from . import interface
+from . import latency
+from . import loadavg
+from . import memory
+from . import sensors
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-from __future__ import division
-
import datetime
import logging
import math
import tempfile
import threading
import time
+import unicodedata
from ..constants import *
from ..i18n import _
-_plugins = {}
-
-def get():
- """
- Returns a list with all automatically registered plugins.
- """
- return _plugins.values()
-
class Timer(object):
def __init__(self, timeout, heartbeat=1):
self.timeout = timeout
return self.elapsed > self.timeout
-class Plugin(object):
+class PluginRegistration(type):
+ plugins = {}
+
+ def __init__(plugin, name, bases, dict):
+ type.__init__(plugin, name, bases, dict)
+
+ # The main class from which is inherited is not registered
+ # as a plugin.
+ if name == "Plugin":
+ return
+
+ if not all((plugin.name, plugin.description)):
+ raise RuntimeError(_("Plugin is not properly configured: %s") % plugin)
+
+ PluginRegistration.plugins[plugin.name] = plugin
+
+
+def get():
+ """
+ Returns a list with all automatically registered plugins.
+ """
+ return PluginRegistration.plugins.values()
+
+class Plugin(object, metaclass=PluginRegistration):
# The name of this plugin.
name = None
# The default interval for all plugins
interval = 60
- # Automatically register all providers.
- class __metaclass__(type):
- def __init__(plugin, name, bases, dict):
- type.__init__(plugin, name, bases, dict)
-
- # The main class from which is inherited is not registered
- # as a plugin.
- if name == "Plugin":
- return
-
- if not all((plugin.name, plugin.description)):
- raise RuntimeError(_("Plugin is not properly configured: %s") \
- % plugin)
-
- _plugins[plugin.name] = plugin
-
def __init__(self, collecty, **kwargs):
self.collecty = collecty
@staticmethod
def _normalise_filename(filename):
# Convert the filename into ASCII characters only
- filename = filename.encode("ascii", "ignore")
+ filename = unicodedata.normalize("NFKC", filename)
# Replace any spaces by dashes
filename = filename.replace(" ", "-")
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import os
-import base
+from . import base
from ..i18n import _
layer4_protocol = "other"
# Count connection states
- if self.protocol_states.has_key(layer4_protocol):
+ if layer4_protocol in self.protocol_states:
state = line[5]
try:
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-from __future__ import division
-import base
+
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import os
import re
-import base
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import os
import re
-import base
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import os
-import base
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-from __future__ import division
+
import os
-import base
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import collecty.ping
-import base
+from . import base
from ..i18n import _
ping = collecty.ping.Ping(destination=self.hostname, timeout=20000)
ping.run(count=5, deadline=self.deadline)
- except collecty.ping.PingError, e:
+ except collecty.ping.PingError as e:
self.log.warning(_("Could not run latency check for %(host)s: %(msg)s") \
% { "host" : self.hostname, "msg" : e.msg })
return
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
import os
-import base
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
###############################################################################
# #
# collecty - A system statistics collection daemon for IPFire #
# #
###############################################################################
-from __future__ import division
-import base
+
+from . import base
from ..i18n import _
-#!/usr/bin/python
+#!/usr/bin/python3
# encoding: utf-8
###############################################################################
# #
import os
import re
-import base
+from . import base
from ..i18n import _