From 58b482856cf37b0519e516ab8dc1105ba958f8b2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 26 Apr 2019 18:22:17 +0200 Subject: Adding upstream version 1.14.0. Signed-off-by: Daniel Baumann --- collectors/cgroups.plugin/cgroup-name.sh.in | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'collectors/cgroups.plugin/cgroup-name.sh.in') diff --git a/collectors/cgroups.plugin/cgroup-name.sh.in b/collectors/cgroups.plugin/cgroup-name.sh.in index 97e030852..48f523885 100755 --- a/collectors/cgroups.plugin/cgroup-name.sh.in +++ b/collectors/cgroups.plugin/cgroup-name.sh.in @@ -58,6 +58,11 @@ function docker_get_name_api() { warning "Can't find ${DOCKER_HOST}" 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 '^{.*') NAME=$(echo "$JSON" | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||') @@ -71,12 +76,17 @@ function k8s_get_name() { id="${1##*/}" fi KUBE_TOKEN="$(/dev/null 2>&1; then + NAME="$( + curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" "https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/pods" | + jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_\(.status.containerStatuses[0].name) \(.status.containerStatuses[0].containerID)"' | + grep "$id" | + cut -d' ' -f1 + )" + else + warning "jq command not available, k8s_get_name() cannot execute. Please install jq should you wish for k8s to be fully functional" + fi + if [ -z "${NAME}" ]; then warning "cannot find the name of k8s pod with containerID '${id}'. Setting name to ${id} and disabling it" NAME="${id}" -- cgit v1.2.3