From c882e8a855a6803a498be2235560f8d0359edcb6 Mon Sep 17 00:00:00 2001 From: m4rienf Date: Thu, 6 Sep 2012 21:25:22 +0200 Subject: [PATCH] corrected high-resolution time conversions after code review Signed-off-by: Florian Forster --- contrib/collectd_network.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/contrib/collectd_network.py b/contrib/collectd_network.py index 0222cdbd..0a5d57e6 100644 --- a/contrib/collectd_network.py +++ b/contrib/collectd_network.py @@ -6,17 +6,17 @@ # # Distributed under terms of the GPLv2 license. # -# 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 +import socket,struct,sys try: from io import StringIO except ImportError: @@ -35,7 +35,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 +59,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("