Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/collector/nginxplusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/nginx/agent/v3/internal/collector/nginxplusreceiver/internal/metadata"
)

// nolint: ireturn
const defaultTimeout = 10 * time.Second

// nolint: ireturn
Expand Down
21 changes: 20 additions & 1 deletion internal/watcher/instance/nginx_process_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func (npp *NginxProcessParser) getInfo(ctx context.Context, proc *nginxprocess.P
}
}

confPath := getConfPathFromCommand(proc.Cmd)

var nginxInfo *Info

outputBuffer, err := npp.executer.RunCmd(ctx, exePath, "-V")
Expand All @@ -148,6 +150,10 @@ func (npp *NginxProcessParser) getInfo(ctx context.Context, proc *nginxprocess.P
nginxInfo.ExePath = exePath
nginxInfo.ProcessID = proc.PID

if nginxInfo.ConfPath = getNginxConfPath(ctx, nginxInfo); confPath != "" {
nginxInfo.ConfPath = confPath
}

loadableModules := getLoadableModules(nginxInfo)
nginxInfo.LoadableModules = loadableModules

Expand Down Expand Up @@ -268,7 +274,6 @@ func parseNginxVersionCommandOutput(ctx context.Context, output *bytes.Buffer) *
}

nginxInfo.Prefix = getNginxPrefix(ctx, nginxInfo)
nginxInfo.ConfPath = getNginxConfPath(ctx, nginxInfo)

return nginxInfo
}
Expand Down Expand Up @@ -392,3 +397,17 @@ func convertToMap(processes []*nginxprocess.Process) map[int32]*nginxprocess.Pro

return processesByPID
}

func getConfPathFromCommand(command string) string {
commands := strings.Split(command, " ")

for i, command := range commands {
if command == "-c" {
if i < len(commands)-1 {
return commands[i+1]
}
}
}

return ""
}
11 changes: 11 additions & 0 deletions internal/watcher/instance/nginx_process_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,14 @@ func TestNginxProcessParser_GetExe(t *testing.T) {
})
}
}

func TestGetConfigPathFromCommand(t *testing.T) {
result := getConfPathFromCommand("nginx: master process nginx -c /tmp/nginx.conf")
assert.Equal(t, "/tmp/nginx.conf", result)

result = getConfPathFromCommand("nginx: master process nginx -c")
assert.Equal(t, "", result)

result = getConfPathFromCommand("")
assert.Equal(t, "", result)
}