]> arthur.barton.de Git - netdata.git/blob - plugins.d/cgroup-name.sh
Merge pull request #308 from ktsaou/master
[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 | grep "^${CGROUP:7:12}" | sed "s/[[:space:]]\+/ /g" | cut -d ' ' -f 2)"
30         [ -z "${NAME}" ] && NAME="${CGROUP:0:19}"
31 fi
32
33 if [ -z "${NAME}" ]
34         then
35         if [ ${#CGROUP} -gt 20 ]
36                 then
37                 NAME="${CGROUP:0:20}"
38         else
39                 NAME="${CGROUP}"
40         fi
41 fi
42
43 echo >&2 "${0}: cgroup '${CGROUP}' is named as '${NAME}'"
44 echo "${NAME}"