Skip to content

Commit

Permalink
Cleanup collect_error metric
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Feb 20, 2020
1 parent 7043a29 commit 903b0fd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cgroup_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func NewExporter(paths []string) *Exporter {
info: prometheus.NewDesc(prometheus.BuildFQName(namespace, "", "info"),
"User slice information", []string{"cgroup", "username", "uid", "jobid"}, nil),
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),
}
}

Expand All @@ -249,13 +249,13 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) ([]CgroupMetric, error)
control, err := cgroups.Load(subsystem, cgroups.StaticPath(path))
if err != nil {
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
}
processes, err := control.Processes(cgroups.Cpuacct, true)
if err != nil {
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
}
log.Debugf("Found %d processes", len(processes))
Expand All @@ -276,7 +276,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) ([]CgroupMetric, error)
})
if err != nil {
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
}
stats, _ := ctrl.Stat(cgroups.IgnoreNotExist)
Expand All @@ -295,6 +295,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) ([]CgroupMetric, error)
getInfo(name, &metric)
metrics = append(metrics, metric)
}
ch <- prometheus.MustNewConstMetric(e.collectError, prometheus.GaugeValue, 0, path)
}

return metrics, nil
Expand Down

0 comments on commit 903b0fd

Please sign in to comment.