How to sum up HAProxy backend connections using telegraf?

Use Case:

i’m running ma HAProxy Loadbalancer farm on 10 Virtual Machines. On each VM, telegraf with haproxy input plugin is installed. The plugin is working fine, data is arriving in InfluxDB every 15 secods.

I am interested in the filed “scur”. This is the number of current connections. The meaning of “scur” depends on tag values:
If tag “sv”==‘BACKEND’ and tag “proxy”=‘mybackend’, “scur” is the number of backend connections for the given proxy(‘mybackend’) and the VM referenced in tag “hostname”. Example data (for one VM)

> select hostname,sv,proxy,scur from "haproxy" where hostname='myVM01   ' limit 20
name: viotp.haproxy
time                 hostname  sv         proxy               scur
----                 --------  --         -----               ----
2018-01-05T21:24:30Z myVM01    BACKEND    mybackend1          9033
2018-01-05T21:24:30Z myVM01    server01   mybackend1          0
2018-01-05T21:24:30Z myVM01    server02   mybackend1          1290
2018-01-05T21:24:30Z myVM01    BACKEND    otherbackend01      2
2018-01-05T21:24:30Z myVM01    FRONTEND   somefrontend        9001

I am interested in the backend connections of proxy “mybackend” which is present on all 10 VMs. Example data for 3 VMs’ (filtered)

> select hostname,sv,proxy,scur from "haproxy" where sv='BACKEND' and proxy='mybackend1" limit 20
name: viotp.haproxy
time                 hostname  sv         proxy               scur
----                 --------  --         -----               ----
2018-01-05T21:24:30Z myVM01    BACKEND    mybackend1          9033
2018-01-05T21:24:30Z myVM02    BACKEND    mybackend1          3588
2018-01-05T21:24:30Z myVM03    BACKEND    mybackend1          7960
2018-01-05T21:24:45Z myVM01    BACKEND    mybackend1          9112
2018-01-05T21:24:45Z myVM02    BACKEND    mybackend1          3500
2018-01-05T21:24:45Z myVM03    BACKEND    mybackend1          7960

Question

How can i sum up the number of connections for “mybackend1” over all VMs at a given point in time?
When looking at example data above:

  • at 21:24:30 there were 9033+3588+7960 connections
  • at 21:24:45 there were 9112+3500+7960 connections

How can i build that sum and store result back in an Influx Measurement?

Notes

  • i have kapacitor installed so solution can be based on Influx CQ or TICK script.

Hope anybody can help. BTW: I’m new to TICK stack but would call myself an haproxy expert. So if i can help with any problems regarding haproxy drop me a note.