Browse Source

file sd: create and increment an inotify error counter when file-SD i… (#11066)

* file sd: create and increment an inotify error counter when file-SD is unable to watch files. Additionally, order metrics alphabetically.

Signed-off-by: Michael Fuller <mfuller@digitalocean.com>

* file.go: consistent naming and help for prometheus_sd_file_watcher_errors_total

Signed-off-by: Michael Fuller <mfuller@digitalocean.com>

Signed-off-by: Michael Fuller <mfuller@digitalocean.com>
Co-authored-by: Michael Fuller <mfuller@digitalocean.com>
pull/11605/head^2
Michael Fuller 2 years ago committed by GitHub
parent
commit
15ba7a0d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      discovery/file/file.go

16
discovery/file/file.go

@ -39,18 +39,23 @@ import (
) )
var ( var (
fileSDReadErrorsCount = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "prometheus_sd_file_read_errors_total",
Help: "The number of File-SD read errors.",
})
fileSDScanDuration = prometheus.NewSummary( fileSDScanDuration = prometheus.NewSummary(
prometheus.SummaryOpts{ prometheus.SummaryOpts{
Name: "prometheus_sd_file_scan_duration_seconds", Name: "prometheus_sd_file_scan_duration_seconds",
Help: "The duration of the File-SD scan in seconds.", Help: "The duration of the File-SD scan in seconds.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}, Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}) })
fileSDReadErrorsCount = prometheus.NewCounter( fileSDTimeStamp = NewTimestampCollector()
fileWatcherErrorsCount = prometheus.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "prometheus_sd_file_read_errors_total", Name: "prometheus_sd_file_watcher_errors_total",
Help: "The number of File-SD read errors.", Help: "The number of File-SD errors caused by filesystem watch failures.",
}) })
fileSDTimeStamp = NewTimestampCollector()
patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`) patFileSDName = regexp.MustCompile(`^[^*]*(\*[^/]*)?\.(json|yml|yaml|JSON|YML|YAML)$`)
@ -62,7 +67,7 @@ var (
func init() { func init() {
discovery.RegisterConfig(&SDConfig{}) discovery.RegisterConfig(&SDConfig{})
prometheus.MustRegister(fileSDScanDuration, fileSDReadErrorsCount, fileSDTimeStamp) prometheus.MustRegister(fileSDReadErrorsCount, fileSDScanDuration, fileSDTimeStamp, fileWatcherErrorsCount)
} }
// SDConfig is the configuration for file based discovery. // SDConfig is the configuration for file based discovery.
@ -237,6 +242,7 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
level.Error(d.logger).Log("msg", "Error adding file watcher", "err", err) level.Error(d.logger).Log("msg", "Error adding file watcher", "err", err)
fileWatcherErrorsCount.Inc()
return return
} }
d.watcher = watcher d.watcher = watcher

Loading…
Cancel
Save