3 // ----------------------------------------------------------------------------
6 static int cgroup_enable_cpuacct_stat = CONFIG_ONDEMAND_ONDEMAND;
7 static int cgroup_enable_cpuacct_usage = CONFIG_ONDEMAND_ONDEMAND;
8 static int cgroup_enable_memory = CONFIG_ONDEMAND_ONDEMAND;
9 static int cgroup_enable_devices = CONFIG_ONDEMAND_ONDEMAND;
10 static int cgroup_enable_blkio = CONFIG_ONDEMAND_ONDEMAND;
11 static int cgroup_enable_systemd_services = CONFIG_ONDEMAND_YES;
12 static int cgroup_enable_new_cgroups_detected_at_runtime = 1;
13 static int cgroup_check_for_new_every = 10;
14 static int cgroup_update_every = 1;
16 static char *cgroup_cpuacct_base = NULL;
17 static char *cgroup_blkio_base = NULL;
18 static char *cgroup_memory_base = NULL;
19 static char *cgroup_devices_base = NULL;
21 static int cgroup_root_count = 0;
22 static int cgroup_root_max = 500;
23 static int cgroup_max_depth = 0;
25 static SIMPLE_PATTERN *disabled_cgroups_patterns = NULL;
26 static SIMPLE_PATTERN *disabled_cgroup_paths = NULL;
27 static SIMPLE_PATTERN *disabled_cgroup_renames = NULL;
28 static SIMPLE_PATTERN *systemd_services_cgroups = NULL;
30 static char *cgroups_rename_script = PLUGINS_DIR "/cgroup-name.sh";
32 void read_cgroup_plugin_configuration() {
33 cgroup_update_every = (int)config_get_number("plugin:cgroups", "update every", rrd_update_every);
34 if(cgroup_update_every < rrd_update_every)
35 cgroup_update_every = rrd_update_every;
37 cgroup_check_for_new_every = (int)config_get_number("plugin:cgroups", "check for new cgroups every", cgroup_check_for_new_every * cgroup_update_every);
38 if(cgroup_check_for_new_every < cgroup_update_every)
39 cgroup_check_for_new_every = cgroup_update_every;
41 cgroup_enable_cpuacct_stat = config_get_boolean_ondemand("plugin:cgroups", "enable cpuacct stat", cgroup_enable_cpuacct_stat);
42 cgroup_enable_cpuacct_usage = config_get_boolean_ondemand("plugin:cgroups", "enable cpuacct usage", cgroup_enable_cpuacct_usage);
43 cgroup_enable_memory = config_get_boolean_ondemand("plugin:cgroups", "enable memory", cgroup_enable_memory);
44 cgroup_enable_blkio = config_get_boolean_ondemand("plugin:cgroups", "enable blkio", cgroup_enable_blkio);
46 cgroup_enable_systemd_services = config_get_boolean_ondemand("plugin:cgroups", "enable systemd services", cgroup_enable_systemd_services);
48 char filename[FILENAME_MAX + 1], *s;
49 struct mountinfo *mi, *root = mountinfo_read(0);
51 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuacct");
52 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "cpuacct");
54 error("Cannot find cgroup cpuacct mountinfo. Assuming default: /sys/fs/cgroup/cpuacct");
55 s = "/sys/fs/cgroup/cpuacct";
57 else s = mi->mount_point;
58 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
59 cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
61 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio");
62 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "blkio");
64 error("Cannot find cgroup blkio mountinfo. Assuming default: /sys/fs/cgroup/blkio");
65 s = "/sys/fs/cgroup/blkio";
67 else s = mi->mount_point;
68 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
69 cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
71 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory");
72 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "memory");
74 error("Cannot find cgroup memory mountinfo. Assuming default: /sys/fs/cgroup/memory");
75 s = "/sys/fs/cgroup/memory";
77 else s = mi->mount_point;
78 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
79 cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
81 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "devices");
82 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "devices");
84 error("Cannot find cgroup devices mountinfo. Assuming default: /sys/fs/cgroup/devices");
85 s = "/sys/fs/cgroup/devices";
87 else s = mi->mount_point;
88 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
89 cgroup_devices_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/devices", filename);
91 cgroup_root_max = (int)config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
92 cgroup_max_depth = (int)config_get_number("plugin:cgroups", "max cgroups depth to monitor", cgroup_max_depth);
94 cgroup_enable_new_cgroups_detected_at_runtime = config_get_boolean("plugin:cgroups", "enable new cgroups detected at run time", cgroup_enable_new_cgroups_detected_at_runtime);
96 disabled_cgroups_patterns = simple_pattern_create(
97 config_get("plugin:cgroups", "disable by default cgroups matching", " *.mount "
108 " /lxc/*/ns " // #1397
117 ), SIMPLE_PATTERN_EXACT);
119 disabled_cgroup_paths = simple_pattern_create(
120 config_get("plugin:cgroups", "do not search for cgroups in paths matching"
127 ), SIMPLE_PATTERN_EXACT);
129 cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", cgroups_rename_script);
131 disabled_cgroup_renames = simple_pattern_create(
132 config_get("plugin:cgroups", "do not run script to rename cgroups matching", " / "
140 ), SIMPLE_PATTERN_EXACT);
142 if(cgroup_enable_systemd_services)
143 systemd_services_cgroups = simple_pattern_create(
144 config_get("plugin:cgroups", "cgroups to match as systemd services"
145 , " !/system.slice/*/*.service /system.slice/*.service "
146 ), SIMPLE_PATTERN_EXACT);
148 mountinfo_free(root);
151 // ----------------------------------------------------------------------------
159 unsigned long long Read;
160 unsigned long long Write;
162 unsigned long long Sync;
163 unsigned long long Async;
164 unsigned long long Total;
168 // https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
176 unsigned long long cache;
177 unsigned long long rss;
178 unsigned long long rss_huge;
179 unsigned long long mapped_file;
180 unsigned long long writeback;
181 unsigned long long dirty;
182 unsigned long long swap;
183 unsigned long long pgpgin;
184 unsigned long long pgpgout;
185 unsigned long long pgfault;
186 unsigned long long pgmajfault;
188 unsigned long long inactive_anon;
189 unsigned long long active_anon;
190 unsigned long long inactive_file;
191 unsigned long long active_file;
192 unsigned long long unevictable;
193 unsigned long long hierarchical_memory_limit;
194 unsigned long long total_cache;
195 unsigned long long total_rss;
196 unsigned long long total_rss_huge;
197 unsigned long long total_mapped_file;
198 unsigned long long total_writeback;
199 unsigned long long total_dirty;
200 unsigned long long total_swap;
201 unsigned long long total_pgpgin;
202 unsigned long long total_pgpgout;
203 unsigned long long total_pgfault;
204 unsigned long long total_pgmajfault;
205 unsigned long long total_inactive_anon;
206 unsigned long long total_active_anon;
207 unsigned long long total_inactive_file;
208 unsigned long long total_active_file;
209 unsigned long long total_unevictable;
212 int usage_in_bytes_updated;
213 char *filename_usage_in_bytes;
214 unsigned long long usage_in_bytes;
216 int msw_usage_in_bytes_updated;
217 char *filename_msw_usage_in_bytes;
218 unsigned long long msw_usage_in_bytes;
221 char *filename_failcnt;
222 unsigned long long failcnt;
225 // https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
226 struct cpuacct_stat {
231 unsigned long long user;
232 unsigned long long system;
235 // https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
236 struct cpuacct_usage {
242 unsigned long long *cpu_percpu;
245 #define CGROUP_OPTIONS_DISABLED_DUPLICATE 0x00000001
246 #define CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE 0x00000002
251 char available; // found in the filesystem
252 char enabled; // enabled in the config
262 struct cpuacct_stat cpuacct_stat;
263 struct cpuacct_usage cpuacct_usage;
265 struct memory memory;
267 struct blkio io_service_bytes; // bytes
268 struct blkio io_serviced; // operations
270 struct blkio throttle_io_service_bytes; // bytes
271 struct blkio throttle_io_serviced; // operations
273 struct blkio io_merged; // operations
274 struct blkio io_queued; // operations
278 RRDSET *st_cpu_per_core;
280 RRDSET *st_writeback;
281 RRDSET *st_mem_activity;
283 RRDSET *st_mem_usage;
284 RRDSET *st_mem_failcnt;
286 RRDSET *st_serviced_ops;
287 RRDSET *st_throttle_io;
288 RRDSET *st_throttle_serviced_ops;
289 RRDSET *st_queued_ops;
290 RRDSET *st_merged_ops;
294 RRDDIM *rd_mem_usage;
298 } *cgroup_root = NULL;
300 // ----------------------------------------------------------------------------
301 // read values from /sys
303 void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) {
304 static procfile *ff = NULL;
306 static uint32_t user_hash = 0;
307 static uint32_t system_hash = 0;
309 if(unlikely(user_hash == 0)) {
310 user_hash = simple_hash("user");
311 system_hash = simple_hash("system");
316 ff = procfile_reopen(ff, cp->filename, NULL, PROCFILE_FLAG_DEFAULT);
319 ff = procfile_readall(ff);
322 unsigned long i, lines = procfile_lines(ff);
325 error("File '%s' should have 1+ lines.", cp->filename);
329 for(i = 0; i < lines ; i++) {
330 char *s = procfile_lineword(ff, i, 0);
331 uint32_t hash = simple_hash(s);
333 if(hash == user_hash && !strcmp(s, "user"))
334 cp->user = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
336 else if(hash == system_hash && !strcmp(s, "system"))
337 cp->system = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
342 // fprintf(stderr, "READ '%s': user: %llu, system: %llu\n", cp->filename, cp->user, cp->system);
346 void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
347 static procfile *ff = NULL;
351 ff = procfile_reopen(ff, ca->filename, NULL, PROCFILE_FLAG_DEFAULT);
354 ff = procfile_readall(ff);
357 if(procfile_lines(ff) < 1) {
358 error("File '%s' should have 1+ lines but has %u.", ca->filename, procfile_lines(ff));
362 unsigned long i = procfile_linewords(ff, 0);
365 // we may have 1 more CPU reported
367 char *s = procfile_lineword(ff, 0, i - 1);
373 freez(ca->cpu_percpu);
374 ca->cpu_percpu = mallocz(sizeof(unsigned long long) * i);
375 ca->cpus = (unsigned int)i;
378 for(i = 0; i < ca->cpus ;i++) {
379 ca->cpu_percpu[i] = strtoull(procfile_lineword(ff, 0, i), NULL, 10);
380 // fprintf(stderr, "READ '%s': cpu%d/%d: %llu ('%s')\n", ca->filename, i, ca->cpus, ca->cpu_percpu[i], procfile_lineword(ff, 0, i));
387 void cgroup_read_blkio(struct blkio *io) {
388 static procfile *ff = NULL;
390 static uint32_t Read_hash = 0;
391 static uint32_t Write_hash = 0;
393 static uint32_t Sync_hash = 0;
394 static uint32_t Async_hash = 0;
395 static uint32_t Total_hash = 0;
398 if(unlikely(Read_hash == 0)) {
399 Read_hash = simple_hash("Read");
400 Write_hash = simple_hash("Write");
402 Sync_hash = simple_hash("Sync");
403 Async_hash = simple_hash("Async");
404 Total_hash = simple_hash("Total");
410 ff = procfile_reopen(ff, io->filename, NULL, PROCFILE_FLAG_DEFAULT);
413 ff = procfile_readall(ff);
416 unsigned long i, lines = procfile_lines(ff);
419 error("File '%s' should have 1+ lines.", io->filename);
431 for(i = 0; i < lines ; i++) {
432 char *s = procfile_lineword(ff, i, 1);
433 uint32_t hash = simple_hash(s);
435 if(hash == Read_hash && !strcmp(s, "Read"))
436 io->Read += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
438 else if(hash == Write_hash && !strcmp(s, "Write"))
439 io->Write += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
442 else if(hash == Sync_hash && !strcmp(s, "Sync"))
443 io->Sync += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
445 else if(hash == Async_hash && !strcmp(s, "Async"))
446 io->Async += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
448 else if(hash == Total_hash && !strcmp(s, "Total"))
449 io->Total += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
454 // fprintf(stderr, "READ '%s': Read: %llu, Write: %llu, Sync: %llu, Async: %llu, Total: %llu\n", io->filename, io->Read, io->Write, io->Sync, io->Async, io->Total);
458 void cgroup_read_memory(struct memory *mem) {
459 static procfile *ff = NULL;
461 static uint32_t cache_hash = 0;
462 static uint32_t rss_hash = 0;
463 static uint32_t rss_huge_hash = 0;
464 static uint32_t mapped_file_hash = 0;
465 static uint32_t writeback_hash = 0;
466 static uint32_t dirty_hash = 0;
467 static uint32_t swap_hash = 0;
468 static uint32_t pgpgin_hash = 0;
469 static uint32_t pgpgout_hash = 0;
470 static uint32_t pgfault_hash = 0;
471 static uint32_t pgmajfault_hash = 0;
473 static uint32_t inactive_anon_hash = 0;
474 static uint32_t active_anon_hash = 0;
475 static uint32_t inactive_file_hash = 0;
476 static uint32_t active_file_hash = 0;
477 static uint32_t unevictable_hash = 0;
478 static uint32_t hierarchical_memory_limit_hash = 0;
479 static uint32_t total_cache_hash = 0;
480 static uint32_t total_rss_hash = 0;
481 static uint32_t total_rss_huge_hash = 0;
482 static uint32_t total_mapped_file_hash = 0;
483 static uint32_t total_writeback_hash = 0;
484 static uint32_t total_dirty_hash = 0;
485 static uint32_t total_swap_hash = 0;
486 static uint32_t total_pgpgin_hash = 0;
487 static uint32_t total_pgpgout_hash = 0;
488 static uint32_t total_pgfault_hash = 0;
489 static uint32_t total_pgmajfault_hash = 0;
490 static uint32_t total_inactive_anon_hash = 0;
491 static uint32_t total_active_anon_hash = 0;
492 static uint32_t total_inactive_file_hash = 0;
493 static uint32_t total_active_file_hash = 0;
494 static uint32_t total_unevictable_hash = 0;
496 if(unlikely(cache_hash == 0)) {
497 cache_hash = simple_hash("cache");
498 rss_hash = simple_hash("rss");
499 rss_huge_hash = simple_hash("rss_huge");
500 mapped_file_hash = simple_hash("mapped_file");
501 writeback_hash = simple_hash("writeback");
502 dirty_hash = simple_hash("dirty");
503 swap_hash = simple_hash("swap");
504 pgpgin_hash = simple_hash("pgpgin");
505 pgpgout_hash = simple_hash("pgpgout");
506 pgfault_hash = simple_hash("pgfault");
507 pgmajfault_hash = simple_hash("pgmajfault");
509 inactive_anon_hash = simple_hash("inactive_anon");
510 active_anon_hash = simple_hash("active_anon");
511 inactive_file_hash = simple_hash("inactive_file");
512 active_file_hash = simple_hash("active_file");
513 unevictable_hash = simple_hash("unevictable");
514 hierarchical_memory_limit_hash = simple_hash("hierarchical_memory_limit");
515 total_cache_hash = simple_hash("total_cache");
516 total_rss_hash = simple_hash("total_rss");
517 total_rss_huge_hash = simple_hash("total_rss_huge");
518 total_mapped_file_hash = simple_hash("total_mapped_file");
519 total_writeback_hash = simple_hash("total_writeback");
520 total_dirty_hash = simple_hash("total_dirty");
521 total_swap_hash = simple_hash("total_swap");
522 total_pgpgin_hash = simple_hash("total_pgpgin");
523 total_pgpgout_hash = simple_hash("total_pgpgout");
524 total_pgfault_hash = simple_hash("total_pgfault");
525 total_pgmajfault_hash = simple_hash("total_pgmajfault");
526 total_inactive_anon_hash = simple_hash("total_inactive_anon");
527 total_active_anon_hash = simple_hash("total_active_anon");
528 total_inactive_file_hash = simple_hash("total_inactive_file");
529 total_active_file_hash = simple_hash("total_active_file");
530 total_unevictable_hash = simple_hash("total_unevictable");
536 ff = procfile_reopen(ff, mem->filename, NULL, PROCFILE_FLAG_DEFAULT);
539 ff = procfile_readall(ff);
542 unsigned long i, lines = procfile_lines(ff);
545 error("File '%s' should have 1+ lines.", mem->filename);
549 for(i = 0; i < lines ; i++) {
550 char *s = procfile_lineword(ff, i, 0);
551 uint32_t hash = simple_hash(s);
553 if(hash == cache_hash && !strcmp(s, "cache"))
554 mem->cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
556 else if(hash == rss_hash && !strcmp(s, "rss"))
557 mem->rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
559 else if(hash == rss_huge_hash && !strcmp(s, "rss_huge"))
560 mem->rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
562 else if(hash == mapped_file_hash && !strcmp(s, "mapped_file"))
563 mem->mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
565 else if(hash == writeback_hash && !strcmp(s, "writeback"))
566 mem->writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
568 else if(hash == dirty_hash && !strcmp(s, "dirty")) {
569 mem->dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
570 mem->has_dirty_swap = 1;
573 else if(hash == swap_hash && !strcmp(s, "swap")) {
574 mem->swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
575 mem->has_dirty_swap = 1;
578 else if(hash == pgpgin_hash && !strcmp(s, "pgpgin"))
579 mem->pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
581 else if(hash == pgpgout_hash && !strcmp(s, "pgpgout"))
582 mem->pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
584 else if(hash == pgfault_hash && !strcmp(s, "pgfault"))
585 mem->pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
587 else if(hash == pgmajfault_hash && !strcmp(s, "pgmajfault"))
588 mem->pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
591 else if(hash == inactive_anon_hash && !strcmp(s, "inactive_anon"))
592 mem->inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
594 else if(hash == active_anon_hash && !strcmp(s, "active_anon"))
595 mem->active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
597 else if(hash == inactive_file_hash && !strcmp(s, "inactive_file"))
598 mem->inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
600 else if(hash == active_file_hash && !strcmp(s, "active_file"))
601 mem->active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
603 else if(hash == unevictable_hash && !strcmp(s, "unevictable"))
604 mem->unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
606 else if(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit"))
607 mem->hierarchical_memory_limit = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
609 else if(hash == total_cache_hash && !strcmp(s, "total_cache"))
610 mem->total_cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
612 else if(hash == total_rss_hash && !strcmp(s, "total_rss"))
613 mem->total_rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
615 else if(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge"))
616 mem->total_rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
618 else if(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file"))
619 mem->total_mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
621 else if(hash == total_writeback_hash && !strcmp(s, "total_writeback"))
622 mem->total_writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
624 else if(hash == total_dirty_hash && !strcmp(s, "total_dirty"))
625 mem->total_dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
627 else if(hash == total_swap_hash && !strcmp(s, "total_swap"))
628 mem->total_swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
630 else if(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin"))
631 mem->total_pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
633 else if(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout"))
634 mem->total_pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
636 else if(hash == total_pgfault_hash && !strcmp(s, "total_pgfault"))
637 mem->total_pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
639 else if(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault"))
640 mem->total_pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
642 else if(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon"))
643 mem->total_inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
645 else if(hash == total_active_anon_hash && !strcmp(s, "total_active_anon"))
646 mem->total_active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
648 else if(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file"))
649 mem->total_inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
651 else if(hash == total_active_file_hash && !strcmp(s, "total_active_file"))
652 mem->total_active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
654 else if(hash == total_unevictable_hash && !strcmp(s, "total_unevictable"))
655 mem->total_unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
659 // fprintf(stderr, "READ: '%s', cache: %llu, rss: %llu, rss_huge: %llu, mapped_file: %llu, writeback: %llu, dirty: %llu, swap: %llu, pgpgin: %llu, pgpgout: %llu, pgfault: %llu, pgmajfault: %llu, inactive_anon: %llu, active_anon: %llu, inactive_file: %llu, active_file: %llu, unevictable: %llu, hierarchical_memory_limit: %llu, total_cache: %llu, total_rss: %llu, total_rss_huge: %llu, total_mapped_file: %llu, total_writeback: %llu, total_dirty: %llu, total_swap: %llu, total_pgpgin: %llu, total_pgpgout: %llu, total_pgfault: %llu, total_pgmajfault: %llu, total_inactive_anon: %llu, total_active_anon: %llu, total_inactive_file: %llu, total_active_file: %llu, total_unevictable: %llu\n", mem->filename, mem->cache, mem->rss, mem->rss_huge, mem->mapped_file, mem->writeback, mem->dirty, mem->swap, mem->pgpgin, mem->pgpgout, mem->pgfault, mem->pgmajfault, mem->inactive_anon, mem->active_anon, mem->inactive_file, mem->active_file, mem->unevictable, mem->hierarchical_memory_limit, mem->total_cache, mem->total_rss, mem->total_rss_huge, mem->total_mapped_file, mem->total_writeback, mem->total_dirty, mem->total_swap, mem->total_pgpgin, mem->total_pgpgout, mem->total_pgfault, mem->total_pgmajfault, mem->total_inactive_anon, mem->total_active_anon, mem->total_inactive_file, mem->total_active_file, mem->total_unevictable);
664 mem->usage_in_bytes_updated = 0;
665 if(mem->filename_usage_in_bytes) {
666 if(likely(!read_single_number_file(mem->filename_usage_in_bytes, &mem->usage_in_bytes)))
667 mem->usage_in_bytes_updated = 1;
670 mem->msw_usage_in_bytes_updated = 0;
671 if(mem->filename_msw_usage_in_bytes) {
672 if(likely(!read_single_number_file(mem->filename_msw_usage_in_bytes, &mem->msw_usage_in_bytes)))
673 mem->msw_usage_in_bytes_updated = 1;
676 mem->failcnt_updated = 0;
677 if(mem->filename_failcnt) {
678 if(likely(!read_single_number_file(mem->filename_failcnt, &mem->failcnt)))
679 mem->failcnt_updated = 1;
683 void cgroup_read(struct cgroup *cg) {
684 debug(D_CGROUP, "reading metrics for cgroups '%s'", cg->id);
686 cgroup_read_cpuacct_stat(&cg->cpuacct_stat);
687 cgroup_read_cpuacct_usage(&cg->cpuacct_usage);
688 cgroup_read_memory(&cg->memory);
689 cgroup_read_blkio(&cg->io_service_bytes);
690 cgroup_read_blkio(&cg->io_serviced);
691 cgroup_read_blkio(&cg->throttle_io_service_bytes);
692 cgroup_read_blkio(&cg->throttle_io_serviced);
693 cgroup_read_blkio(&cg->io_merged);
694 cgroup_read_blkio(&cg->io_queued);
697 void read_all_cgroups(struct cgroup *root) {
698 debug(D_CGROUP, "reading metrics for all cgroups");
702 for(cg = root; cg ; cg = cg->next)
703 if(cg->enabled && cg->available)
707 // ----------------------------------------------------------------------------
708 // add/remove/find cgroup objects
710 #define CGROUP_CHARTID_LINE_MAX 1024
712 static char *cgroup_title_strdupz(const char *s) {
713 if(!s || !*s) s = "/";
715 if(*s == '/' && s[1] != '\0') s++;
717 char *r = strdupz(s);
718 netdata_fix_chart_name(r);
723 static char *cgroup_chart_id_strdupz(const char *s) {
724 if(!s || !*s) s = "/";
726 if(*s == '/' && s[1] != '\0') s++;
728 char *r = strdupz(s);
729 netdata_fix_chart_id(r);
734 void cgroup_get_chart_name(struct cgroup *cg) {
735 debug(D_CGROUP, "looking for the name of cgroup '%s' with chart id '%s' and title '%s'", cg->id, cg->chart_id, cg->chart_title);
738 char buffer[CGROUP_CHARTID_LINE_MAX + 1];
740 snprintfz(buffer, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'", cgroups_rename_script, cg->chart_id);
742 debug(D_CGROUP, "executing command '%s' for cgroup '%s'", buffer, cg->id);
743 FILE *fp = mypopen(buffer, &cgroup_pid);
745 // debug(D_CGROUP, "reading from command '%s' for cgroup '%s'", buffer, cg->id);
746 char *s = fgets(buffer, CGROUP_CHARTID_LINE_MAX, fp);
747 // debug(D_CGROUP, "closing command for cgroup '%s'", cg->id);
748 mypclose(fp, cgroup_pid);
749 // debug(D_CGROUP, "closed command for cgroup '%s'", cg->id);
751 if(s && *s && *s != '\n') {
752 debug(D_CGROUP, "cgroup '%s' should be renamed to '%s'", cg->id, s);
756 freez(cg->chart_title);
757 cg->chart_title = cgroup_title_strdupz(s);
760 cg->chart_id = cgroup_chart_id_strdupz(s);
761 cg->hash_chart = simple_hash(cg->chart_id);
765 error("CGROUP: Cannot popen(\"%s\", \"r\").", buffer);
768 struct cgroup *cgroup_add(const char *id) {
769 if(!id || !*id) id = "/";
770 debug(D_CGROUP, "adding to list, cgroup with id '%s'", id);
772 if(cgroup_root_count >= cgroup_root_max) {
773 info("Maximum number of cgroups reached (%d). Not adding cgroup '%s'", cgroup_root_count, id);
777 int def = simple_pattern_matches(disabled_cgroups_patterns, id)?0:cgroup_enable_new_cgroups_detected_at_runtime;
778 struct cgroup *cg = callocz(1, sizeof(struct cgroup));
780 cg->id = strdupz(id);
781 cg->hash = simple_hash(cg->id);
783 cg->chart_title = cgroup_title_strdupz(id);
785 cg->chart_id = cgroup_chart_id_strdupz(id);
786 cg->hash_chart = simple_hash(cg->chart_id);
793 for(e = cgroup_root; e->next ;e = e->next) ;
799 // fix the chart_id and title by calling the external script
800 if(!simple_pattern_matches(disabled_cgroup_renames, cg->id) &&
801 !simple_pattern_matches(disabled_cgroup_renames, cg->chart_id)) {
803 cgroup_get_chart_name(cg);
805 debug(D_CGROUP, "cgroup '%s' renamed to '%s' (title: '%s')", cg->id, cg->chart_id, cg->chart_title);
808 debug(D_CGROUP, "cgroup '%s' will not be renamed - it matches the list of disabled cgroup renames (will be shown as '%s')", cg->id, cg->chart_id);
810 int user_configurable = 1;
812 // check if this cgroup should be a systemd service
813 if(cgroup_enable_systemd_services) {
814 if(simple_pattern_matches(systemd_services_cgroups, cg->id) ||
815 simple_pattern_matches(systemd_services_cgroups, cg->chart_id)) {
816 debug(D_CGROUP, "cgroup '%s' with chart id '%s' (title: '%s') matches systemd services cgroups", cg->id, cg->chart_id, cg->chart_title);
818 char buffer[CGROUP_CHARTID_LINE_MAX + 1];
819 cg->options |= CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE;
821 strncpy(buffer, cg->id, CGROUP_CHARTID_LINE_MAX);
824 //freez(cg->chart_id);
825 //cg->chart_id = cgroup_chart_id_strdupz(s);
826 //cg->hash_chart = simple_hash(cg->chart_id);
828 // skip to the last slash
829 size_t len = strlen(s);
830 while(len--) if(unlikely(s[len] == '/')) break;
831 if(len) s = &s[len + 1];
835 while(len--) if(unlikely(s[len] == '.')) break;
836 if(len) s[len] = '\0';
838 freez(cg->chart_title);
839 cg->chart_title = cgroup_title_strdupz(s);
842 user_configurable = 0;
844 debug(D_CGROUP, "cgroup '%s' renamed to '%s' (title: '%s')", cg->id, cg->chart_id, cg->chart_title);
847 debug(D_CGROUP, "cgroup '%s' with chart id '%s' (title: '%s') does not match systemd services groups", cg->id, cg->chart_id, cg->chart_title);
850 if(user_configurable) {
851 // allow the user to enable/disable this individualy
852 char option[FILENAME_MAX + 1];
853 snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
854 cg->enabled = (char) config_get_boolean("plugin:cgroups", option, def);
857 // detect duplicate cgroups
860 for (t = cgroup_root; t; t = t->next) {
861 if (t != cg && t->enabled && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id)) {
862 if (!strncmp(t->chart_id, "/system.slice/", 14) && !strncmp(cg->chart_id, "/init.scope/system.slice/", 25)) {
863 error("Control group with chart id '%s' already exists with id '%s' and is enabled. Swapping them by enabling cgroup with id '%s' and disabling cgroup with id '%s'.",
864 cg->chart_id, t->id, cg->id, t->id);
865 debug(D_CGROUP, "Control group with chart id '%s' already exists with id '%s' and is enabled. Swapping them by enabling cgroup with id '%s' and disabling cgroup with id '%s'.",
866 cg->chart_id, t->id, cg->id, t->id);
868 t->options |= CGROUP_OPTIONS_DISABLED_DUPLICATE;
871 error("Control group with chart id '%s' already exists with id '%s' and is enabled and available. Disabling cgroup with id '%s'.",
872 cg->chart_id, t->id, cg->id);
873 debug(D_CGROUP, "Control group with chart id '%s' already exists with id '%s' and is enabled and available. Disabling cgroup with id '%s'.",
874 cg->chart_id, t->id, cg->id);
876 cg->options |= CGROUP_OPTIONS_DISABLED_DUPLICATE;
884 debug(D_CGROUP, "ADDED CGROUP: '%s' with chart id '%s' and title '%s' as %s (default was %s)", cg->id, cg->chart_id, cg->chart_title, (cg->enabled)?"enabled":"disabled", (def)?"enabled":"disabled");
889 void cgroup_free(struct cgroup *cg) {
890 debug(D_CGROUP, "Removing cgroup '%s' with chart id '%s' (was %s and %s)", cg->id, cg->chart_id, (cg->enabled)?"enabled":"disabled", (cg->available)?"available":"not available");
892 freez(cg->cpuacct_usage.cpu_percpu);
894 freez(cg->cpuacct_stat.filename);
895 freez(cg->cpuacct_usage.filename);
897 freez(cg->memory.filename);
898 freez(cg->memory.filename_failcnt);
899 freez(cg->memory.filename_usage_in_bytes);
900 freez(cg->memory.filename_msw_usage_in_bytes);
902 freez(cg->io_service_bytes.filename);
903 freez(cg->io_serviced.filename);
905 freez(cg->throttle_io_service_bytes.filename);
906 freez(cg->throttle_io_serviced.filename);
908 freez(cg->io_merged.filename);
909 freez(cg->io_queued.filename);
913 freez(cg->chart_title);
920 // find if a given cgroup exists
921 struct cgroup *cgroup_find(const char *id) {
922 debug(D_CGROUP, "searching for cgroup '%s'", id);
924 uint32_t hash = simple_hash(id);
927 for(cg = cgroup_root; cg ; cg = cg->next) {
928 if(hash == cg->hash && strcmp(id, cg->id) == 0)
932 debug(D_CGROUP, "cgroup '%s' %s in memory", id, (cg)?"found":"not found");
936 // ----------------------------------------------------------------------------
937 // detect running cgroups
939 // callback for find_file_in_subdirs()
940 void found_subdir_in_dir(const char *dir) {
941 debug(D_CGROUP, "examining cgroup dir '%s'", dir);
943 struct cgroup *cg = cgroup_find(dir);
945 if(*dir && cgroup_max_depth > 0) {
949 for(s = dir; *s ;s++)
950 if(unlikely(*s == '/'))
953 if(depth > cgroup_max_depth) {
954 info("cgroup '%s' is too deep (%d, while max is %d)", dir, depth, cgroup_max_depth);
958 // debug(D_CGROUP, "will add dir '%s' as cgroup", dir);
959 cg = cgroup_add(dir);
962 if(cg) cg->available = 1;
965 int find_dir_in_subdirs(const char *base, const char *this, void (*callback)(const char *)) {
966 if(!this) this = base;
967 debug(D_CGROUP, "searching for directories in '%s' (base '%s')", this?this:"", base);
969 size_t dirlen = strlen(this), baselen = strlen(base);
974 const char *relative_path = &this[baselen];
975 if(!*relative_path) relative_path = "/";
977 DIR *dir = opendir(this);
979 error("Cannot read cgroups directory '%s'", base);
984 callback(relative_path);
986 struct dirent *de = NULL;
987 while((de = readdir(dir))) {
988 if(de->d_type == DT_DIR
990 (de->d_name[0] == '.' && de->d_name[1] == '\0')
991 || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
995 if(de->d_type == DT_DIR) {
997 const char *r = relative_path;
998 if(*r == '\0') r = "/";
1000 // do not decent in directories we are not interested
1002 if(simple_pattern_matches(disabled_cgroup_paths, r))
1005 // we check for this option here
1006 // so that the config will not have settings
1007 // for leaf directories
1008 char option[FILENAME_MAX + 1];
1009 snprintfz(option, FILENAME_MAX, "search for cgroups under %s", r);
1010 option[FILENAME_MAX] = '\0';
1011 enabled = config_get_boolean("plugin:cgroups", option, def);
1015 char *s = mallocz(dirlen + strlen(de->d_name) + 2);
1018 strcat(s, de->d_name);
1019 int ret2 = find_dir_in_subdirs(base, s, callback);
1020 if(ret2 > 0) ret += ret2;
1030 void mark_all_cgroups_as_not_available() {
1031 debug(D_CGROUP, "marking all cgroups as not available");
1035 // mark all as not available
1036 for(cg = cgroup_root; cg ; cg = cg->next) {
1041 void cleanup_all_cgroups() {
1042 struct cgroup *cg = cgroup_root, *last = NULL;
1045 if(!cg->available) {
1046 // enable the first duplicate cgroup
1049 for(t = cgroup_root; t ; t = t->next) {
1050 if(t != cg && t->available && !t->enabled && t->options & CGROUP_OPTIONS_DISABLED_DUPLICATE && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id)) {
1051 debug(D_CGROUP, "Enabling duplicate of cgroup '%s' with id '%s', because the original with id '%s' stopped.", t->chart_id, t->id, cg->id);
1053 t->options &= ~CGROUP_OPTIONS_DISABLED_DUPLICATE;
1060 cgroup_root = cg->next;
1062 last->next = cg->next;
1078 void find_all_cgroups() {
1079 debug(D_CGROUP, "searching for cgroups");
1081 mark_all_cgroups_as_not_available();
1083 if(cgroup_enable_cpuacct_stat || cgroup_enable_cpuacct_usage) {
1084 if (find_dir_in_subdirs(cgroup_cpuacct_base, NULL, found_subdir_in_dir) == -1) {
1085 cgroup_enable_cpuacct_stat = cgroup_enable_cpuacct_usage = 0;
1086 error("disabled cgroup cpu statistics.");
1090 if(cgroup_enable_blkio) {
1091 if (find_dir_in_subdirs(cgroup_blkio_base, NULL, found_subdir_in_dir) == -1) {
1092 cgroup_enable_blkio = 0;
1093 error("disabled cgroup blkio statistics.");
1097 if(cgroup_enable_memory) {
1098 if(find_dir_in_subdirs(cgroup_memory_base, NULL, found_subdir_in_dir) == -1) {
1099 cgroup_enable_memory = 0;
1100 error("disabled cgroup memory statistics.");
1104 if(cgroup_enable_devices) {
1105 if(find_dir_in_subdirs(cgroup_devices_base, NULL, found_subdir_in_dir) == -1) {
1106 cgroup_enable_devices = 0;
1107 error("disabled cgroup devices statistics.");
1111 // remove any non-existing cgroups
1112 cleanup_all_cgroups();
1116 for(cg = cgroup_root; cg ; cg = cg->next) {
1117 // fprintf(stderr, " >>> CGROUP '%s' (%u - %s) with name '%s'\n", cg->id, cg->hash, cg->available?"available":"stopped", cg->name);
1119 if(unlikely(!cg->available))
1122 debug(D_CGROUP, "checking paths for cgroup '%s'", cg->id);
1124 // check for newly added cgroups
1125 // and update the filenames they read
1126 char filename[FILENAME_MAX + 1];
1127 if(unlikely(cgroup_enable_cpuacct_stat && !cg->cpuacct_stat.filename)) {
1128 snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.stat", cgroup_cpuacct_base, cg->id);
1129 if(stat(filename, &buf) != -1) {
1130 cg->cpuacct_stat.filename = strdupz(filename);
1131 debug(D_CGROUP, "cpuacct.stat filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_stat.filename);
1133 else debug(D_CGROUP, "cpuacct.stat file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1136 if(unlikely(cgroup_enable_cpuacct_usage && !cg->cpuacct_usage.filename)) {
1137 snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.usage_percpu", cgroup_cpuacct_base, cg->id);
1138 if(stat(filename, &buf) != -1) {
1139 cg->cpuacct_usage.filename = strdupz(filename);
1140 debug(D_CGROUP, "cpuacct.usage_percpu filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_usage.filename);
1142 else debug(D_CGROUP, "cpuacct.usage_percpu file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1145 if(unlikely(cgroup_enable_memory)) {
1146 if(unlikely(!cg->memory.filename)) {
1147 snprintfz(filename, FILENAME_MAX, "%s%s/memory.stat", cgroup_memory_base, cg->id);
1148 if(stat(filename, &buf) != -1) {
1149 cg->memory.filename = strdupz(filename);
1150 debug(D_CGROUP, "memory.stat filename for cgroup '%s': '%s'", cg->id, cg->memory.filename);
1153 debug(D_CGROUP, "memory.stat file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1155 if(unlikely(!cg->memory.filename_usage_in_bytes)) {
1156 snprintfz(filename, FILENAME_MAX, "%s%s/memory.usage_in_bytes", cgroup_memory_base, cg->id);
1157 if(stat(filename, &buf) != -1) {
1158 cg->memory.filename_usage_in_bytes = strdupz(filename);
1159 debug(D_CGROUP, "memory.usage_in_bytes filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_usage_in_bytes);
1162 debug(D_CGROUP, "memory.usage_in_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1164 if(unlikely(!cg->memory.filename_msw_usage_in_bytes)) {
1165 snprintfz(filename, FILENAME_MAX, "%s%s/memory.msw_usage_in_bytes", cgroup_memory_base, cg->id);
1166 if(stat(filename, &buf) != -1) {
1167 cg->memory.filename_msw_usage_in_bytes = strdupz(filename);
1168 debug(D_CGROUP, "memory.msw_usage_in_bytes filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_msw_usage_in_bytes);
1171 debug(D_CGROUP, "memory.msw_usage_in_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1173 if(unlikely(!cg->memory.filename_failcnt)) {
1174 snprintfz(filename, FILENAME_MAX, "%s%s/memory.failcnt", cgroup_memory_base, cg->id);
1175 if(stat(filename, &buf) != -1) {
1176 cg->memory.filename_failcnt = strdupz(filename);
1177 debug(D_CGROUP, "memory.failcnt filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_failcnt);
1180 debug(D_CGROUP, "memory.failcnt file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1184 if(unlikely(cgroup_enable_blkio)) {
1185 if(unlikely(!cg->io_service_bytes.filename)) {
1186 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_service_bytes", cgroup_blkio_base, cg->id);
1187 if(stat(filename, &buf) != -1) {
1188 cg->io_service_bytes.filename = strdupz(filename);
1189 debug(D_CGROUP, "io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->io_service_bytes.filename);
1191 else debug(D_CGROUP, "io_service_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1193 if(unlikely(!cg->io_serviced.filename)) {
1194 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_serviced", cgroup_blkio_base, cg->id);
1195 if(stat(filename, &buf) != -1) {
1196 cg->io_serviced.filename = strdupz(filename);
1197 debug(D_CGROUP, "io_serviced filename for cgroup '%s': '%s'", cg->id, cg->io_serviced.filename);
1199 else debug(D_CGROUP, "io_serviced file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1201 if(unlikely(!cg->throttle_io_service_bytes.filename)) {
1202 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_service_bytes", cgroup_blkio_base, cg->id);
1203 if(stat(filename, &buf) != -1) {
1204 cg->throttle_io_service_bytes.filename = strdupz(filename);
1205 debug(D_CGROUP, "throttle_io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_service_bytes.filename);
1207 else debug(D_CGROUP, "throttle_io_service_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1209 if(unlikely(!cg->throttle_io_serviced.filename)) {
1210 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_serviced", cgroup_blkio_base, cg->id);
1211 if(stat(filename, &buf) != -1) {
1212 cg->throttle_io_serviced.filename = strdupz(filename);
1213 debug(D_CGROUP, "throttle_io_serviced filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_serviced.filename);
1215 else debug(D_CGROUP, "throttle_io_serviced file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1217 if(unlikely(!cg->io_merged.filename)) {
1218 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_merged", cgroup_blkio_base, cg->id);
1219 if(stat(filename, &buf) != -1) {
1220 cg->io_merged.filename = strdupz(filename);
1221 debug(D_CGROUP, "io_merged filename for cgroup '%s': '%s'", cg->id, cg->io_merged.filename);
1223 else debug(D_CGROUP, "io_merged file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1225 if(unlikely(!cg->io_queued.filename)) {
1226 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_queued", cgroup_blkio_base, cg->id);
1227 if(stat(filename, &buf) != -1) {
1228 cg->io_queued.filename = strdupz(filename);
1229 debug(D_CGROUP, "io_queued filename for cgroup '%s': '%s'", cg->id, cg->io_queued.filename);
1231 else debug(D_CGROUP, "io_queued file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1236 debug(D_CGROUP, "done searching for cgroups");
1240 // ----------------------------------------------------------------------------
1243 #define CHART_TITLE_MAX 300
1245 void update_services_charts(int update_every, int do_cpu, int do_mem_usage) {
1246 static RRDSET *st_cpu = NULL;
1247 static RRDSET *st_mem_usage = NULL;
1249 // create the charts
1252 if(unlikely(!st_cpu)) {
1253 char title[CHART_TITLE_MAX + 1];
1255 st_cpu = rrdset_find_bytype("services", "cpu");
1257 snprintfz(title, CHART_TITLE_MAX, "Systemd Services CPU utilization (%d%% = %d core%s)", (processors * 100), processors, (processors > 1) ? "s" : "");
1258 st_cpu = rrdset_create("services", "cpu", NULL, "cpu", "services.cpu", title, "%", 30000, update_every, RRDSET_TYPE_STACKED);
1261 else rrdset_next(st_cpu);
1265 if(unlikely(!st_mem_usage)) {
1266 st_mem_usage = rrdset_find_bytype("services", "mem_usage");
1268 st_mem_usage = rrdset_create("services", "mem_usage", NULL, "mem", "services.mem_usage", "Systemd Services RAM Usage", "MB", 30001, update_every, RRDSET_TYPE_STACKED);
1270 else rrdset_next(st_mem_usage);
1273 // update the values
1275 for(cg = cgroup_root; cg ; cg = cg->next) {
1276 if(!cg->available || !cg->enabled || !(cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE)) continue;
1278 if(do_cpu && cg->cpuacct_stat.updated) {
1279 if(unlikely(!cg->rd_cpu))
1280 cg->rd_cpu = rrddim_add(st_cpu, cg->chart_id, cg->chart_title, 100, hz, RRDDIM_INCREMENTAL);
1282 rrddim_set_by_pointer(st_cpu, cg->rd_cpu, cg->cpuacct_stat.user + cg->cpuacct_stat.system);
1286 if(unlikely(!cg->rd_mem_usage))
1287 cg->rd_mem_usage = rrddim_add(st_mem_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1289 rrddim_set_by_pointer(st_mem_usage, cg->rd_mem_usage, cg->memory.usage_in_bytes);
1293 // complete the iteration
1294 if(do_cpu) rrdset_done(st_cpu);
1295 if(do_mem_usage) rrdset_done(st_mem_usage);
1298 static inline char *cgroup_chart_type(char *buffer, const char *id, size_t len) {
1299 if(buffer[0]) return buffer;
1301 if(id[0] == '\0' || (id[0] == '/' && id[1] == '\0'))
1302 strncpy(buffer, "cgroup_root", len);
1304 snprintfz(buffer, len, "cgroup_%s", id);
1306 netdata_fix_chart_id(buffer);
1310 void update_cgroup_charts(int update_every) {
1311 debug(D_CGROUP, "updating cgroups charts");
1313 char type[RRD_ID_LENGTH_MAX + 1];
1314 char title[CHART_TITLE_MAX + 1];
1316 int services_do_cpu = 0;
1317 int services_do_mem_usage = 0;
1320 for(cg = cgroup_root; cg ; cg = cg->next) {
1321 if(!cg->available || !cg->enabled) continue;
1323 if(cgroup_enable_systemd_services && cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE) {
1324 if(cg->cpuacct_stat.updated && (cg->cpuacct_stat.user || cg->cpuacct_stat.system)) services_do_cpu++;
1325 if(cg->memory.usage_in_bytes_updated) services_do_mem_usage++;
1331 if(cg->cpuacct_stat.updated) {
1332 if(unlikely(!cg->st_cpu)) {
1333 cg->st_cpu = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "cpu");
1335 snprintfz(title, CHART_TITLE_MAX, "CPU Usage (%d%% = %d core%s) for cgroup %s", (processors * 100), processors, (processors > 1) ? "s" : "", cg->chart_title);
1336 cg->st_cpu = rrdset_create(type, "cpu", NULL, "cpu", "cgroup.cpu", title, "%", 40000, update_every, RRDSET_TYPE_STACKED);
1338 rrddim_add(cg->st_cpu, "user", NULL, 100, hz, RRDDIM_INCREMENTAL);
1339 rrddim_add(cg->st_cpu, "system", NULL, 100, hz, RRDDIM_INCREMENTAL);
1342 else rrdset_next(cg->st_cpu);
1344 rrddim_set(cg->st_cpu, "user", cg->cpuacct_stat.user);
1345 rrddim_set(cg->st_cpu, "system", cg->cpuacct_stat.system);
1346 rrdset_done(cg->st_cpu);
1349 if(cg->cpuacct_usage.updated) {
1350 char id[RRD_ID_LENGTH_MAX + 1];
1353 if(unlikely(!cg->st_cpu_per_core)) {
1354 cg->st_cpu_per_core = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "cpu_per_core");
1355 if(!cg->st_cpu_per_core) {
1356 snprintfz(title, CHART_TITLE_MAX, "CPU Usage (%d%% = %d core%s) Per Core for cgroup %s", (processors * 100), processors, (processors > 1) ? "s" : "", cg->chart_title);
1357 cg->st_cpu_per_core = rrdset_create(type, "cpu_per_core", NULL, "cpu", "cgroup.cpu_per_core", title, "%", 40100, update_every, RRDSET_TYPE_STACKED);
1359 for(i = 0; i < cg->cpuacct_usage.cpus; i++) {
1360 snprintfz(id, CHART_TITLE_MAX, "cpu%u", i);
1361 rrddim_add(cg->st_cpu_per_core, id, NULL, 100, 1000000000, RRDDIM_INCREMENTAL);
1365 else rrdset_next(cg->st_cpu_per_core);
1367 for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
1368 snprintfz(id, CHART_TITLE_MAX, "cpu%u", i);
1369 rrddim_set(cg->st_cpu_per_core, id, cg->cpuacct_usage.cpu_percpu[i]);
1371 rrdset_done(cg->st_cpu_per_core);
1374 if(cg->memory.updated) {
1375 if(cg->memory.cache || cg->memory.rss || cg->memory.rss_huge || cg->memory.mapped_file) {
1376 if(unlikely(!cg->st_mem)) {
1377 cg->st_mem = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "mem");
1379 snprintfz(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_title);
1380 cg->st_mem = rrdset_create(type, "mem", NULL, "mem", "cgroup.mem", title, "MB", 40210, update_every, RRDSET_TYPE_STACKED);
1382 rrddim_add(cg->st_mem, "cache", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1383 rrddim_add(cg->st_mem, "rss", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1384 if(cg->memory.has_dirty_swap)
1385 rrddim_add(cg->st_mem, "swap", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1386 rrddim_add(cg->st_mem, "rss_huge", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1387 rrddim_add(cg->st_mem, "mapped_file", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1390 else rrdset_next(cg->st_mem);
1392 rrddim_set(cg->st_mem, "cache", cg->memory.cache);
1393 rrddim_set(cg->st_mem, "rss", cg->memory.rss);
1394 if(cg->memory.has_dirty_swap)
1395 rrddim_set(cg->st_mem, "swap", cg->memory.swap);
1396 rrddim_set(cg->st_mem, "rss_huge", cg->memory.rss_huge);
1397 rrddim_set(cg->st_mem, "mapped_file", cg->memory.mapped_file);
1398 rrdset_done(cg->st_mem);
1401 if(unlikely(!cg->st_writeback)) {
1402 cg->st_writeback = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "writeback");
1403 if(!cg->st_writeback) {
1404 snprintfz(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_title);
1405 cg->st_writeback = rrdset_create(type, "writeback", NULL, "mem", "cgroup.writeback", title, "MB", 40300, update_every, RRDSET_TYPE_AREA);
1407 if(cg->memory.has_dirty_swap)
1408 rrddim_add(cg->st_writeback, "dirty", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1409 rrddim_add(cg->st_writeback, "writeback", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1412 else rrdset_next(cg->st_writeback);
1414 if(cg->memory.has_dirty_swap)
1415 rrddim_set(cg->st_writeback, "dirty", cg->memory.dirty);
1416 rrddim_set(cg->st_writeback, "writeback", cg->memory.writeback);
1417 rrdset_done(cg->st_writeback);
1419 if(cg->memory.pgpgin || cg->memory.pgpgout) {
1420 if(unlikely(!cg->st_mem_activity)) {
1421 cg->st_mem_activity = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "mem_activity");
1422 if(!cg->st_mem_activity) {
1423 snprintfz(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_title);
1424 cg->st_mem_activity = rrdset_create(type, "mem_activity", NULL, "mem", "cgroup.mem_activity", title, "MB/s", 40400, update_every, RRDSET_TYPE_LINE);
1426 rrddim_add(cg->st_mem_activity, "pgpgin", "in", sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
1427 rrddim_add(cg->st_mem_activity, "pgpgout", "out", -sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
1430 else rrdset_next(cg->st_mem_activity);
1432 rrddim_set(cg->st_mem_activity, "pgpgin", cg->memory.pgpgin);
1433 rrddim_set(cg->st_mem_activity, "pgpgout", cg->memory.pgpgout);
1434 rrdset_done(cg->st_mem_activity);
1437 if(cg->memory.pgfault || cg->memory.pgmajfault) {
1438 if(unlikely(!cg->st_pgfaults)) {
1439 cg->st_pgfaults = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "pgfaults");
1440 if(!cg->st_pgfaults) {
1441 snprintfz(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_title);
1442 cg->st_pgfaults = rrdset_create(type, "pgfaults", NULL, "mem", "cgroup.pgfaults", title, "MB/s", 40500, update_every, RRDSET_TYPE_LINE);
1444 rrddim_add(cg->st_pgfaults, "pgfault", NULL, sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
1445 rrddim_add(cg->st_pgfaults, "pgmajfault", "swap", -sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
1448 else rrdset_next(cg->st_pgfaults);
1450 rrddim_set(cg->st_pgfaults, "pgfault", cg->memory.pgfault);
1451 rrddim_set(cg->st_pgfaults, "pgmajfault", cg->memory.pgmajfault);
1452 rrdset_done(cg->st_pgfaults);
1456 if(cg->memory.usage_in_bytes_updated) {
1457 if(unlikely(!cg->st_mem_usage)) {
1458 cg->st_mem_usage = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "mem_usage");
1459 if(!cg->st_mem_usage) {
1460 snprintfz(title, CHART_TITLE_MAX, "Total Memory for cgroup %s", cg->chart_title);
1461 cg->st_mem_usage = rrdset_create(type, "mem_usage", NULL, "mem", "cgroup.mem_usage", title, "MB", 40200, update_every, RRDSET_TYPE_STACKED);
1463 rrddim_add(cg->st_mem_usage, "ram", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1464 rrddim_add(cg->st_mem_usage, "swap", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
1467 else rrdset_next(cg->st_mem_usage);
1469 rrddim_set(cg->st_mem_usage, "ram", cg->memory.usage_in_bytes);
1470 rrddim_set(cg->st_mem_usage, "swap", (cg->memory.msw_usage_in_bytes > cg->memory.usage_in_bytes)?cg->memory.msw_usage_in_bytes - cg->memory.usage_in_bytes:0);
1471 rrdset_done(cg->st_mem_usage);
1474 if(cg->memory.failcnt_updated && cg->memory.failcnt) {
1475 if(unlikely(!cg->st_mem_failcnt)) {
1476 cg->st_mem_failcnt = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "mem_failcnt");
1477 if(!cg->st_mem_failcnt) {
1478 snprintfz(title, CHART_TITLE_MAX, "Memory Limit Failures for cgroup %s", cg->chart_title);
1479 cg->st_mem_failcnt = rrdset_create(type, "mem_failcnt", NULL, "mem", "cgroup.mem_failcnt", title, "MB", 40250, update_every, RRDSET_TYPE_LINE);
1481 rrddim_add(cg->st_mem_failcnt, "failures", NULL, 1, 1, RRDDIM_INCREMENTAL);
1484 else rrdset_next(cg->st_mem_failcnt);
1486 rrddim_set(cg->st_mem_failcnt, "failures", cg->memory.failcnt);
1487 rrdset_done(cg->st_mem_failcnt);
1490 if(cg->io_service_bytes.updated && (cg->io_service_bytes.Read || cg->io_service_bytes.Write)) {
1491 if(unlikely(!cg->st_io)) {
1492 cg->st_io = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "io");
1494 snprintfz(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1495 cg->st_io = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200, update_every, RRDSET_TYPE_AREA);
1497 rrddim_add(cg->st_io, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
1498 rrddim_add(cg->st_io, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
1501 else rrdset_next(cg->st_io);
1503 rrddim_set(cg->st_io, "read", cg->io_service_bytes.Read);
1504 rrddim_set(cg->st_io, "write", cg->io_service_bytes.Write);
1505 rrdset_done(cg->st_io);
1508 if(cg->io_serviced.updated && (cg->io_serviced.Read || cg->io_serviced.Write)) {
1509 if(unlikely(!cg->st_serviced_ops)) {
1510 cg->st_serviced_ops = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "serviced_ops");
1511 if(!cg->st_serviced_ops) {
1512 snprintfz(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s"
1514 cg->st_serviced_ops = rrdset_create(type, "serviced_ops", NULL, "disk", "cgroup.serviced_ops", title, "operations/s", 41200, update_every, RRDSET_TYPE_LINE);
1516 rrddim_add(cg->st_serviced_ops, "read", NULL, 1, 1, RRDDIM_INCREMENTAL);
1517 rrddim_add(cg->st_serviced_ops, "write", NULL, -1, 1, RRDDIM_INCREMENTAL);
1520 else rrdset_next(cg->st_serviced_ops);
1522 rrddim_set(cg->st_serviced_ops, "read", cg->io_serviced.Read);
1523 rrddim_set(cg->st_serviced_ops, "write", cg->io_serviced.Write);
1524 rrdset_done(cg->st_serviced_ops);
1527 if(cg->throttle_io_service_bytes.updated && (cg->throttle_io_service_bytes.Read || cg->throttle_io_service_bytes.Write)) {
1528 if(unlikely(!cg->st_throttle_io)) {
1529 cg->st_throttle_io = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "throttle_io");
1530 if(!cg->st_throttle_io) {
1531 snprintfz(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1532 cg->st_throttle_io = rrdset_create(type, "throttle_io", NULL, "disk", "cgroup.throttle_io", title, "KB/s", 41200, update_every, RRDSET_TYPE_AREA);
1534 rrddim_add(cg->st_throttle_io, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
1535 rrddim_add(cg->st_throttle_io, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
1538 else rrdset_next(cg->st_throttle_io);
1540 rrddim_set(cg->st_throttle_io, "read", cg->throttle_io_service_bytes.Read);
1541 rrddim_set(cg->st_throttle_io, "write", cg->throttle_io_service_bytes.Write);
1542 rrdset_done(cg->st_throttle_io);
1545 if(cg->throttle_io_serviced.updated && (cg->throttle_io_serviced.Read || cg->throttle_io_serviced.Write)) {
1546 if(unlikely(!cg->st_throttle_serviced_ops)) {
1547 cg->st_throttle_serviced_ops = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "throttle_serviced_ops");
1548 if(!cg->st_throttle_serviced_ops) {
1549 snprintfz(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1550 cg->st_throttle_serviced_ops = rrdset_create(type, "throttle_serviced_ops", NULL, "disk", "cgroup.throttle_serviced_ops", title, "operations/s", 41200, update_every, RRDSET_TYPE_LINE);
1552 rrddim_add(cg->st_throttle_serviced_ops, "read", NULL, 1, 1, RRDDIM_INCREMENTAL);
1553 rrddim_add(cg->st_throttle_serviced_ops, "write", NULL, -1, 1, RRDDIM_INCREMENTAL);
1556 else rrdset_next(cg->st_throttle_serviced_ops);
1558 rrddim_set(cg->st_throttle_serviced_ops, "read", cg->throttle_io_serviced.Read);
1559 rrddim_set(cg->st_throttle_serviced_ops, "write", cg->throttle_io_serviced.Write);
1560 rrdset_done(cg->st_throttle_serviced_ops);
1563 if(cg->io_queued.updated) {
1564 if(unlikely(!cg->st_queued_ops)) {
1565 cg->st_queued_ops = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "queued_ops");
1566 if(!cg->st_queued_ops) {
1567 snprintfz(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_title);
1568 cg->st_queued_ops = rrdset_create(type, "queued_ops", NULL, "disk", "cgroup.queued_ops", title, "operations", 42000, update_every, RRDSET_TYPE_LINE);
1570 rrddim_add(cg->st_queued_ops, "read", NULL, 1, 1, RRDDIM_ABSOLUTE);
1571 rrddim_add(cg->st_queued_ops, "write", NULL, -1, 1, RRDDIM_ABSOLUTE);
1574 else rrdset_next(cg->st_queued_ops);
1576 rrddim_set(cg->st_queued_ops, "read", cg->io_queued.Read);
1577 rrddim_set(cg->st_queued_ops, "write", cg->io_queued.Write);
1578 rrdset_done(cg->st_queued_ops);
1581 if(cg->io_merged.updated && (cg->io_merged.Read || cg->io_merged.Write)) {
1582 if(unlikely(!cg->st_merged_ops)) {
1583 cg->st_merged_ops = rrdset_find_bytype(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "merged_ops");
1584 if(!cg->st_merged_ops) {
1585 snprintfz(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_title);
1586 cg->st_merged_ops = rrdset_create(type, "merged_ops", NULL, "disk", "cgroup.merged_ops", title, "operations/s", 42100, update_every, RRDSET_TYPE_LINE);
1588 rrddim_add(cg->st_merged_ops, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
1589 rrddim_add(cg->st_merged_ops, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
1592 else rrdset_next(cg->st_merged_ops);
1594 rrddim_set(cg->st_merged_ops, "read", cg->io_merged.Read);
1595 rrddim_set(cg->st_merged_ops, "write", cg->io_merged.Write);
1596 rrdset_done(cg->st_merged_ops);
1600 debug(D_CGROUP, "done updating cgroups charts");
1602 if(cgroup_enable_systemd_services && services_do_cpu)
1603 update_services_charts(update_every, services_do_cpu, services_do_mem_usage);
1606 // ----------------------------------------------------------------------------
1609 void *cgroups_main(void *ptr) {
1610 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
1612 info("CGROUP Plugin thread created with task id %d", gettid());
1614 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
1615 error("Cannot set pthread cancel type to DEFERRED.");
1617 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
1618 error("Cannot set pthread cancel state to ENABLE.");
1620 struct rusage thread;
1622 // when ZERO, attempt to do it
1623 int vdo_cpu_netdata = config_get_boolean("plugin:cgroups", "cgroups plugin resource charts", 1);
1625 read_cgroup_plugin_configuration();
1627 RRDSET *stcpu_thread = NULL;
1629 usec_t step = cgroup_update_every * USEC_PER_SEC;
1630 usec_t find_every = cgroup_check_for_new_every * USEC_PER_SEC, find_next = 0;
1632 usec_t now = now_monotonic_usec();
1633 usec_t next = now - (now % step) + step;
1636 sleep_usec(next - now);
1637 now = now_monotonic_usec();
1640 if(unlikely(netdata_exit)) break;
1642 // BEGIN -- the job to be done
1644 if(unlikely(now >= find_next)) {
1646 find_next = now + find_every;
1649 read_all_cgroups(cgroup_root);
1650 update_cgroup_charts(cgroup_update_every);
1652 // END -- the job is done
1654 // --------------------------------------------------------------------
1656 if(vdo_cpu_netdata) {
1657 getrusage(RUSAGE_THREAD, &thread);
1659 if(!stcpu_thread) stcpu_thread = rrdset_find("netdata.plugin_cgroups_cpu");
1661 stcpu_thread = rrdset_create("netdata", "plugin_cgroups_cpu", NULL, "cgroups", NULL, "NetData CGroups Plugin CPU usage", "milliseconds/s", 132000, cgroup_update_every, RRDSET_TYPE_STACKED);
1663 rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL);
1664 rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
1666 else rrdset_next(stcpu_thread);
1668 rrddim_set(stcpu_thread, "user" , thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
1669 rrddim_set(stcpu_thread, "system", thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
1670 rrdset_done(stcpu_thread);
1674 info("CGROUP thread exiting");
1676 static_thread->enabled = 0;