Skip to content
Snippets Groups Projects
Commit 1e9bb4ec authored by Wei Li's avatar Wei Li Committed by Ben Kochie
Browse files

textfile: fix duplicate metrics error (#738)


The textfile gatherer should only be added to gatherer list once.

Signed-off-by: default avatarLi Wei <liwei@anbutu.com>
parent a96f1738
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -22,6 +22,7 @@ import (
"path/filepath"
"sort"
"strings"
"sync"
"time"
 
"github.com/golang/protobuf/proto"
Loading
Loading
@@ -34,6 +35,7 @@ import (
 
var (
textFileDirectory = kingpin.Flag("collector.textfile.directory", "Directory to read text files with metrics from.").Default("").String()
textFileAddOnce sync.Once
)
 
type textFileCollector struct {
Loading
Loading
@@ -56,10 +58,12 @@ func NewTextFileCollector() (Collector, error) {
// the flag is not passed.
log.Infof("No directory specified, see --collector.textfile.directory")
} else {
prometheus.DefaultGatherer = prometheus.Gatherers{
prometheus.DefaultGatherer,
prometheus.GathererFunc(func() ([]*dto.MetricFamily, error) { return c.parseTextFiles(), nil }),
}
textFileAddOnce.Do(func() {
prometheus.DefaultGatherer = prometheus.Gatherers{
prometheus.DefaultGatherer,
prometheus.GathererFunc(func() ([]*dto.MetricFamily, error) { return c.parseTextFiles(), nil }),
}
})
}
 
return c, nil
Loading
Loading
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