Adding new metric to relay

Signed-off-by: Pedro Tanaka <pedro.tanaka@shopify.com>
This commit is contained in:
Pedro Tanaka 2022-04-21 11:47:19 +02:00
parent 60742e1bd6
commit 2d339b0853
No known key found for this signature in database
GPG key ID: D0D8389DA4EE060B

View file

@ -35,8 +35,9 @@ type Relay struct {
logger log.Logger logger log.Logger
packetLength uint packetLength uint
packetsTotal prometheus.Counter packetsTotal prometheus.Counter
longLinesTotal prometheus.Counter longLinesTotal prometheus.Counter
relayedLinesTotal prometheus.Counter
} }
var ( var (
@ -54,6 +55,13 @@ var (
}, },
[]string{"target"}, []string{"target"},
) )
relayLinesRelayedTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "statsd_exporter_relay_lines_relayed_total",
Help: "The number of lines that were buffered to be relayed.",
},
[]string{"target"},
)
) )
// NewRelay creates a statsd UDP relay. It can be used to send copies of statsd raw // NewRelay creates a statsd UDP relay. It can be used to send copies of statsd raw
@ -77,8 +85,9 @@ func NewRelay(l log.Logger, target string, packetLength uint) (*Relay, error) {
logger: l, logger: l,
packetLength: packetLength, packetLength: packetLength,
packetsTotal: relayPacketsTotal.WithLabelValues(target), packetsTotal: relayPacketsTotal.WithLabelValues(target),
longLinesTotal: relayLongLinesTotal.WithLabelValues(target), longLinesTotal: relayLongLinesTotal.WithLabelValues(target),
relayedLinesTotal: relayLinesRelayedTotal.WithLabelValues(target),
} }
// Startup the UDP sender. // Startup the UDP sender.
@ -152,5 +161,6 @@ func (r *Relay) RelayLine(l string) {
if !strings.HasSuffix(l, "\n") { if !strings.HasSuffix(l, "\n") {
l = l + "\n" l = l + "\n"
} }
r.relayedLinesTotal.Inc()
r.bufferChannel <- []byte(l) r.bufferChannel <- []byte(l)
} }