]> arthur.barton.de Git - netdata.git/blobdiff - src/sys_fs_cgroup.c
Merge pull request #1840 from ktsaou/master
[netdata.git] / src / sys_fs_cgroup.c
index f4b3db2d235260cc2d02b6076fcf59ea459b8e6a..8b92646b7442e54708c56c3c32f5a05c8769c361 100644 (file)
@@ -49,7 +49,7 @@ static SIMPLE_PATTERN *enabled_cgroup_paths = NULL;
 static SIMPLE_PATTERN *enabled_cgroup_renames = NULL;
 static SIMPLE_PATTERN *systemd_services_cgroups = NULL;
 
-static char *cgroups_rename_script = PLUGINS_DIR "/cgroup-name.sh";
+static char *cgroups_rename_script = NULL;
 
 static uint32_t Read_hash = 0;
 static uint32_t Write_hash = 0;
@@ -105,7 +105,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/cpuacct";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
 
     mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio");
@@ -115,7 +115,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/blkio";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
 
     mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory");
@@ -125,7 +125,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/memory";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
 
     mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "devices");
@@ -135,7 +135,7 @@ void read_cgroup_plugin_configuration() {
         s = "/sys/fs/cgroup/devices";
     }
     else s = mi->mount_point;
-    snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
+    snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
     cgroup_devices_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/devices", filename);
 
     cgroup_root_max = (int)config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
@@ -145,6 +145,7 @@ void read_cgroup_plugin_configuration() {
 
     enabled_cgroup_patterns = simple_pattern_create(
             config_get("plugin:cgroups", "enable by default cgroups matching",
+                    " /system.slice/docker-*.scope "
                     " !*.mount "
                     " !*.partition "
                     " !*.scope "
@@ -176,10 +177,13 @@ void read_cgroup_plugin_configuration() {
                     " * "
             ), SIMPLE_PATTERN_EXACT);
 
-    cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", cgroups_rename_script);
+    snprintfz(filename, FILENAME_MAX, "%s/cgroup-name.sh", netdata_configured_plugins_dir);
+    cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", filename);
 
     enabled_cgroup_renames = simple_pattern_create(
             config_get("plugin:cgroups", "run script to rename cgroups matching",
+                    " *docker* "
+                    " *lxc* "
                     " !/ "
                     " !*.mount "
                     " !*.partition "
@@ -594,7 +598,7 @@ static inline void cgroup_read_memory(struct memory *mem) {
         }
 
         if(unlikely(!mem->arl_base)) {
-            mem->arl_base = arl_create(NULL, 60);
+            mem->arl_base = arl_create("cgroup/memory", NULL, 60);
 
             arl_expect(mem->arl_base, "cache", &mem->cache);
             arl_expect(mem->arl_base, "rss", &mem->rss);
@@ -2079,24 +2083,20 @@ void *cgroups_main(void *ptr) {
 
     RRDSET *stcpu_thread = NULL;
 
+    heartbeat_t hb;
+    heartbeat_init(&hb);
     usec_t step = cgroup_update_every * USEC_PER_SEC;
-    usec_t find_every = cgroup_check_for_new_every * USEC_PER_SEC, find_next = 0;
+    usec_t find_every = cgroup_check_for_new_every * USEC_PER_SEC, find_dt = 0;
     for(;;) {
-        usec_t now = now_monotonic_usec();
-        usec_t next = now - (now % step) + step;
-
-        while(now < next) {
-            sleep_usec(next - now);
-            now = now_monotonic_usec();
-        }
-
+        usec_t hb_dt = heartbeat_next(&hb, step);
         if(unlikely(netdata_exit)) break;
 
         // BEGIN -- the job to be done
 
-        if(unlikely(now >= find_next)) {
+        find_dt += hb_dt;
+        if(unlikely(find_dt >= find_every)) {
             find_all_cgroups();
-            find_next = now + find_every;
+            find_dt = 0;
         }
 
         read_all_cgroups(cgroup_root);