Class ResourceDetector

java.lang.Object
codes.grow.packages.otelcollector.ResourceDetector

public final class ResourceDetector extends Object
Best-effort client-side resource detection: host (host.name, host.arch, os.type, os.version), process (process.pid, process.executable.path, process.runtime.*, process.owner), container (container.id from cgroups) and k8s (k8s.pod.name, k8s.namespace.name, … from the downward-API variables K8S_* / POD_*, HOSTNAME and the service-account namespace file). Detectors that find nothing add nothing.
  • Method Details

    • system

      public static ResourceDetector system()
      A detector over the process environment and file system.
      Returns:
      the detector
    • of

      public static ResourceDetector of(Map<String,String> env, Function<String,Optional<String>> readFile)
      A detector over explicit sources (tests).
      Parameters:
      env - environment variables
      readFile - reads a text file, empty when it cannot
      Returns:
      the detector
    • detect

      public Map<String,Object> detect(Collection<String> detectors)
      Runs the given detectors.
      Parameters:
      detectors - names: host, process, container, k8s
      Returns:
      the detected attributes
    • containerId

      public Optional<String> containerId()
      Container id from /proc/self/cgroup (cgroup v1) or /proc/self/mountinfo (cgroup v2).
      Returns:
      the 64-hex id, or empty