X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=contrib%2Fcollectd_network.py;h=cb328f2b23a69166036793a6e40a12b96ac74e2e;hp=445b1838d0256dce0ce425daa2aadd8e0cdf5696;hb=de407dd4e036f73e9bd4658af9d71f504fc11109;hpb=efa4700ad47969749b0fca622294fd006b2d7cb8 diff --git a/contrib/collectd_network.py b/contrib/collectd_network.py index 445b1838..cb328f2b 100644 --- a/contrib/collectd_network.py +++ b/contrib/collectd_network.py @@ -4,19 +4,28 @@ # # Copyright © 2009 Adrian Perez # -# Distributed under terms of the GPLv2 license. +# Distributed under terms of the GPLv2 license or newer. +# +# Frank Marien (frank@apsu.be) 6 Sep 2012 +# - quick fixes for 5.1 binary protocol +# - updated to python 3 +# - fixed for larger packet sizes (possible on lo interface) +# - fixed comment typo (decode_network_string decodes a string) """ Collectd network protocol implementation. """ -import socket -import struct - -try: - from cStringIO import StringIO -except ImportError: +import socket,struct +import platform +if platform.python_version() < '2.8.0': + # Python 2.7 and below io.StringIO does not like unicode from StringIO import StringIO +else: + try: + from io import StringIO + except ImportError: + from cStringIO import StringIO from datetime import datetime from copy import deepcopy @@ -31,17 +40,19 @@ DEFAULT_IPv4_GROUP = "239.192.74.66" DEFAULT_IPv6_GROUP = "ff18::efc0:4a42" """Default IPv6 multicast group""" - +HR_TIME_DIV = (2.0**30) # Message kinds TYPE_HOST = 0x0000 TYPE_TIME = 0x0001 +TYPE_TIME_HR = 0x0008 TYPE_PLUGIN = 0x0002 TYPE_PLUGIN_INSTANCE = 0x0003 TYPE_TYPE = 0x0004 TYPE_TYPE_INSTANCE = 0x0005 TYPE_VALUES = 0x0006 TYPE_INTERVAL = 0x0007 +TYPE_INTERVAL_HR = 0x0009 # For notifications TYPE_MESSAGE = 0x0100 @@ -50,14 +61,14 @@ TYPE_SEVERITY = 0x0101 # DS kinds DS_TYPE_COUNTER = 0 DS_TYPE_GAUGE = 1 - +DS_TYPE_DERIVE = 2 +DS_TYPE_ABSOLUTE = 3 header = struct.Struct("!2H") number = struct.Struct("!Q") short = struct.Struct("!H") double = struct.Struct("