docker install: support for Proxmox vms/containers name resolution (#16193)
Ilya Mashchenko committed
Oct 20, 2023 at 17:29 UTC
3a3ce98db4f525f723e8cd2383fd924b43b5490e
2 files changed
+33
-8
collectors/cgroups.plugin/cgroup-name.sh
+6
-8
@@ -620,21 +620,19 @@ if [ -z "${NAME}" ]; then
620
# libvirtd / qemu virtual machines
621
NAME="qemu_$(echo "${CGROUP}" | sed 's/^machine_//; s/\.libvirt-qemu$//; s/-/_/;')"
622
623
- elif [[ ${CGROUP} =~ qemu.slice_([0-9]+).scope && -d /etc/pve ]]; then
623
+ elif [[ ${CGROUP} =~ qemu.slice_([0-9]+).scope && -d "${NETDATA_HOST_PREFIX}/etc/pve" ]]; then
624
# Proxmox VMs
625
-
626
- FILENAME="/etc/pve/qemu-server/${BASH_REMATCH[1]}.conf"
625
+ FILENAME="${NETDATA_HOST_PREFIX}/etc/pve/qemu-server/${BASH_REMATCH[1]}.conf"
626
if [[ -f $FILENAME && -r $FILENAME ]]; then
628
- NAME="qemu_$(grep -e '^name: ' "/etc/pve/qemu-server/${BASH_REMATCH[1]}.conf" | head -1 | sed -rn 's|\s*name\s*:\s*(.*)?$|\1|p')"
627
+ NAME="qemu_$(grep -e '^name: ' "${FILENAME}" | head -1 | sed -rn 's|\s*name\s*:\s*(.*)?$|\1|p')"
628
else
629
error "proxmox config file missing ${FILENAME} or netdata does not have read access. Please ensure netdata is a member of www-data group."
630
fi
632
- elif [[ ${CGROUP} =~ lxc_([0-9]+) && -d /etc/pve ]]; then
631
+ elif [[ ${CGROUP} =~ lxc_([0-9]+) && -d "${NETDATA_HOST_PREFIX}/etc/pve" ]]; then
632
# Proxmox Containers (LXC)
634
-
635
- FILENAME="/etc/pve/lxc/${BASH_REMATCH[1]}.conf"
633
+ FILENAME="${NETDATA_HOST_PREFIX}/etc/pve/lxc/${BASH_REMATCH[1]}.conf"
634
if [[ -f ${FILENAME} && -r ${FILENAME} ]]; then
637
- NAME=$(grep -e '^hostname: ' "/etc/pve/lxc/${BASH_REMATCH[1]}.conf" | head -1 | sed -rn 's|\s*hostname\s*:\s*(.*)?$|\1|p')
635
+ NAME=$(grep -e '^hostname: ' "${FILENAME}" | head -1 | sed -rn 's|\s*hostname\s*:\s*(.*)?$|\1|p')
636
else
637
error "proxmox config file missing ${FILENAME} or netdata does not have read access. Please ensure netdata is a member of www-data group."
638
fi
packaging/docker/run.sh
+27
@@ -46,6 +46,33 @@ if [ -n "${PGID}" ]; then
46
usermod -a -G "${PGID}" "${DOCKER_USR}" || echo >&2 "Could not add netdata user to group docker with ID ${PGID}"
47
fi
48
49
+# Needed to read Proxmox VMs and (LXC) containers configuration files (name resolution + CPU and memory limits)
50
+function add_netdata_to_proxmox_conf_files_group() {
51
+ group_guid="$(stat -c %g /host/etc/pve 2>/dev/null || true)"
52
+ [ -z "${group_guid}" ] && return
53
+
54
+ if ! getent group "${group_guid}" >/dev/null; then
55
+ echo "Creating proxmox-etc-pve group with GID ${group_guid}"
56
+ if ! addgroup -g "${group_guid}" "proxmox-etc-pve"; then
57
+ echo >&2 "Failed to add group proxmox-etc-pve with GID ${group_guid}."
58
+ return
59
+ fi
60
+ fi
61
+
62
+ if ! getent group "${group_guid}" | grep -q netdata; then
63
+ echo "Assign netdata user to group ${group_guid}"
64
+ if ! usermod -a -G "${group_guid}" "${DOCKER_USR}"; then
65
+ echo >&2 "Failed to add netdata user to group with GID ${group_guid}."
66
+ return
67
+ fi
68
+ fi
69
+}
70
+
71
+if [ -d "/host/etc/pve" ]; then
72
+ add_netdata_to_proxmox_conf_files_group || true
73
+fi
74
+
75
+
76
if mountpoint -q /etc/netdata; then
77
echo "Copying stock configuration to /etc/netdata"
78
cp -an /etc/netdata.stock/* /etc/netdata