@cryptotaxi247 / netdata-1 / commits / e38a4953c

add "unix://" scheme to DOCKER_HOST in run.sh (#20286)

Ilya Mashchenko committed May 15, 2025 at 15:10 UTC e38a4953c30dfa69c4aefc1f06f149b6548836d4
2 files changed +22 -10
packaging/docker/run.sh
+2 -2
@@ -68,11 +68,11 @@ if [ "${EUID}" -eq 0 ]; then
68 re='^[0-9]+$'
69 if [[ $BALENA_PGID =~ $re ]]; then
70 echo "Netdata detected balena-engine.sock"
71 - DOCKER_HOST='/var/run/balena-engine.sock'
71 + DOCKER_HOST='unix:///var/run/balena-engine.sock'
72 PGID="$BALENA_PGID"
73 elif [[ $DOCKER_PGID =~ $re ]]; then
74 echo "Netdata detected docker.sock"
75 - DOCKER_HOST="/var/run/docker.sock"
75 + DOCKER_HOST="unix:///var/run/docker.sock"
76 PGID="$DOCKER_PGID"
77 fi
78 export PGID
src/collectors/cgroups.plugin/cgroup-name.sh.in
+20 -8
@@ -147,25 +147,37 @@ function docker_like_get_name_command() {
147 function docker_like_get_name_api() {
148 local host_var="${1}"
149 local host="${!host_var}"
150 - local path="/containers/${2}/json"
150 + local container_id="${2}"
151 + local path="/containers/${container_id}/json"
152 +
153 if [ -z "${host}" ]; then
154 warning "No ${host_var} is set"
155 return 1
156 fi
157 +
158 if ! command -v jq >/dev/null 2>&1; then
159 warning "Can't find jq command line tool. jq is required for netdata to retrieve container name using ${host} API, falling back to docker ps"
160 return 1
161 fi
159 - if [ -S "${host}" ]; then
160 - info "Running API command: curl --unix-socket \"${host}\" http://localhost${path}"
161 - JSON=$(curl -sS --unix-socket "${host}" "http://localhost${path}")
162 +
163 + if [[ "${host}" =~ ^([a-z]+)://(.*) ]]; then
164 + address="${BASH_REMATCH[2]}"
165 + else
166 + address="${host}"
167 + fi
168 +
169 + if [ -S "${address}" ]; then
170 + info "Running API command: curl --unix-socket \"${address}\" http://localhost${path}"
171 + JSON=$(curl -sS --unix-socket "${address}" "http://localhost${path}")
172 else
163 - info "Running API command: curl \"${host}${path}\""
164 - JSON=$(curl -sS "${host}${path}")
173 + info "Running API command: curl \"${address}${path}\""
174 + JSON=$(curl -sS "${address}${path}")
175 fi
176 +
177 if OUTPUT=$(echo "${JSON}" | jq -r '.Config.Env[]?, "CONT_NAME=\(.Name)", "IMAGE_NAME=\(.Config.Image)", (.Config.Labels | to_entries[] | "LABEL_\(.key)=\(.value)")') && [ -n "$OUTPUT" ]; then
178 parse_docker_like_inspect_output "$OUTPUT"
179 fi
180 +
181 return 0
182 }
183
@@ -615,8 +627,8 @@ function podman_validate_id() {
627
628 # -----------------------------------------------------------------------------
629
618 -DOCKER_HOST="${DOCKER_HOST:=/var/run/docker.sock}"
619 -PODMAN_HOST="${PODMAN_HOST:=/run/podman/podman.sock}"
630 +DOCKER_HOST="${DOCKER_HOST:=unix:///var/run/docker.sock}"
631 +PODMAN_HOST="${PODMAN_HOST:=unix:///run/podman/podman.sock}"
632 CGROUP_PATH="${1}" # the path as it is (e.g. '/docker/efcf4c409')
633 CGROUP="${2//\//_}" # the modified path (e.g. 'docker_efcf4c409')
634 EXIT_SUCCESS=0