Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add process metrics receiver MacOS #17863

Closed
8naama opened this issue Jan 19, 2023 · 2 comments
Closed

Feature request: Add process metrics receiver MacOS #17863

8naama opened this issue Jan 19, 2023 · 2 comments
Labels
enhancement New feature or request needs triage New item requiring triage receiver/hostmetrics

Comments

@8naama
Copy link
Contributor

8naama commented Jan 19, 2023

Component(s)

receiver/hostmetrics

Is your feature request related to a problem? Please describe.

We want to collect process metrics for Mac. Currently the hostmetrics process metrics receiver is only implemented for windows and linux.

Describe the solution you'd like

Receiver that supports collecting process metrics in mac using shirou/gopsutil/process package.

Reference

Limitations

  1. Cwd() function is not supported in mac with no cgo
  2. disk usage for process is not implemented for darwin
  3. PID 1 returns error error reading parent pid for process "launchd" (pid 1): invalid pid 0 which seems to be related to this open issue.

Describe alternatives you've considered

I created a Fork of the repository that can collect Mac process metrics and handles the limitation like so:

  1. using Exe() function returns errors when used in the collector:
    • bad call to lsof: exit status 1 - seems like the process has 'root' as the process owner
    • missing txt data returned by lsof; - seems like the process have a memory address in DEVICE or NAME params (running lsof -p <PID> in the terminal)

Instead of Exe() or Cwd(), we can use Cmdline() and regex to cut the used path in the command. The issue is it's not always perfect:

package main

import(
	"fmt"
	"regexp"
	"github.com/shirou/gopsutil/process"
)

func main() {
	processes, err := process.Processes()
	if err != nil {
		fmt.Println(err)
	}

	for _,p := range processes {
		processExecutablePath, err := p.Exe()
		if err != nil {
			fmt.Println(err)
		}
		processCmdArgument, err := p.Cmdline()
		if err != nil {
			fmt.Println(err)
		}
		regex, _ := regexp.Compile("^\\S+")
		processCmdArgument = regex.FindString(processCmdArgument)
		if processExecutablePath != processCmdArgument {
			fmt.Printf("CMDLINE command got different value than EXE for process %v\nExe(): %v\nCmdline(): %v\n\n", p, processExecutablePath, processCmdArgument)
		}
	}
}
  1. Exclude darwin in the scrapeAndAppendDiskMetrics function to not collect the disk usage metrics
  2. Exclude PID 1 in darwin in parentPid function

Additional context

Would be happy if anyone has any recommendations and feedback or other possible solution and would be happy to help implement such solution. Are there any plans to develop this receiver?

@8naama 8naama added enhancement New feature or request needs triage New item requiring triage labels Jan 19, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

codeboten added a commit that referenced this issue Feb 23, 2023
Adding process metrics for Mac.
Currently, the hostmetrics process metrics receiver is only implemented for windows and linux.

Link to tracking Issue: Issue #17863

---------

Co-authored-by: Alex Boten <[email protected]>
Co-authored-by: Antoine Toulme <[email protected]>
@codeboten
Copy link
Contributor

Fixed by #18723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage New item requiring triage receiver/hostmetrics
Projects
None yet
Development

No branches or pull requests

2 participants