X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fcollectd_network.py;h=809f19dee65d2ec89a030a762bacb5e98041d8aa;hb=7a956273a735f15adc49359ba1733170216d79ab;hp=0222cdbdb3b3d526e14f3f3f08ffda4b866aba07;hpb=bc053db36028690e589607d5711724fe13bb170d;p=collectd.git diff --git a/contrib/collectd_network.py b/contrib/collectd_network.py index 0222cdbd..809f19de 100644 --- a/contrib/collectd_network.py +++ b/contrib/collectd_network.py @@ -4,23 +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) 4 Sep 2012 +# Frank Marien (frank@apsu.be) 6 Sep 2012 # - quick fixes for 5.1 binary protocol -# - updated for python 3 +# - 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 io import StringIO -except ImportError: - from cStringIO import StringIO +import socket,struct,sys +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 @@ -35,7 +40,7 @@ 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 @@ -59,13 +64,11 @@ 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("