]> arthur.barton.de Git - netdata.git/blob - plugins.d/cgroup-name.sh
cgroup-name.sh now extracts proper docker names #115
[netdata.git] / plugins.d / cgroup-name.sh
1 #!/bin/bash
2
3 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
4
5 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
6 CONFIG="${NETDATA_CONFIG_DIR}/cgroups-names.conf"
7 CGROUP="${1}"
8 NAME=
9
10 if [ -z "${CGROUP}" ]
11         then
12         echo >&2 "${0}: called without a cgroup name. Nothing to do."
13         exit 1
14 fi
15
16 if [ -f "${CONFIG}" ]
17         then
18         NAME="$(cat "${CONFIG}" | grep "^${CGROUP} " | sed "s/[[:space:]]\+/ /g" | cut -d ' ' -f 2)"
19         if [ -z "${NAME}" ]
20                 then
21                 echo >&2 "${0}: cannot find cgroup '${CGROUP}' in '${CONFIG}'."
22         fi
23 else
24         echo >&2 "${0}: configuration file '${CONFIG}' is not available."
25 fi
26
27 if [ -z "${NAME}" -a "${CGROUP:0:7}" = "docker/" ]
28         then
29         NAME="$(docker ps --filter=id="${CGROUP:7:64}" --format="{{.Names}}")"
30         [ -z "${NAME}" ] && NAME="${CGROUP:0:19}"
31         [ ${#NAME} -gt 20 ] && NAME="${NAME:0:20}"
32 fi
33
34 if [ -z "${NAME}" ]
35         then
36         if [ ${#CGROUP} -gt 20 ]
37                 then
38                 NAME="${CGROUP:0:20}"
39         else
40                 NAME="${CGROUP}"
41         fi
42 fi
43
44 echo >&2 "${0}: cgroup '${CGROUP}' is named as '${NAME}'"
45 echo "${NAME}"