diff options
author | Paul Emm. Katsoulakis <34388743+paulkatsoulakis@users.noreply.github.com> | 2019-04-17 16:47:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-17 16:47:16 +0300 |
commit | fa5c84a61874b14a3d1a7a6dd9de424a55105f23 (patch) | |
tree | 3e33b52fdfa956d2745b433ba2f5aa890f0fd840 | |
parent | 8bc815e376ef53ace43fa5e06c2a8e33b1ba2e0a (diff) |
netdata/collectors/cgroups.plugin: When jq not available, prompt the user he may have to install jq (#5848)
* netdata/collectors/cgroups.plugin: When jq not available, pop a warning to let the user know he might have to install jq. We still support him with alternative way of retrieving the docker name, but there may be cases the user prefers the API approach
* netdata/collectors/cgroups.plugin: Missed one more jq call to handle
-rwxr-xr-x | collectors/cgroups.plugin/cgroup-name.sh.in | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/collectors/cgroups.plugin/cgroup-name.sh.in b/collectors/cgroups.plugin/cgroup-name.sh.in index 97e030852e..48f523885b 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="$(</var/run/secrets/kubernetes.io/serviceaccount/token)" - 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 -)" + if command -v jq >/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}" |