Skip to content

Commit

Permalink
Avoid possible nil pointer errors (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock authored May 12, 2023
1 parent 4f5fed9 commit 640ac7e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cgroup_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,15 @@ func (e *Exporter) getMetrics(name string, pids map[string][]int) (CgroupMetric,
metric.err = true
return metric, err
}
stats, _ := ctrl.Stat(cgroups.IgnoreNotExist)
stats, err := ctrl.Stat(cgroups.IgnoreNotExist)
if err != nil {
level.Error(e.logger).Log("msg", "Failed to stat cgroups", "path", name, "err", err)
return metric, err
}
if stats == nil {
level.Error(e.logger).Log("msg", "Cgroup stats are nil", "path", name)
return metric, err
}
if stats.CPU != nil {
if stats.CPU.Usage != nil {
metric.cpuUser = float64(stats.CPU.Usage.User) / 1000000000.0
Expand Down

0 comments on commit 640ac7e

Please sign in to comment.