Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 22 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,12 @@ func (npp *NginxProcessParser) getInfo(ctx context.Context, proc *nginxprocess.P
nginxInfo.ExePath = exePath
nginxInfo.ProcessID = proc.PID

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

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

Expand Down Expand Up @@ -268,7 +276,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 +399,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)
}