influxdb : use multi values measurement

influxdb (> 0.9.5) now support fastly multiple values by mesuerement,
through a new column store engine.

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2015-11-25 07:57:02 +01:00 committed by Dietmar Maurer
parent 0b19ac6f8d
commit 2ce302d0e5

View File

@ -100,37 +100,42 @@ sub write_influxdb_hash {
}
sub build_influxdb_payload {
my ($payload, $d, $ctime, $tags, $keyprefix, $depth) = @_;
my ($payload, $d, $ctime, $tags, $measurement, $depth) = @_;
$depth = 0 if !$depth;
my @values = ();
for my $key (keys %$d) {
my $value = $d->{$key};
my $oldtags = $tags;
if ( defined $value ) {
if ( ref $value eq 'HASH' ) {
if($depth == 0) {
$keyprefix = $key;
$measurement = $key;
}elsif($depth == 1){
$tags .= ",instance=$key";
}
$depth++;
build_influxdb_payload($payload, $value, $ctime, $tags, $keyprefix, $depth);
build_influxdb_payload($payload, $value, $ctime, $tags, $measurement, $depth);
$depth--;
}elsif ($value =~ m/^\d+$/) {
$keyprefix = "system" if !$keyprefix && $depth == 0;
$payload->{string} .= $keyprefix."_"."$key,$tags value=$value $ctime\n";
$measurement = "system" if !$measurement && $depth == 0;
push(@values, "$key=$value");
}
}
$tags = $oldtags;
}
if(@values > 0) {
my $valuestr = join(',', @values);
$payload->{string} .= $measurement.",$tags $valuestr $ctime\n";
}
}
1;