From 36de16390027b6615bc6855e8baf6811a763baee Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Fri, 21 Oct 2016 12:12:19 +0200 Subject: [PATCH] Add File-SD metrics (#2103) * Add File-SD metrics * Count read errors, not scan errors. --- retrieval/discovery/file.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/retrieval/discovery/file.go b/retrieval/discovery/file.go index 40034944ad..ba7b9be916 100644 --- a/retrieval/discovery/file.go +++ b/retrieval/discovery/file.go @@ -21,6 +21,7 @@ import ( "strings" "time" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/log" "github.com/prometheus/common/model" "golang.org/x/net/context" @@ -32,6 +33,26 @@ import ( const fileSDFilepathLabel = model.MetaLabelPrefix + "filepath" +var ( + fileSDScanDuration = prometheus.NewSummary( + prometheus.SummaryOpts{ + Namespace: namespace, + Name: "sd_file_scan_duration_seconds", + Help: "The duration of the File-SD scan in seconds.", + }) + fileSDReadErrorsCount = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: namespace, + Name: "sd_file_read_errors_total", + Help: "The number of File-SD read errors.", + }) +) + +func init() { + prometheus.MustRegister(fileSDScanDuration) + prometheus.MustRegister(fileSDReadErrorsCount) +} + // FileDiscovery provides service discovery functionality based // on files that contain target groups in JSON or YAML format. Refreshing // happens using file watches and periodic refreshes. @@ -173,10 +194,16 @@ func (fd *FileDiscovery) stop() { // refresh reads all files matching the discovery's patterns and sends the respective // updated target groups through the channel. func (fd *FileDiscovery) refresh(ch chan<- []*config.TargetGroup) { + t0 := time.Now() + defer func() { + fileSDScanDuration.Observe(time.Since(t0).Seconds()) + }() + ref := map[string]int{} for _, p := range fd.listFiles() { tgroups, err := readFile(p) if err != nil { + fileSDReadErrorsCount.Inc() log.Errorf("Error reading file %q: %s", p, err) // Prevent deletion down below. ref[p] = fd.lastRefresh[p]