Skip to content
Snippets Groups Projects
Commit 18f4afb3 authored by HUANG Wei's avatar HUANG Wei Committed by Cameron Sparr
Browse files

Inherit previous instance's stats in statsd plugin.

This way, after a reload, the stats wont restart again at least for the
counter type.

closes #887
parent 77dcbe95
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,8 @@ const ( ...@@ -26,6 +26,8 @@ const (
var dropwarn = "ERROR: Message queue full. Discarding line [%s] " + var dropwarn = "ERROR: Message queue full. Discarding line [%s] " +
"You may want to increase allowed_pending_messages in the config\n" "You may want to increase allowed_pending_messages in the config\n"
var prevInstance *Statsd
type Statsd struct { type Statsd struct {
// Address & Port to serve from // Address & Port to serve from
ServiceAddress string ServiceAddress string
...@@ -234,10 +236,18 @@ func (s *Statsd) Start(_ telegraf.Accumulator) error { ...@@ -234,10 +236,18 @@ func (s *Statsd) Start(_ telegraf.Accumulator) error {
// Make data structures // Make data structures
s.done = make(chan struct{}) s.done = make(chan struct{})
s.in = make(chan []byte, s.AllowedPendingMessages) s.in = make(chan []byte, s.AllowedPendingMessages)
s.gauges = make(map[string]cachedgauge)
s.counters = make(map[string]cachedcounter) if prevInstance == nil {
s.sets = make(map[string]cachedset) s.gauges = make(map[string]cachedgauge)
s.timings = make(map[string]cachedtimings) s.counters = make(map[string]cachedcounter)
s.sets = make(map[string]cachedset)
s.timings = make(map[string]cachedtimings)
} else {
s.gauges = prevInstance.gauges
s.counters = prevInstance.counters
s.sets = prevInstance.sets
s.timings = prevInstance.timings
}
s.wg.Add(2) s.wg.Add(2)
// Start the UDP listener // Start the UDP listener
...@@ -245,6 +255,7 @@ func (s *Statsd) Start(_ telegraf.Accumulator) error { ...@@ -245,6 +255,7 @@ func (s *Statsd) Start(_ telegraf.Accumulator) error {
// Start the line parser // Start the line parser
go s.parser() go s.parser()
log.Printf("Started the statsd service on %s\n", s.ServiceAddress) log.Printf("Started the statsd service on %s\n", s.ServiceAddress)
prevInstance = s
return nil return nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment