Cleanup collect_error metric

This commit is contained in:
Trey Dockendorf 2020-02-20 14:45:43 -05:00
parent 7043a29cb6
commit 903b0fd581
1 changed files with 5 additions and 4 deletions

View File

@ -237,7 +237,7 @@ func NewExporter(paths []string) *Exporter {
info: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "info"), info: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "info"),
"User slice information", []string{"cgroup", "username", "uid", "jobid"}, nil), "User slice information", []string{"cgroup", "username", "uid", "jobid"}, nil),
collectError: prometheus.NewDesc(prometheus.BuildFQName(namespace, "exporter", "collect_error"), collectError: prometheus.NewDesc(prometheus.BuildFQName(namespace, "exporter", "collect_error"),
"Indicates collection error, 0=no error, 1=error", []string{"path", "error"}, nil), "Indicates collection error, 0=no error, 1=error", []string{"path"}, nil),
} }
} }
@ -249,13 +249,13 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) ([]CgroupMetric, error)
control, err := cgroups.Load(subsystem, cgroups.StaticPath(path)) control, err := cgroups.Load(subsystem, cgroups.StaticPath(path))
if err != nil { if err != nil {
log.Errorf("Error loading cgroup subsystem path %s: %s", path, err.Error()) log.Errorf("Error loading cgroup subsystem path %s: %s", path, err.Error())
ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 1, path, "load-subsystem") ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 1, path)
continue continue
} }
processes, err := control.Processes(cgroups.Cpuacct, true) processes, err := control.Processes(cgroups.Cpuacct, true)
if err != nil { if err != nil {
log.Errorf("Error loading cgroup processes for path %s: %s", path, err.Error()) log.Errorf("Error loading cgroup processes for path %s: %s", path, err.Error())
ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 1, path, "load-processes") ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 1, path)
continue continue
} }
log.Debugf("Found %d processes", len(processes)) log.Debugf("Found %d processes", len(processes))
@ -276,7 +276,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) ([]CgroupMetric, error)
}) })
if err != nil { if err != nil {
log.Errorf("Failed to load cgroups for %s: %s", name, err.Error()) log.Errorf("Failed to load cgroups for %s: %s", name, err.Error())
ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 1, name, "load-subsystem") ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 1, name)
continue continue
} }
stats, _ := ctrl.Stat(cgroups.IgnoreNotExist) stats, _ := ctrl.Stat(cgroups.IgnoreNotExist)
@ -295,6 +295,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) ([]CgroupMetric, error)
getInfo(name, &metric) getInfo(name, &metric)
metrics = append(metrics, metric) metrics = append(metrics, metric)
} }
ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 0, path)
} }
return metrics, nil return metrics, nil