Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Dec 1, 2023
1 parent 7fc2229 commit f32a61c
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type Config struct {
// the collector does not have permission for.
MuteProcessIOError bool `mapstructure:"mute_process_io_error,omitempty"`

// MuteProcessCgroupError is a flag that will mute the error encountered when trying to read the cgroup of a process
// the collector does not have permission for.
MuteProcessCgroupError bool `mapstructure:"mute_process_cgroup_error,omitempty"`

// ResilientProcessScraping is a flag that will let the collector continue reading a process even when
// the collector does not have permission to read it's executable path (Linux)
MuteProcessExeError bool `mapstructure:"mute_process_exe_error,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Process threads count.
| Name | Description | Values | Enabled |
| ---- | ----------- | ------ | ------- |
| process.cgroup | cgroup associated with the process. | Any Str | false |
| process.command | The command used to launch the process (i.e. the command name). On Linux based systems, can be set to the zeroth string in proc/[pid]/cmdline. On Windows, can be set to the first parameter extracted from GetCommandLineW. | Any Str | true |
| process.command_line | The full command used to launch the process as a single string representing the full command. On Windows, can be set to the result of GetCommandLineW. Do not set this if you have to assemble it just for monitoring; use process.command_args instead. | Any Str | true |
| process.executable.name | The name of the process executable. On Linux based systems, can be set to the Name in proc/[pid]/status. On Windows, can be set to the base name of GetProcessImageFileNameW. | Any Str | true |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ all_set:
process.threads:
enabled: true
resource_attributes:
process.cgroup:
enabled: true
process.command:
enabled: true
process.command_line:
Expand Down Expand Up @@ -71,6 +73,8 @@ none_set:
process.threads:
enabled: false
resource_attributes:
process.cgroup:
enabled: false
process.command:
enabled: false
process.command_line:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ resource_attributes:
description: The username of the user that owns the process.
enabled: true
type: string
process.cgroup:
description: cgroup associated with the process.
enabled: false
type: string

attributes:
direction:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type processMetadata struct {
}

type executableMetadata struct {
name string
path string
name string
path string
cgroup string
}

type commandMetadata struct {
Expand All @@ -46,6 +47,7 @@ func (m *processMetadata) buildResource(rb *metadata.ResourceBuilder) pcommon.Re
rb.SetProcessParentPid(int64(m.parentPid))
rb.SetProcessExecutableName(m.executable.name)
rb.SetProcessExecutablePath(m.executable.path)
rb.SetProcessCgroup(m.executable.cgroup)
if m.command != nil {
rb.SetProcessCommand(m.command.command)
if m.command.commandLineSlice != nil {
Expand Down Expand Up @@ -73,6 +75,7 @@ type processHandles interface {

type processHandle interface {
NameWithContext(context.Context) (string, error)
CgroupWithContext(context.Context) (string, error)
ExeWithContext(context.Context) (string, error)
UsernameWithContext(context.Context) (string, error)
CmdlineWithContext(context.Context) (string, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,15 @@ func (s *scraper) getProcessMetadata() ([]*processMetadata, error) {
}
continue
}
cgroup, err := getProcessCgroup(ctx, handle)
if err != nil {
if !s.config.MuteProcessCgroupError {
errs.AddPartial(1, fmt.Errorf("error reading process cgroup for pid %v: %w", pid, err))
}
continue
}

executable := &executableMetadata{name: name, path: exe}
executable := &executableMetadata{name: name, path: exe, cgroup: cgroup}

// filter processes by name
if (s.includeFS != nil && !s.includeFS.Matches(executable.name)) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func getProcessName(ctx context.Context, proc processHandle, _ string) (string,
return name, nil
}

func getProcessCgroup(ctx context.Context, proc processHandle) (string, error) {
cgroup, err := proc.CgroupWithContext(ctx)
if err != nil {
return "", err
}

return cgroup, nil
}

func getProcessExecutable(ctx context.Context, proc processHandle) (string, error) {
cmdline, err := proc.CmdlineWithContext(ctx)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func getProcessExecutable(ctx context.Context, proc processHandle) (string, erro
return exe, nil
}

func getProcessCgroup(ctx context.Context, proc processHandle) (string, error) {
cgroup, err := proc.CgroupWithContext(ctx)
if err != nil {
return "", err
}

return cgroup, nil
}

func getProcessCommand(ctx context.Context, proc processHandle) (*commandMetadata, error) {
cmdline, err := proc.CmdlineSliceWithContext(ctx)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func getProcessName(context.Context, processHandle, string) (string, error) {
return "", nil
}

func getProcessCgroup(ctx context.Context, proc processHandle) (string, error) {
return "", nil
}

func getProcessExecutable(context.Context, processHandle) (string, error) {
return "", nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ func getProcessName(_ context.Context, _ processHandle, exePath string) (string,
return filepath.Base(exePath), nil
}

func getProcessCgroup(ctx context.Context, proc processHandle) (string, error) {
cgroup, err := proc.CgroupWithContext(ctx)
if err != nil {
return "", err
}

return cgroup, nil
}

func getProcessExecutable(ctx context.Context, proc processHandle) (string, error) {
exe, err := proc.ExeWithContext(ctx)
if err != nil {
Expand Down

0 comments on commit f32a61c

Please sign in to comment.