#!/usr/bin/perl                                                                                                                                                                     
use LWP::Simple;
my $host="haproxy1";
my $url = 'http://127.0.0.1:1090/hastat;csv';
my$t=time;
$_=get $url;

#should be just ignoring empty values but im lazy
s/,,/,0,/g;
s/,,/,0,/g;

my @a=split(/\n/);

foreach(@a) {
    if($_ =~ /\#/) {;} else {

	($pxname,$svname,$qcur,$qmax,$scur,$smax,$slim,$stot,$bin,$bout,$dreq,$dresp,$ereq,$econ,$eresp,$wretr,$wredis,$status,$weight,$act,$bck,$chkfail,$chkdown,$lastchg,$downtime,$qlimit,$pid,$iid,$sid,$throttle,$lbtot,$tracked,$type) = split(/,/);

	print "PUTVAL $host/haproxy-$pxname/if_octets-$svname $t:$bin:$bout\n";
	print "PUTVAL $host/haproxy-$pxname/gauge-queue_$svname $t:$qcur\n";
	print "PUTVAL $host/haproxy-$pxname/derive-connections_$svname $t:$stot\n";
	print "PUTVAL $host/haproxy-$pxname/gauge-conn_active_$svname $t:$scur\n";
	print "PUTVAL $host/haproxy-$pxname/derive-redispatch_$svname $t:$wredis\n";
	print "PUTVAL $host/haproxy-$pxname/derive-retries_$svname $t:$wretr\n";
    }
}