summaryrefslogtreecommitdiffstats
path: root/collectors/cgroups.plugin/cgroup-name.sh.in
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2019-08-04 08:57:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2019-08-04 08:57:13 +0000
commitcbf70980c060bde02906a8e9de2064459bacc93c (patch)
tree5b9ade02e0ed32a4b33f5e8647092d0c02ea586d /collectors/cgroups.plugin/cgroup-name.sh.in
parentReleasing debian version 1.16.0-1. (diff)
downloadnetdata-cbf70980c060bde02906a8e9de2064459bacc93c.tar.xz
netdata-cbf70980c060bde02906a8e9de2064459bacc93c.zip
Merging upstream version 1.16.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/cgroups.plugin/cgroup-name.sh.in')
-rwxr-xr-xcollectors/cgroups.plugin/cgroup-name.sh.in19
1 files changed, 13 insertions, 6 deletions
diff --git a/collectors/cgroups.plugin/cgroup-name.sh.in b/collectors/cgroups.plugin/cgroup-name.sh.in
index 48f523885..784c06042 100755
--- a/collectors/cgroups.plugin/cgroup-name.sh.in
+++ b/collectors/cgroups.plugin/cgroup-name.sh.in
@@ -53,18 +53,25 @@ function docker_get_name_classic() {
}
function docker_get_name_api() {
- local id="${1}"
- if [ ! -S "${DOCKER_HOST}" ]; then
- warning "Can't find ${DOCKER_HOST}"
+ local path="/containers/${1}/json"
+ if [ -z "${DOCKER_HOST}" ]; then
+ warning "No DOCKER_HOST is set"
return 1
fi
if ! command -v jq >/dev/null 2>&1; then
warning "Can't find jq command line tool. jq is required for netdata to retrieve docker container name using ${DOCKER_HOST} API, falling back to docker ps"
return 1
fi
-
- info "Running API command: /containers/${id}/json"
- JSON=$(echo -e "GET /containers/${id}/json HTTP/1.0\\r\\n" | nc -U "${DOCKER_HOST}" | grep '^{.*')
+ if [ -S "${DOCKER_HOST}" ]; then
+ info "Running API command: curl --unix-socket ${DOCKER_HOST} http://localhost${path}"
+ JSON=$(curl -sS --unix-socket "${DOCKER_HOST}" "http://localhost${path}")
+ elif [ "${DOCKER_HOST}" == "/var/run/docker.sock" ]; then
+ warning "Docker socket was not found at ${DOCKER_HOST}"
+ return 1
+ else
+ info "Running API command: curl ${DOCKER_HOST}${path}"
+ JSON=$(curl -sS "${DOCKER_HOST}${path}")
+ fi
NAME=$(echo "$JSON" | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||')
return 0
}