Skip to content

Commit

Permalink
process collector: Fixed pedantic registry failures on darwin with cg…
Browse files Browse the repository at this point in the history
…o. (#1715)

Errors:

```
 * collected metric process_resident_memory_bytes gauge:{value:8.798208e+06} with unregistered descriptor Desc{fqName: "process_resident_memory_bytes", help: "Resident memory size in bytes.", constLabels: {}, variableLabels: {}}
 * collected metric process_virtual_memory_bytes gauge:{value:4.2175053824e+11} with unregistered descriptor Desc{fqName: "process_virtual_memory_bytes", help: "Virtual memory size in bytes.", constLabels: {}, variableLabels: {}}

```

Signed-off-by: bwplotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka authored Jan 21, 2025
1 parent 038b37a commit 1bcda80
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
19 changes: 19 additions & 0 deletions prometheus/process_collector_cgo_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,22 @@ func getMemory() (*memoryInfo, error) {

return &memoryInfo{vsize: uint64(vsize), rss: uint64(rss)}, nil
}

// describe returns all descriptions of the collector for Darwin.
// Ensure that this list of descriptors is kept in sync with the metrics collected
// in the processCollect method. Any changes to the metrics in processCollect
// (such as adding or removing metrics) should be reflected in this list of descriptors.
func (c *processCollector) describe(ch chan<- *Desc) {
ch <- c.cpuTotal
ch <- c.openFDs
ch <- c.maxFDs
ch <- c.maxVsize
ch <- c.startTime
ch <- c.rss
ch <- c.vsize

/* the process could be collected but not implemented yet
ch <- c.inBytes
ch <- c.outBytes
*/
}
19 changes: 0 additions & 19 deletions prometheus/process_collector_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,6 @@ func getOpenFileCount() (float64, error) {
}
}

// describe returns all descriptions of the collector for Darwin.
// Ensure that this list of descriptors is kept in sync with the metrics collected
// in the processCollect method. Any changes to the metrics in processCollect
// (such as adding or removing metrics) should be reflected in this list of descriptors.
func (c *processCollector) describe(ch chan<- *Desc) {
ch <- c.cpuTotal
ch <- c.openFDs
ch <- c.maxFDs
ch <- c.maxVsize
ch <- c.startTime

/* the process could be collected but not implemented yet
ch <- c.rss
ch <- c.vsize
ch <- c.inBytes
ch <- c.outBytes
*/
}

func (c *processCollector) processCollect(ch chan<- Metric) {
if procs, err := unix.SysctlKinfoProcSlice("kern.proc.pid", os.Getpid()); err == nil {
if len(procs) == 1 {
Expand Down
19 changes: 19 additions & 0 deletions prometheus/process_collector_nocgo_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ package prometheus
func getMemory() (*memoryInfo, error) {
return nil, notImplementedErr
}

// describe returns all descriptions of the collector for Darwin.
// Ensure that this list of descriptors is kept in sync with the metrics collected
// in the processCollect method. Any changes to the metrics in processCollect
// (such as adding or removing metrics) should be reflected in this list of descriptors.
func (c *processCollector) describe(ch chan<- *Desc) {
ch <- c.cpuTotal
ch <- c.openFDs
ch <- c.maxFDs
ch <- c.maxVsize
ch <- c.startTime

/* the process could be collected but not implemented yet
ch <- c.rss
ch <- c.vsize
ch <- c.inBytes
ch <- c.outBytes
*/
}

0 comments on commit 1bcda80

Please # to comment.