Convert haproxy-statsd to a pipeline send

By default this sends out each stat in a single UDP packet.  I found
with the AFS monitoring, blasting these out in very quick succession
can result in stats getting lost fairly easily.

statsd's pipelines are really designed for this.  It batches up all
the stats and then sends them out combined in reasonable MTU sized
chunks.

Change-Id: Ife520d549da3a1a667be15e95a747e313825ac20
This commit is contained in:
Ian Wienand 2018-06-12 09:46:56 +10:00
parent 35f7f0dd78
commit d514389e41

View File

@ -145,12 +145,13 @@ class HAProxy(object):
return ret
def reportStats(self, stats):
pipe = statsd.pipeline()
for row in stats:
base = 'haproxy.%s.%s.' % (row['pxname'], row['svname'])
for key in GAUGES:
value = row[key]
if value != '':
statsd.gauge(base + key, int(value))
pipe.gauge(base + key, int(value))
for key in COUNTERS:
metric = base + key
newvalue = row[key]
@ -160,8 +161,9 @@ class HAProxy(object):
oldvalue = self.prevdata.get(metric)
if oldvalue is not None:
value = newvalue - oldvalue
statsd.incr(metric, value)
pipe.incr(metric, value)
self.prevdata[metric] = newvalue
pipe.send()
def run(self):
while True: