Skip to content

Jetson core check fails to execute tegrastats in Agent 7.78.0 #50654

@junyu-junyu

Description

@junyu-junyu

Summary

The NVIDIA Jetson core check fails in Datadog Agent 7.78.0 when running tegrastats.

The check builds a shell command string like:

(/usr/bin/tegrastats --interval 500) & pid=$!; (sleep 1 && kill -9 $pid)

but in Agent 7.78.0 it is passed directly to exec.CommandContext(ctx, cmdStr), so Go tries to execute the entire shell expression as a binary path.

This causes errors such as:

fork/exec (/usr/bin/tegrastats --interval 500) & pid=$!; (sleep 1 && kill -9 $pid): no such file or directory

When use_sudo: true, it also fails because sudo receives the shell expression as a command without sh -c:

tegrastats did not produce any output: exit status 1. Stderr: usage: sudo ...

Affected version

  • Datadog Agent: 7.78.0
  • Platform: NVIDIA Jetson / Ubuntu 18.04 / aarch64
  • Integration: jetson

Configuration

instances:
  -
    tegrastats_path: /usr/bin/tegrastats
    use_sudo: false

With use_sudo: true, the error changes to the sudo usage output, but the root cause appears to be the same missing shell invocation.

Observed behavior

Running:

/opt/datadog-agent/bin/agent/agent check jetson

returns:

Error: fork/exec (/usr/bin/tegrastats --interval 500) & pid=$!; (sleep 1 && kill -9 $pid): no such file or directory

The service logs show repeated failures:

check:jetson | Error running check: tegrastats did not produce any output

Expected behavior

The Jetson check should execute tegrastats, collect one sample, parse it, and submit nvidia.jetson.* metrics.

Source code difference

In Agent 7.76.3, the check used sh -c:

if c.useSudo {
    cmd = exec.Command("sudo", "-n", "sh", "-c", cmdStr)
} else {
    cmd = exec.Command("sh", "-c", cmdStr)
}

Reference:

https://github.com/DataDog/datadog-agent/blob/7.76.3/pkg/collector/corechecks/nvidia/jetson/jetson.go#L124-L135

In Agent 7.78.0, this changed to:

if c.useSudo {
    cmd = exec.CommandContext(ctx, "sudo", "-n", cmdStr)
} else {
    cmd = exec.CommandContext(ctx, cmdStr)
}

Reference:

https://github.com/DataDog/datadog-agent/blob/7.78.0/pkg/collector/corechecks/nvidia/jetson/jetson.go#L146-L162

Because cmdStr contains shell syntax such as parentheses, &, $!, ;, and &&, it must be executed via sh -c.

Suggested fix

Use exec.CommandContext while preserving sh -c, for example:

if c.useSudo {
    cmd = exec.CommandContext(ctx, "sudo", "-n", "sh", "-c", cmdStr)
} else {
    cmd = exec.CommandContext(ctx, "sh", "-c", cmdStr)
}

Alternatively, avoid shell syntax entirely by starting tegrastats directly with args and handling timeout/process termination in Go.

Workaround

A local symlink/wrapper workaround can make the invalid executable path resolve, but this is not ideal and should not be required.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions