Skip to content

Commit

Permalink
Merge pull request #2123 from prometheus/superq/cpuGuest
Browse files Browse the repository at this point in the history
Add flag to disable guest CPU metrics
  • Loading branch information
SuperQ authored Aug 17, 2021
2 parents 832909d + 84b36c4 commit 9956773
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* [ENHANCEMENT]
* [BUGFIX]

* [ENHANCEMENT] Add flag to disable guest CPU metrics #2123

## 1.2.2 / 2021-08-06

* [BUGFIX] Fix processes collector long int parsing #2112
Expand Down
9 changes: 6 additions & 3 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type cpuCollector struct {
const jumpBackSeconds = 3.0

var (
enableCPUGuest = kingpin.Flag("collector.cpu.guest", "Enables metric node_cpu_guest_seconds_total").Default("true").Bool()
enableCPUInfo = kingpin.Flag("collector.cpu.info", "Enables metric cpu_info").Bool()
flagsInclude = kingpin.Flag("collector.cpu.info.flags-include", "Filter the `flags` field in cpuInfo with a value that must be a regular expression").String()
bugsInclude = kingpin.Flag("collector.cpu.info.bugs-include", "Filter the `bugs` field in cpuInfo with a value that must be a regular expression").String()
Expand Down Expand Up @@ -296,9 +297,11 @@ func (c *cpuCollector) updateStat(ch chan<- prometheus.Metric) error {
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, cpuStat.SoftIRQ, cpuNum, "softirq")
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, cpuStat.Steal, cpuNum, "steal")

// Guest CPU is also accounted for in cpuStat.User and cpuStat.Nice, expose these as separate metrics.
ch <- prometheus.MustNewConstMetric(c.cpuGuest, prometheus.CounterValue, cpuStat.Guest, cpuNum, "user")
ch <- prometheus.MustNewConstMetric(c.cpuGuest, prometheus.CounterValue, cpuStat.GuestNice, cpuNum, "nice")
if *enableCPUGuest {
// Guest CPU is also accounted for in cpuStat.User and cpuStat.Nice, expose these as separate metrics.
ch <- prometheus.MustNewConstMetric(c.cpuGuest, prometheus.CounterValue, cpuStat.Guest, cpuNum, "user")
ch <- prometheus.MustNewConstMetric(c.cpuGuest, prometheus.CounterValue, cpuStat.GuestNice, cpuNum, "nice")
}
}

return nil
Expand Down

0 comments on commit 9956773

Please sign in to comment.