Check the version of the default cgroup mountpoint (#11102)
Vladimir Kobal committed
May 6, 2021 at 17:02 UTC
b1ce4fa3b6b8c423716b4ee6cbb56d12a438d737
3 files changed
+20
-2
collectors/cgroups.plugin/sys_fs_cgroup.c
+15
-2
@@ -160,7 +160,20 @@ static enum cgroups_type cgroups_try_detect_version()
160
if(!cgroups2_available)
161
return CGROUPS_V1;
162
163
- // 2. check systemd compiletime setting
163
+#if defined CGROUP2_SUPER_MAGIC
164
+ // 2. check filesystem type for the default mountpoint
165
+ char filename[FILENAME_MAX + 1];
166
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/fs/cgroup");
167
+ struct statfs fsinfo;
168
+ if (!statfs(filename, &fsinfo)) {
169
+ if (fsinfo.f_type == CGROUP2_SUPER_MAGIC)
170
+ return CGROUPS_V2;
171
+ if (fsinfo.f_type == CGROUP_SUPER_MAGIC)
172
+ return CGROUPS_V1;
173
+ }
174
+#endif
175
+
176
+ // 3. check systemd compiletime setting
177
if ((systemd_setting = cgroups_detect_systemd("systemd --version")) == SYSTEMD_CGROUP_ERR)
178
systemd_setting = cgroups_detect_systemd(SYSTEMD_CMD_RHEL);
179
@@ -174,7 +187,7 @@ static enum cgroups_type cgroups_try_detect_version()
187
return CGROUPS_V1;
188
}
189
177
- // 3. if we are unified as on Fedora (default cgroups2 only mode)
190
+ // 4. if we are unified as on Fedora (default cgroups2 only mode)
191
// check kernel command line flag that can override that setting
192
f = fopen("/proc/cmdline", "r");
193
if (!f) {
configure.ac
+1
@@ -249,6 +249,7 @@ AC_HEADER_RESOLV
249
AC_CHECK_HEADERS_ONCE([sys/prctl.h])
250
AC_CHECK_HEADERS_ONCE([sys/vfs.h])
251
AC_CHECK_HEADERS_ONCE([sys/statfs.h])
252
+AC_CHECK_HEADERS_ONCE([linux/magic.h])
253
AC_CHECK_HEADERS_ONCE([sys/statvfs.h])
254
AC_CHECK_HEADERS_ONCE([sys/mount.h])
255
libnetdata/libnetdata.h
+4
@@ -118,6 +118,10 @@ extern "C" {
118
#include <sys/statfs.h>
119
#endif
120
121
+#ifdef HAVE_LINUX_MAGIC_H
122
+#include <linux/magic.h>
123
+#endif
124
+
125
#ifdef HAVE_SYS_MOUNT_H
126
#include <sys/mount.h>
127
#endif