summaryrefslogtreecommitdiffstats
path: root/collectors/cgroups.plugin/cgroup-network-helper.sh
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/cgroups.plugin/cgroup-network-helper.sh')
-rwxr-xr-xcollectors/cgroups.plugin/cgroup-network-helper.sh17
1 files changed, 10 insertions, 7 deletions
diff --git a/collectors/cgroups.plugin/cgroup-network-helper.sh b/collectors/cgroups.plugin/cgroup-network-helper.sh
index 1b60f452a..f355480b8 100755
--- a/collectors/cgroups.plugin/cgroup-network-helper.sh
+++ b/collectors/cgroups.plugin/cgroup-network-helper.sh
@@ -76,7 +76,7 @@ debug() {
pid=
cgroup=
-while [ ! -z "${1}" ]
+while [ -n "${1}" ]
do
case "${1}" in
--cgroup) cgroup="${2}"; shift 1;;
@@ -164,7 +164,7 @@ virsh_find_all_interfaces_for_cgroup() {
# shellcheck disable=SC2230
virsh="$(which virsh 2>/dev/null || command -v virsh 2>/dev/null)"
- if [ ! -z "${virsh}" ]
+ if [ -n "${virsh}" ]
then
local d
d="$(virsh_cgroup_to_domain_name "${c}")"
@@ -172,7 +172,7 @@ virsh_find_all_interfaces_for_cgroup() {
# e.g.: vm01\x2dweb => vm01-web (https://github.com/netdata/netdata/issues/11088#issuecomment-832618149)
d="$(printf '%b' "${d}")"
- if [ ! -z "${d}" ]
+ if [ -n "${d}" ]
then
debug "running: virsh domiflist ${d}; to find the network interfaces"
@@ -203,8 +203,11 @@ netnsid_find_all_interfaces_for_pid() {
local pid="${1}"
[ -z "${pid}" ] && return 1
- local nsid=$(lsns -t net -p ${pid} -o NETNSID -nr)
- [ -z "${nsid}" -o "${nsid}" = "unassigned" ] && return 1
+ local nsid
+ nsid=$(lsns -t net -p "${pid}" -o NETNSID -nr 2>/dev/null)
+ if [ -z "${nsid}" ] || [ "${nsid}" = "unassigned" ]; then
+ return 1
+ fi
set_source "netnsid"
ip link show |\
@@ -234,14 +237,14 @@ netnsid_find_all_interfaces_for_cgroup() {
find_all_interfaces_of_pid_or_cgroup() {
local p="${1}" c="${2}" # the pid and the cgroup path
- if [ ! -z "${pid}" ]
+ if [ -n "${pid}" ]
then
# we have been called with a pid
proc_pid_fdinfo_iff "${p}"
netnsid_find_all_interfaces_for_pid "${p}"
- elif [ ! -z "${c}" ]
+ elif [ -n "${c}" ]
then
# we have been called with a cgroup