summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bc053db)
raw | patch | inline | side by side (parent: bc053db)
author | m4rienf <frank@apsu.be> | |
Thu, 6 Sep 2012 19:25:22 +0000 (21:25 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 7 Sep 2012 09:00:44 +0000 (11:00 +0200) |
Signed-off-by: Florian Forster <octo@collectd.org>
contrib/collectd_network.py | patch | blob | history |
index 0222cdbdb3b3d526e14f3f3f08ffda4b866aba07..0a5d57e6cfe6030eec55df16fecb28b45a828c66 100644 (file)
#
# 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:
DEFAULT_IPv6_GROUP = "ff18::efc0:4a42"
"""Default IPv6 multicast group"""
-
+HR_TIME_DIV = (2.0**30)
# Message kinds
TYPE_HOST = 0x0000
DS_TYPE_DERIVE = 2
DS_TYPE_ABSOLUTE = 3
-
header = struct.Struct("!2H")
number = struct.Struct("!Q")
short = struct.Struct("!H")
double = struct.Struct("<d")
-
def decode_network_values(ptype, plen, buf):
"""Decodes a list of DS values in collectd network format
"""
def decode_network_number(ptype, plen, buf):
- """Decodes a number (64-bit unsigned) in collectd network format.
+ """Decodes a number (64-bit unsigned) from collectd network format.
"""
return number.unpack_from(buf, header.size)[0]
def decode_network_string(msgtype, plen, buf):
- """Decodes a floating point number (64-bit) in collectd network format.
+ """Decodes a string from collectd network format.
"""
return buf[header.size:plen-1]
if kind == TYPE_TIME:
vl.time = nt.time = data
elif kind == TYPE_TIME_HR:
- vl.time = nt.time = data
+ vl.time = nt.time = data / HR_TIME_DIV
elif kind == TYPE_INTERVAL:
vl.interval = data
elif kind == TYPE_INTERVAL_HR:
- vl.interval = data
+ vl.interval = data / HR_TIME_DIV
elif kind == TYPE_HOST:
vl.host = nt.host = data
elif kind == TYPE_PLUGIN: