[pve-devel] [PATCH] influxdb : use multi values measurement

Alexandre Derumier aderumier at odiso.com
Wed Nov 25 07:57:02 CET 2015


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

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Status/InfluxDB.pm | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/PVE/Status/InfluxDB.pm b/PVE/Status/InfluxDB.pm
index 507f9b2..4d1a237 100644
--- a/PVE/Status/InfluxDB.pm
+++ b/PVE/Status/InfluxDB.pm
@@ -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;
-- 
2.1.4




More information about the pve-devel mailing list