Permalink
Browse files

Merge branch 'collectd-5.1'

  • Loading branch information...
2 parents 0abfaa6 + fda68e2 commit 59dded4cc1a2077ad11c6e9b507e15ad19e0e38c @octo octo committed Sep 7, 2012
View
@@ -91,6 +91,7 @@ fi
if test "x$ac_system" = "xSolaris"
then
AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1, [Define to enforce POSIX thread semantics under Solaris.])
+ AC_DEFINE(_REENTRANT, 1, [Define to enable reentrancy interfaces.])
fi
if test "x$ac_system" = "xAIX"
then
@@ -532,6 +533,8 @@ AC_CHECK_HEADERS(netinet/if_ether.h, [], [],
#endif
])
+AC_CHECK_HEADERS(netinet/ip_compat.h)
+
# For the multimeter plugin
have_termios_h="no"
AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
@@ -5,18 +5,22 @@
# Copyright © 2009 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the GPLv2 license.
+#
+# 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
-
+import socket,struct,sys
try:
- from cStringIO import StringIO
+ from io import StringIO
except ImportError:
- from StringIO import StringIO
+ from cStringIO import StringIO
from datetime import datetime
from copy import deepcopy
@@ -31,17 +35,19 @@
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 +56,14 @@
# 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("<d")
-
def decode_network_values(ptype, plen, buf):
"""Decodes a list of DS values in collectd network format
"""
@@ -70,27 +76,33 @@ def decode_network_values(ptype, plen, buf):
assert double.size == number.size
result = []
- for dstype in map(ord, buf[header.size+short.size:off]):
+ for dstype in buf[header.size+short.size:off]:
if dstype == DS_TYPE_COUNTER:
result.append((dstype, number.unpack_from(buf, off)[0]))
off += valskip
elif dstype == DS_TYPE_GAUGE:
result.append((dstype, double.unpack_from(buf, off)[0]))
off += valskip
+ elif dstype == DS_TYPE_DERIVE:
+ result.append((dstype, number.unpack_from(buf, off)[0]))
+ off += valskip
+ elif dstype == DS_TYPE_ABSOLUTE:
+ result.append((dstype, number.unpack_from(buf, off)[0]))
+ off += valskip
else:
raise ValueError("DS type %i unsupported" % dstype)
return result
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]
@@ -99,7 +111,9 @@ def decode_network_string(msgtype, plen, buf):
_decoders = {
TYPE_VALUES : decode_network_values,
TYPE_TIME : decode_network_number,
+ TYPE_TIME_HR : decode_network_number,
TYPE_INTERVAL : decode_network_number,
+ TYPE_INTERVAL_HR : decode_network_number,
TYPE_HOST : decode_network_string,
TYPE_PLUGIN : decode_network_string,
TYPE_PLUGIN_INSTANCE: decode_network_string,
@@ -115,6 +129,7 @@ def decode_network_packet(buf):
"""
off = 0
blen = len(buf)
+
while off < blen:
ptype, plen = header.unpack_from(buf, off)
@@ -128,9 +143,6 @@ def decode_network_packet(buf):
off += plen
-
-
-
class Data(object):
time = 0
host = None
@@ -140,7 +152,7 @@ class Data(object):
typeinstance = None
def __init__(self, **kw):
- [setattr(self, k, v) for k, v in kw.iteritems()]
+ [setattr(self, k, v) for k, v in kw.items()]
@property
def datetime(self):
@@ -150,19 +162,19 @@ def datetime(self):
def source(self):
buf = StringIO()
if self.host:
- buf.write(self.host)
+ buf.write(str(self.host))
if self.plugin:
buf.write("/")
- buf.write(self.plugin)
+ buf.write(str(self.plugin))
if self.plugininstance:
buf.write("/")
- buf.write(self.plugininstance)
+ buf.write(str(self.plugininstance))
if self.type:
buf.write("/")
- buf.write(self.type)
+ buf.write(str(self.type))
if self.typeinstance:
buf.write("/")
- buf.write(self.typeinstance)
+ buf.write(str(self.typeinstance))
return buf.getvalue()
def __str__(self):
@@ -215,8 +227,12 @@ def interpret_opcodes(iterable):
for kind, data in iterable:
if kind == TYPE_TIME:
vl.time = nt.time = data
+ elif kind == TYPE_TIME_HR:
+ vl.time = nt.time = data / HR_TIME_DIV
elif kind == TYPE_INTERVAL:
vl.interval = data
+ elif kind == TYPE_INTERVAL_HR:
+ vl.interval = data / HR_TIME_DIV
elif kind == TYPE_HOST:
vl.host = nt.host = data
elif kind == TYPE_PLUGIN:
@@ -248,7 +264,7 @@ class Reader(object):
host = None
port = DEFAULT_PORT
- BUFFER_SIZE = 1024
+ BUFFER_SIZE = 16384
def __init__(self, host=None, port=DEFAULT_PORT, multicast=False):
@@ -311,8 +327,6 @@ def interpret(self, iterable=None):
"""
if iterable is None:
iterable = self.decode()
- if isinstance(iterable, basestring):
+ if isinstance(iterable, str):
iterable = self.decode(iterable)
return interpret_opcodes(iterable)
-
-
@@ -240,6 +240,50 @@ HTML
$html_started = 0;
}
+sub contains_invalid_chars
+{
+ my $str = shift;
+
+ for (split (m//, $str))
+ {
+ my $n = ord ($_);
+
+ # Whitespace is allowed.
+ if (($n >= 9) && ($n <= 13))
+ {
+ next;
+ }
+ elsif ($n < 32)
+ {
+ return (1);
+ }
+ }
+
+ return;
+}
+
+sub contains_invalid_chars
+{
+ my $str = shift;
+
+ for (split (m//, $str))
+ {
+ my $n = ord ($_);
+
+ # Whitespace is allowed.
+ if (($n >= 9) && ($n <= 13))
+ {
+ next;
+ }
+ elsif ($n < 32)
+ {
+ return (1);
+ }
+ }
+
+ return;
+}
+
sub show_selector
{
my $timespan_selection = get_timespan_selection ();
@@ -254,6 +298,7 @@ sub show_selector
HTML
for (sort (keys %$host_selection))
{
+ next if contains_invalid_chars ($_);
my $host = encode_entities ($_);
my $selected = $host_selection->{$_}
? ' selected="selected"'
@@ -266,6 +311,7 @@ HTML
HTML
for (sort (keys %$plugin_selection))
{
+ next if contains_invalid_chars ($_);
my $plugin = encode_entities ($_);
my $selected = $plugin_selection->{$_}
? ' selected="selected"'
@@ -278,6 +324,7 @@ HTML
HTML
for (sort { $TimeSpans->{$a} <=> $TimeSpans->{$b} } (keys (%$TimeSpans)))
{
+ next if contains_invalid_chars ($_);
my $name = encode_entities ($_);
my $value = $TimeSpans->{$_};
my $selected = ($value == $timespan_selection)
@@ -304,6 +351,7 @@ sub action_list_hosts
for (sort @hosts)
{
my $url = encode_entities (script_name () . "?action=show_selection;hostname=$_");
+ next if contains_invalid_chars ($_);
my $name = encode_entities ($_);
print qq# <li><a href="$url">$name</a></li>\n#;
}
@@ -34,7 +34,7 @@ sub new
my $obj = Collectd::Graph::Type->new (@_);
$obj->{'data_sources'} = [qw(free used)];
$obj->{'rrd_opts'} = ['-v', 'Bytes'];
- $obj->{'rrd_title'} = 'Disk space ({type_instance})';
+ $obj->{'rrd_title'} = 'Disk space ({instance})';
$obj->{'rrd_format'} = '%5.1lf%sB';
$obj->{'colors'} = [qw(00b000 ff0000)];
@@ -58,7 +58,7 @@ sub getRRDArgs
my $faded_green = get_faded_color ('00ff00');
my $faded_red = get_faded_color ('ff0000');
- return (['-t', 'Diskspace (' . $ident->{'type_instance'} . ')', '-v', 'Bytes', '-l', '0',
+ return (['-t', $obj->getTitle ($ident), '-v', 'Bytes', '-l', '0',
"DEF:free_min=${filename}:free:MIN",
"DEF:free_avg=${filename}:free:AVERAGE",
"DEF:free_max=${filename}:free:MAX",
View
@@ -33,6 +33,7 @@ use File::Basename ('dirname');
our $InDir = '/var/lib/collectd';
our $RRDtool = 'rrdtool';
+our $RRDFilter = 'rrd_filter.px';
our %TypesCounterToDerive = # {{{
(
@@ -184,7 +185,15 @@ sub handle_file # {{{
{
my $dir = join ('/', @path);
print "mkdir -p \"$dir/$plugin-$type_inst\"\n";
- print "mv \"$path\" \"$dir/$plugin-$type_inst/$type.rrd\"\n";
+ if (($plugin eq 'df') and ($type eq 'df'))
+ {
+ print "$RRDFilter --infile=\"$path\" --outfile=\"$dir/$plugin-$type_inst/df_complex-free.rrd\" --map free:value\n";
+ print "$RRDFilter --infile=\"$path\" --outfile=\"$dir/$plugin-$type_inst/df_complex-used.rrd\" --map used:value\n";
+ }
+ else
+ {
+ print "mv \"$path\" \"$dir/$plugin-$type_inst/$type.rrd\"\n";
+ }
}
} # }}} sub handle_file
@@ -223,19 +232,24 @@ migrate-4-5.px [OPTIONS]
Valid options are:
- --indir <dir> Source directory
- Default: $InDir
- --rrdtool <path> Path to the RRDtool binary
- Default: $RRDtool
+ --indir <dir> Source directory
+ Default: $InDir
+ --rrdtool <path> Path to the RRDtool binary
+ Default: $RRDtool
+ --rrdfilter <path> Path to the rrd_filter.px script
+ Default: $RRDFilter
EOF
exit (1);
} # }}} sub exit_usage
GetOptions ("indir|i=s" => \$InDir,
"rrdtool=s" => \$RRDtool,
+ "rrdfilter=s" => \$RRDFilter,
"help|h" => \&exit_usage) or exit_usage ();
+print "#!/bin/bash\n\n";
+
scan_dir ($InDir);
# vim: set sw=2 sts=2 et fdm=marker :
View
@@ -43,7 +43,7 @@ collectd_SOURCES = collectd.c collectd.h \
collectd_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
collectd_CFLAGS = $(AM_CFLAGS)
collectd_LDFLAGS = -export-dynamic
-collectd_LDADD =
+collectd_LDADD = -lm
collectd_DEPENDENCIES =
# Link to these libraries..
@@ -70,7 +70,6 @@ collectd_LDADD += -ldevinfo
endif
if BUILD_AIX
collectd_LDFLAGS += -Wl,-bexpall,-brtllib
-collectd_LDADD += -lm
endif
# The daemon needs to call sg_init, so we need to link it against libstatgrab,
@@ -1372,7 +1371,7 @@ EXTRA_DIST += collectd.conf.pod \
fi
pinba.pb-c.c pinba.pb-c.h: pinba.proto
- protoc-c --c_out $(builddir) pinba.proto
+ protoc-c --c_out . pinba.proto
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(sysconfdir)
Oops, something went wrong.

0 comments on commit 59dded4

Please sign in to comment.