3 // ----------------------------------------------------------------------------
6 #define CHART_PRIORITY_SYSTEMD_SERVICES 19000
7 #define CHART_PRIORITY_CONTAINERS 40000
9 static long system_page_size = 4096; // system will be queried via sysconf() in configuration()
11 static int cgroup_enable_cpuacct_stat = CONFIG_ONDEMAND_ONDEMAND;
12 static int cgroup_enable_cpuacct_usage = CONFIG_ONDEMAND_ONDEMAND;
13 static int cgroup_enable_memory = CONFIG_ONDEMAND_ONDEMAND;
14 static int cgroup_enable_detailed_memory = CONFIG_ONDEMAND_ONDEMAND;
15 static int cgroup_enable_memory_failcnt = CONFIG_ONDEMAND_ONDEMAND;
16 static int cgroup_enable_swap = CONFIG_ONDEMAND_ONDEMAND;
17 static int cgroup_enable_blkio_io = CONFIG_ONDEMAND_ONDEMAND;
18 static int cgroup_enable_blkio_ops = CONFIG_ONDEMAND_ONDEMAND;
19 static int cgroup_enable_blkio_throttle_io = CONFIG_ONDEMAND_ONDEMAND;
20 static int cgroup_enable_blkio_throttle_ops = CONFIG_ONDEMAND_ONDEMAND;
21 static int cgroup_enable_blkio_merged_ops = CONFIG_ONDEMAND_ONDEMAND;
22 static int cgroup_enable_blkio_queued_ops = CONFIG_ONDEMAND_ONDEMAND;
24 static int cgroup_enable_systemd_services = CONFIG_ONDEMAND_YES;
25 static int cgroup_enable_systemd_services_detailed_memory = CONFIG_ONDEMAND_NO;
26 static int cgroup_used_memory_without_cache = CONFIG_ONDEMAND_YES;
28 static int cgroup_search_in_devices = 1;
30 static int cgroup_enable_new_cgroups_detected_at_runtime = 1;
31 static int cgroup_check_for_new_every = 10;
32 static int cgroup_update_every = 1;
34 static int cgroup_recheck_zero_blkio_every_iterations = 10;
35 static int cgroup_recheck_zero_mem_failcnt_every_iterations = 10;
36 static int cgroup_recheck_zero_mem_detailed_every_iterations = 10;
38 static char *cgroup_cpuacct_base = NULL;
39 static char *cgroup_blkio_base = NULL;
40 static char *cgroup_memory_base = NULL;
41 static char *cgroup_devices_base = NULL;
43 static int cgroup_root_count = 0;
44 static int cgroup_root_max = 500;
45 static int cgroup_max_depth = 0;
47 static SIMPLE_PATTERN *enabled_cgroup_patterns = NULL;
48 static SIMPLE_PATTERN *enabled_cgroup_paths = NULL;
49 static SIMPLE_PATTERN *enabled_cgroup_renames = NULL;
50 static SIMPLE_PATTERN *systemd_services_cgroups = NULL;
52 static char *cgroups_rename_script = NULL;
54 static uint32_t Read_hash = 0;
55 static uint32_t Write_hash = 0;
56 static uint32_t user_hash = 0;
57 static uint32_t system_hash = 0;
59 void read_cgroup_plugin_configuration() {
60 system_page_size = sysconf(_SC_PAGESIZE);
62 Read_hash = simple_hash("Read");
63 Write_hash = simple_hash("Write");
64 user_hash = simple_hash("user");
65 system_hash = simple_hash("system");
67 cgroup_update_every = (int)config_get_number("plugin:cgroups", "update every", rrd_update_every);
68 if(cgroup_update_every < rrd_update_every)
69 cgroup_update_every = rrd_update_every;
71 cgroup_check_for_new_every = (int)config_get_number("plugin:cgroups", "check for new cgroups every", cgroup_check_for_new_every * cgroup_update_every);
72 if(cgroup_check_for_new_every < cgroup_update_every)
73 cgroup_check_for_new_every = cgroup_update_every;
75 cgroup_enable_cpuacct_stat = config_get_boolean_ondemand("plugin:cgroups", "enable cpuacct stat (total CPU)", cgroup_enable_cpuacct_stat);
76 cgroup_enable_cpuacct_usage = config_get_boolean_ondemand("plugin:cgroups", "enable cpuacct usage (per core CPU)", cgroup_enable_cpuacct_usage);
78 cgroup_enable_memory = config_get_boolean_ondemand("plugin:cgroups", "enable memory (used mem including cache)", cgroup_enable_memory);
79 cgroup_enable_detailed_memory = config_get_boolean_ondemand("plugin:cgroups", "enable detailed memory", cgroup_enable_detailed_memory);
80 cgroup_enable_memory_failcnt = config_get_boolean_ondemand("plugin:cgroups", "enable memory limits fail count", cgroup_enable_memory_failcnt);
81 cgroup_enable_swap = config_get_boolean_ondemand("plugin:cgroups", "enable swap memory", cgroup_enable_swap);
83 cgroup_enable_blkio_io = config_get_boolean_ondemand("plugin:cgroups", "enable blkio bandwidth", cgroup_enable_blkio_io);
84 cgroup_enable_blkio_ops = config_get_boolean_ondemand("plugin:cgroups", "enable blkio operations", cgroup_enable_blkio_ops);
85 cgroup_enable_blkio_throttle_io = config_get_boolean_ondemand("plugin:cgroups", "enable blkio throttle bandwidth", cgroup_enable_blkio_throttle_io);
86 cgroup_enable_blkio_throttle_ops = config_get_boolean_ondemand("plugin:cgroups", "enable blkio throttle operations", cgroup_enable_blkio_throttle_ops);
87 cgroup_enable_blkio_queued_ops = config_get_boolean_ondemand("plugin:cgroups", "enable blkio queued operations", cgroup_enable_blkio_queued_ops);
88 cgroup_enable_blkio_merged_ops = config_get_boolean_ondemand("plugin:cgroups", "enable blkio merged operations", cgroup_enable_blkio_merged_ops);
90 cgroup_recheck_zero_blkio_every_iterations = (int)config_get_number("plugin:cgroups", "recheck zero blkio every iterations", cgroup_recheck_zero_blkio_every_iterations);
91 cgroup_recheck_zero_mem_failcnt_every_iterations = (int)config_get_number("plugin:cgroups", "recheck zero memory failcnt every iterations", cgroup_recheck_zero_mem_failcnt_every_iterations);
92 cgroup_recheck_zero_mem_detailed_every_iterations = (int)config_get_number("plugin:cgroups", "recheck zero detailed memory every iterations", cgroup_recheck_zero_mem_detailed_every_iterations);
94 cgroup_enable_systemd_services = config_get_boolean("plugin:cgroups", "enable systemd services", cgroup_enable_systemd_services);
95 cgroup_enable_systemd_services_detailed_memory = config_get_boolean("plugin:cgroups", "enable systemd services detailed memory", cgroup_enable_systemd_services_detailed_memory);
96 cgroup_used_memory_without_cache = config_get_boolean("plugin:cgroups", "report used memory without cache", cgroup_used_memory_without_cache);
98 char filename[FILENAME_MAX + 1], *s;
99 struct mountinfo *mi, *root = mountinfo_read(0);
101 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuacct");
102 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "cpuacct");
104 error("Cannot find cgroup cpuacct mountinfo. Assuming default: /sys/fs/cgroup/cpuacct");
105 s = "/sys/fs/cgroup/cpuacct";
107 else s = mi->mount_point;
108 snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
109 cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
111 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio");
112 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "blkio");
114 error("Cannot find cgroup blkio mountinfo. Assuming default: /sys/fs/cgroup/blkio");
115 s = "/sys/fs/cgroup/blkio";
117 else s = mi->mount_point;
118 snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
119 cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
121 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory");
122 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "memory");
124 error("Cannot find cgroup memory mountinfo. Assuming default: /sys/fs/cgroup/memory");
125 s = "/sys/fs/cgroup/memory";
127 else s = mi->mount_point;
128 snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
129 cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
131 mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "devices");
132 if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "devices");
134 error("Cannot find cgroup devices mountinfo. Assuming default: /sys/fs/cgroup/devices");
135 s = "/sys/fs/cgroup/devices";
137 else s = mi->mount_point;
138 snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, s);
139 cgroup_devices_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/devices", filename);
141 cgroup_root_max = (int)config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
142 cgroup_max_depth = (int)config_get_number("plugin:cgroups", "max cgroups depth to monitor", cgroup_max_depth);
144 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);
146 enabled_cgroup_patterns = simple_pattern_create(
147 config_get("plugin:cgroups", "enable by default cgroups matching",
148 " /system.slice/docker-*.scope "
160 " !/lxc/*/ns " // #1397
166 " * " // enable anything else
167 ), SIMPLE_PATTERN_EXACT);
169 enabled_cgroup_paths = simple_pattern_create(
170 config_get("plugin:cgroups", "search for cgroups in subpaths matching",
178 ), SIMPLE_PATTERN_EXACT);
180 snprintfz(filename, FILENAME_MAX, "%s/cgroup-name.sh", netdata_configured_plugins_dir);
181 cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", filename);
183 enabled_cgroup_renames = simple_pattern_create(
184 config_get("plugin:cgroups", "run script to rename cgroups matching",
196 ), SIMPLE_PATTERN_EXACT);
198 if(cgroup_enable_systemd_services) {
199 systemd_services_cgroups = simple_pattern_create(
200 config_get("plugin:cgroups", "cgroups to match as systemd services",
201 " !/system.slice/*/*.service "
202 " /system.slice/*.service "
203 ), SIMPLE_PATTERN_EXACT);
206 mountinfo_free(root);
209 // ----------------------------------------------------------------------------
214 int enabled; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
219 unsigned long long Read;
220 unsigned long long Write;
222 unsigned long long Sync;
223 unsigned long long Async;
224 unsigned long long Total;
228 // https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
231 ARL_ENTRY *arl_dirty;
234 int updated_detailed;
235 int updated_usage_in_bytes;
236 int updated_msw_usage_in_bytes;
239 int enabled_detailed; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
240 int enabled_usage_in_bytes; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
241 int enabled_msw_usage_in_bytes; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
242 int enabled_failcnt; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
244 int delay_counter_detailed;
245 int delay_counter_failcnt;
247 char *filename_detailed;
248 char *filename_usage_in_bytes;
249 char *filename_msw_usage_in_bytes;
250 char *filename_failcnt;
252 int detailed_has_dirty;
253 int detailed_has_swap;
256 unsigned long long cache;
257 unsigned long long rss;
258 unsigned long long rss_huge;
259 unsigned long long mapped_file;
260 unsigned long long writeback;
261 unsigned long long dirty;
262 unsigned long long swap;
263 unsigned long long pgpgin;
264 unsigned long long pgpgout;
265 unsigned long long pgfault;
266 unsigned long long pgmajfault;
268 unsigned long long inactive_anon;
269 unsigned long long active_anon;
270 unsigned long long inactive_file;
271 unsigned long long active_file;
272 unsigned long long unevictable;
273 unsigned long long hierarchical_memory_limit;
274 unsigned long long total_cache;
275 unsigned long long total_rss;
276 unsigned long long total_rss_huge;
277 unsigned long long total_mapped_file;
278 unsigned long long total_writeback;
279 unsigned long long total_dirty;
280 unsigned long long total_swap;
281 unsigned long long total_pgpgin;
282 unsigned long long total_pgpgout;
283 unsigned long long total_pgfault;
284 unsigned long long total_pgmajfault;
285 unsigned long long total_inactive_anon;
286 unsigned long long total_active_anon;
287 unsigned long long total_inactive_file;
288 unsigned long long total_active_file;
289 unsigned long long total_unevictable;
292 // single file metrics
293 unsigned long long usage_in_bytes;
294 unsigned long long msw_usage_in_bytes;
295 unsigned long long failcnt;
298 // https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
299 struct cpuacct_stat {
301 int enabled; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
305 unsigned long long user;
306 unsigned long long system;
309 // https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
310 struct cpuacct_usage {
312 int enabled; // CONFIG_ONDEMAND_YES or CONFIG_ONDEMAND_ONDEMAND
317 unsigned long long *cpu_percpu;
320 #define CGROUP_OPTIONS_DISABLED_DUPLICATE 0x00000001
321 #define CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE 0x00000002
326 char available; // found in the filesystem
327 char enabled; // enabled in the config
337 struct cpuacct_stat cpuacct_stat;
338 struct cpuacct_usage cpuacct_usage;
340 struct memory memory;
342 struct blkio io_service_bytes; // bytes
343 struct blkio io_serviced; // operations
345 struct blkio throttle_io_service_bytes; // bytes
346 struct blkio throttle_io_serviced; // operations
348 struct blkio io_merged; // operations
349 struct blkio io_queued; // operations
353 RRDSET *st_cpu_per_core;
355 RRDSET *st_writeback;
356 RRDSET *st_mem_activity;
358 RRDSET *st_mem_usage;
359 RRDSET *st_mem_failcnt;
361 RRDSET *st_serviced_ops;
362 RRDSET *st_throttle_io;
363 RRDSET *st_throttle_serviced_ops;
364 RRDSET *st_queued_ops;
365 RRDSET *st_merged_ops;
369 RRDDIM *rd_mem_usage;
370 RRDDIM *rd_mem_failcnt;
371 RRDDIM *rd_swap_usage;
373 RRDDIM *rd_mem_detailed_cache;
374 RRDDIM *rd_mem_detailed_rss;
375 RRDDIM *rd_mem_detailed_mapped;
376 RRDDIM *rd_mem_detailed_writeback;
377 RRDDIM *rd_mem_detailed_pgpgin;
378 RRDDIM *rd_mem_detailed_pgpgout;
379 RRDDIM *rd_mem_detailed_pgfault;
380 RRDDIM *rd_mem_detailed_pgmajfault;
382 RRDDIM *rd_io_service_bytes_read;
383 RRDDIM *rd_io_serviced_read;
384 RRDDIM *rd_throttle_io_read;
385 RRDDIM *rd_throttle_io_serviced_read;
386 RRDDIM *rd_io_queued_read;
387 RRDDIM *rd_io_merged_read;
389 RRDDIM *rd_io_service_bytes_write;
390 RRDDIM *rd_io_serviced_write;
391 RRDDIM *rd_throttle_io_write;
392 RRDDIM *rd_throttle_io_serviced_write;
393 RRDDIM *rd_io_queued_write;
394 RRDDIM *rd_io_merged_write;
398 } *cgroup_root = NULL;
400 // ----------------------------------------------------------------------------
401 // read values from /sys
403 static inline void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) {
404 static procfile *ff = NULL;
406 if(likely(cp->filename)) {
407 ff = procfile_reopen(ff, cp->filename, NULL, PROCFILE_FLAG_DEFAULT);
413 ff = procfile_readall(ff);
419 unsigned long i, lines = procfile_lines(ff);
421 if(unlikely(lines < 1)) {
422 error("File '%s' should have 1+ lines.", cp->filename);
427 for(i = 0; i < lines ; i++) {
428 char *s = procfile_lineword(ff, i, 0);
429 uint32_t hash = simple_hash(s);
431 if(unlikely(hash == user_hash && !strcmp(s, "user")))
432 cp->user = str2ull(procfile_lineword(ff, i, 1));
434 else if(unlikely(hash == system_hash && !strcmp(s, "system")))
435 cp->system = str2ull(procfile_lineword(ff, i, 1));
440 if(unlikely(cp->enabled == CONFIG_ONDEMAND_ONDEMAND && (cp->user || cp->system)))
441 cp->enabled = CONFIG_ONDEMAND_YES;
445 static inline void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
446 static procfile *ff = NULL;
448 if(likely(ca->filename)) {
449 ff = procfile_reopen(ff, ca->filename, NULL, PROCFILE_FLAG_DEFAULT);
455 ff = procfile_readall(ff);
461 if(unlikely(procfile_lines(ff) < 1)) {
462 error("File '%s' should have 1+ lines but has %zu.", ca->filename, procfile_lines(ff));
467 unsigned long i = procfile_linewords(ff, 0);
468 if(unlikely(i == 0)) {
473 // we may have 1 more CPU reported
475 char *s = procfile_lineword(ff, 0, i - 1);
480 if(unlikely(i != ca->cpus)) {
481 freez(ca->cpu_percpu);
482 ca->cpu_percpu = mallocz(sizeof(unsigned long long) * i);
483 ca->cpus = (unsigned int)i;
486 unsigned long long total = 0;
487 for(i = 0; i < ca->cpus ;i++) {
488 unsigned long long n = str2ull(procfile_lineword(ff, 0, i));
489 ca->cpu_percpu[i] = n;
495 if(unlikely(ca->enabled == CONFIG_ONDEMAND_ONDEMAND && total))
496 ca->enabled = CONFIG_ONDEMAND_YES;
500 static inline void cgroup_read_blkio(struct blkio *io) {
501 static procfile *ff = NULL;
503 if(unlikely(io->enabled == CONFIG_ONDEMAND_ONDEMAND && io->delay_counter > 0)) {
508 if(likely(io->filename)) {
509 ff = procfile_reopen(ff, io->filename, NULL, PROCFILE_FLAG_DEFAULT);
515 ff = procfile_readall(ff);
521 unsigned long i, lines = procfile_lines(ff);
523 if(unlikely(lines < 1)) {
524 error("File '%s' should have 1+ lines.", io->filename);
537 for(i = 0; i < lines ; i++) {
538 char *s = procfile_lineword(ff, i, 1);
539 uint32_t hash = simple_hash(s);
541 if(unlikely(hash == Read_hash && !strcmp(s, "Read")))
542 io->Read += str2ull(procfile_lineword(ff, i, 2));
544 else if(unlikely(hash == Write_hash && !strcmp(s, "Write")))
545 io->Write += str2ull(procfile_lineword(ff, i, 2));
548 else if(unlikely(hash == Sync_hash && !strcmp(s, "Sync")))
549 io->Sync += str2ull(procfile_lineword(ff, i, 2));
551 else if(unlikely(hash == Async_hash && !strcmp(s, "Async")))
552 io->Async += str2ull(procfile_lineword(ff, i, 2));
554 else if(unlikely(hash == Total_hash && !strcmp(s, "Total")))
555 io->Total += str2ull(procfile_lineword(ff, i, 2));
561 if(unlikely(io->enabled == CONFIG_ONDEMAND_ONDEMAND)) {
562 if(unlikely(io->Read || io->Write))
563 io->enabled = CONFIG_ONDEMAND_YES;
565 io->delay_counter = cgroup_recheck_zero_blkio_every_iterations;
570 static inline void cgroup_read_memory(struct memory *mem) {
571 static procfile *ff = NULL;
573 // read detailed ram usage
574 if(likely(mem->filename_detailed)) {
575 if(unlikely(mem->enabled_detailed == CONFIG_ONDEMAND_ONDEMAND && mem->delay_counter_detailed > 0)) {
576 mem->delay_counter_detailed--;
580 ff = procfile_reopen(ff, mem->filename_detailed, NULL, PROCFILE_FLAG_DEFAULT);
582 mem->updated_detailed = 0;
586 ff = procfile_readall(ff);
588 mem->updated_detailed = 0;
592 unsigned long i, lines = procfile_lines(ff);
594 if(unlikely(lines < 1)) {
595 error("File '%s' should have 1+ lines.", mem->filename_detailed);
596 mem->updated_detailed = 0;
600 if(unlikely(!mem->arl_base)) {
601 mem->arl_base = arl_create("cgroup/memory", NULL, 60);
603 arl_expect(mem->arl_base, "cache", &mem->cache);
604 arl_expect(mem->arl_base, "rss", &mem->rss);
605 arl_expect(mem->arl_base, "rss_huge", &mem->rss_huge);
606 arl_expect(mem->arl_base, "mapped_file", &mem->mapped_file);
607 arl_expect(mem->arl_base, "writeback", &mem->writeback);
608 mem->arl_dirty = arl_expect(mem->arl_base, "dirty", &mem->dirty);
609 mem->arl_swap = arl_expect(mem->arl_base, "swap", &mem->swap);
610 arl_expect(mem->arl_base, "pgpgin", &mem->pgpgin);
611 arl_expect(mem->arl_base, "pgpgout", &mem->pgpgout);
612 arl_expect(mem->arl_base, "pgfault", &mem->pgfault);
613 arl_expect(mem->arl_base, "pgmajfault", &mem->pgmajfault);
616 arl_begin(mem->arl_base);
618 for(i = 0; i < lines ; i++) {
619 if(arl_check(mem->arl_base,
620 procfile_lineword(ff, i, 0),
621 procfile_lineword(ff, i, 1))) break;
624 if(unlikely(mem->arl_dirty->flags & ARL_ENTRY_FLAG_FOUND))
625 mem->detailed_has_dirty = 1;
627 if(unlikely(mem->arl_swap->flags & ARL_ENTRY_FLAG_FOUND))
628 mem->detailed_has_swap = 1;
630 // 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);
632 mem->updated_detailed = 1;
634 if(unlikely(mem->enabled_detailed == CONFIG_ONDEMAND_ONDEMAND)) {
635 if(mem->cache || mem->dirty || mem->rss || mem->rss_huge || mem->mapped_file || mem->writeback || mem->swap || mem->pgpgin || mem->pgpgout || mem->pgfault || mem->pgmajfault)
636 mem->enabled_detailed = CONFIG_ONDEMAND_YES;
638 mem->delay_counter_detailed = cgroup_recheck_zero_mem_detailed_every_iterations;
644 // read usage_in_bytes
645 if(likely(mem->filename_usage_in_bytes)) {
646 mem->updated_usage_in_bytes = !read_single_number_file(mem->filename_usage_in_bytes, &mem->usage_in_bytes);
647 if(unlikely(mem->updated_usage_in_bytes && mem->enabled_usage_in_bytes == CONFIG_ONDEMAND_ONDEMAND && mem->usage_in_bytes))
648 mem->enabled_usage_in_bytes = CONFIG_ONDEMAND_YES;
651 // read msw_usage_in_bytes
652 if(likely(mem->filename_msw_usage_in_bytes)) {
653 mem->updated_msw_usage_in_bytes = !read_single_number_file(mem->filename_msw_usage_in_bytes, &mem->msw_usage_in_bytes);
654 if(unlikely(mem->updated_msw_usage_in_bytes && mem->enabled_msw_usage_in_bytes == CONFIG_ONDEMAND_ONDEMAND && mem->msw_usage_in_bytes))
655 mem->enabled_msw_usage_in_bytes = CONFIG_ONDEMAND_YES;
659 if(likely(mem->filename_failcnt)) {
660 if(unlikely(mem->enabled_failcnt == CONFIG_ONDEMAND_ONDEMAND && mem->delay_counter_failcnt > 0)) {
661 mem->updated_failcnt = 0;
662 mem->delay_counter_failcnt--;
665 mem->updated_failcnt = !read_single_number_file(mem->filename_failcnt, &mem->failcnt);
666 if(unlikely(mem->updated_failcnt && mem->enabled_failcnt == CONFIG_ONDEMAND_ONDEMAND)) {
667 if(unlikely(!mem->failcnt))
668 mem->delay_counter_failcnt = cgroup_recheck_zero_mem_failcnt_every_iterations;
670 mem->enabled_failcnt = CONFIG_ONDEMAND_YES;
676 static inline void cgroup_read(struct cgroup *cg) {
677 debug(D_CGROUP, "reading metrics for cgroups '%s'", cg->id);
679 cgroup_read_cpuacct_stat(&cg->cpuacct_stat);
680 cgroup_read_cpuacct_usage(&cg->cpuacct_usage);
681 cgroup_read_memory(&cg->memory);
682 cgroup_read_blkio(&cg->io_service_bytes);
683 cgroup_read_blkio(&cg->io_serviced);
684 cgroup_read_blkio(&cg->throttle_io_service_bytes);
685 cgroup_read_blkio(&cg->throttle_io_serviced);
686 cgroup_read_blkio(&cg->io_merged);
687 cgroup_read_blkio(&cg->io_queued);
690 static inline void read_all_cgroups(struct cgroup *root) {
691 debug(D_CGROUP, "reading metrics for all cgroups");
695 for(cg = root; cg ; cg = cg->next)
696 if(cg->enabled && cg->available)
700 // ----------------------------------------------------------------------------
701 // add/remove/find cgroup objects
703 #define CGROUP_CHARTID_LINE_MAX 1024
705 static inline char *cgroup_title_strdupz(const char *s) {
706 if(!s || !*s) s = "/";
708 if(*s == '/' && s[1] != '\0') s++;
710 char *r = strdupz(s);
711 netdata_fix_chart_name(r);
716 static inline char *cgroup_chart_id_strdupz(const char *s) {
717 if(!s || !*s) s = "/";
719 if(*s == '/' && s[1] != '\0') s++;
721 char *r = strdupz(s);
722 netdata_fix_chart_id(r);
727 static inline void cgroup_get_chart_name(struct cgroup *cg) {
728 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);
731 char buffer[CGROUP_CHARTID_LINE_MAX + 1];
733 snprintfz(buffer, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'", cgroups_rename_script, cg->chart_id);
735 debug(D_CGROUP, "executing command '%s' for cgroup '%s'", buffer, cg->id);
736 FILE *fp = mypopen(buffer, &cgroup_pid);
738 // debug(D_CGROUP, "reading from command '%s' for cgroup '%s'", buffer, cg->id);
739 char *s = fgets(buffer, CGROUP_CHARTID_LINE_MAX, fp);
740 // debug(D_CGROUP, "closing command for cgroup '%s'", cg->id);
741 mypclose(fp, cgroup_pid);
742 // debug(D_CGROUP, "closed command for cgroup '%s'", cg->id);
744 if(s && *s && *s != '\n') {
745 debug(D_CGROUP, "cgroup '%s' should be renamed to '%s'", cg->id, s);
749 freez(cg->chart_title);
750 cg->chart_title = cgroup_title_strdupz(s);
753 cg->chart_id = cgroup_chart_id_strdupz(s);
754 cg->hash_chart = simple_hash(cg->chart_id);
758 error("CGROUP: Cannot popen(\"%s\", \"r\").", buffer);
761 static inline struct cgroup *cgroup_add(const char *id) {
762 if(!id || !*id) id = "/";
763 debug(D_CGROUP, "adding to list, cgroup with id '%s'", id);
765 if(cgroup_root_count >= cgroup_root_max) {
766 info("Maximum number of cgroups reached (%d). Not adding cgroup '%s'", cgroup_root_count, id);
770 int def = simple_pattern_matches(enabled_cgroup_patterns, id)?cgroup_enable_new_cgroups_detected_at_runtime:0;
771 struct cgroup *cg = callocz(1, sizeof(struct cgroup));
773 cg->id = strdupz(id);
774 cg->hash = simple_hash(cg->id);
776 cg->chart_title = cgroup_title_strdupz(id);
778 cg->chart_id = cgroup_chart_id_strdupz(id);
779 cg->hash_chart = simple_hash(cg->chart_id);
786 for(e = cgroup_root; e->next ;e = e->next) ;
792 // fix the chart_id and title by calling the external script
793 if(simple_pattern_matches(enabled_cgroup_renames, cg->id)) {
795 cgroup_get_chart_name(cg);
797 debug(D_CGROUP, "cgroup '%s' renamed to '%s' (title: '%s')", cg->id, cg->chart_id, cg->chart_title);
800 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);
802 int user_configurable = 1;
804 // check if this cgroup should be a systemd service
805 if(cgroup_enable_systemd_services) {
806 if(simple_pattern_matches(systemd_services_cgroups, cg->id) ||
807 simple_pattern_matches(systemd_services_cgroups, cg->chart_id)) {
808 debug(D_CGROUP, "cgroup '%s' with chart id '%s' (title: '%s') matches systemd services cgroups", cg->id, cg->chart_id, cg->chart_title);
810 char buffer[CGROUP_CHARTID_LINE_MAX + 1];
811 cg->options |= CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE;
813 strncpy(buffer, cg->id, CGROUP_CHARTID_LINE_MAX);
816 //freez(cg->chart_id);
817 //cg->chart_id = cgroup_chart_id_strdupz(s);
818 //cg->hash_chart = simple_hash(cg->chart_id);
820 // skip to the last slash
821 size_t len = strlen(s);
822 while(len--) if(unlikely(s[len] == '/')) break;
823 if(len) s = &s[len + 1];
827 while(len--) if(unlikely(s[len] == '.')) break;
828 if(len) s[len] = '\0';
830 freez(cg->chart_title);
831 cg->chart_title = cgroup_title_strdupz(s);
834 user_configurable = 0;
836 debug(D_CGROUP, "cgroup '%s' renamed to '%s' (title: '%s')", cg->id, cg->chart_id, cg->chart_title);
839 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);
842 if(user_configurable) {
843 // allow the user to enable/disable this individualy
844 char option[FILENAME_MAX + 1];
845 snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
846 cg->enabled = (char) config_get_boolean("plugin:cgroups", option, def);
849 // detect duplicate cgroups
852 for (t = cgroup_root; t; t = t->next) {
853 if (t != cg && t->enabled && t->hash_chart == cg->hash_chart && !strcmp(t->chart_id, cg->chart_id)) {
854 if (!strncmp(t->chart_id, "/system.slice/", 14) && !strncmp(cg->chart_id, "/init.scope/system.slice/", 25)) {
855 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'.",
856 cg->chart_id, t->id, cg->id, t->id);
857 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'.",
858 cg->chart_id, t->id, cg->id, t->id);
860 t->options |= CGROUP_OPTIONS_DISABLED_DUPLICATE;
863 error("Control group with chart id '%s' already exists with id '%s' and is enabled and available. Disabling cgroup with id '%s'.",
864 cg->chart_id, t->id, cg->id);
865 debug(D_CGROUP, "Control group with chart id '%s' already exists with id '%s' and is enabled and available. Disabling cgroup with id '%s'.",
866 cg->chart_id, t->id, cg->id);
868 cg->options |= CGROUP_OPTIONS_DISABLED_DUPLICATE;
876 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");
881 static inline void cgroup_free(struct cgroup *cg) {
882 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");
884 freez(cg->cpuacct_usage.cpu_percpu);
886 freez(cg->cpuacct_stat.filename);
887 freez(cg->cpuacct_usage.filename);
889 arl_free(cg->memory.arl_base);
890 freez(cg->memory.filename_detailed);
891 freez(cg->memory.filename_failcnt);
892 freez(cg->memory.filename_usage_in_bytes);
893 freez(cg->memory.filename_msw_usage_in_bytes);
895 freez(cg->io_service_bytes.filename);
896 freez(cg->io_serviced.filename);
898 freez(cg->throttle_io_service_bytes.filename);
899 freez(cg->throttle_io_serviced.filename);
901 freez(cg->io_merged.filename);
902 freez(cg->io_queued.filename);
906 freez(cg->chart_title);
913 // find if a given cgroup exists
914 static inline struct cgroup *cgroup_find(const char *id) {
915 debug(D_CGROUP, "searching for cgroup '%s'", id);
917 uint32_t hash = simple_hash(id);
920 for(cg = cgroup_root; cg ; cg = cg->next) {
921 if(hash == cg->hash && strcmp(id, cg->id) == 0)
925 debug(D_CGROUP, "cgroup '%s' %s in memory", id, (cg)?"found":"not found");
929 // ----------------------------------------------------------------------------
930 // detect running cgroups
932 // callback for find_file_in_subdirs()
933 static inline void found_subdir_in_dir(const char *dir) {
934 debug(D_CGROUP, "examining cgroup dir '%s'", dir);
936 struct cgroup *cg = cgroup_find(dir);
938 if(*dir && cgroup_max_depth > 0) {
942 for(s = dir; *s ;s++)
943 if(unlikely(*s == '/'))
946 if(depth > cgroup_max_depth) {
947 info("cgroup '%s' is too deep (%d, while max is %d)", dir, depth, cgroup_max_depth);
951 // debug(D_CGROUP, "will add dir '%s' as cgroup", dir);
952 cg = cgroup_add(dir);
955 if(cg) cg->available = 1;
958 static inline int find_dir_in_subdirs(const char *base, const char *this, void (*callback)(const char *)) {
959 if(!this) this = base;
960 debug(D_CGROUP, "searching for directories in '%s' (base '%s')", this?this:"", base);
962 size_t dirlen = strlen(this), baselen = strlen(base);
967 const char *relative_path = &this[baselen];
968 if(!*relative_path) relative_path = "/";
970 DIR *dir = opendir(this);
972 error("Cannot read cgroups directory '%s'", base);
977 callback(relative_path);
979 struct dirent *de = NULL;
980 while((de = readdir(dir))) {
981 if(de->d_type == DT_DIR
983 (de->d_name[0] == '.' && de->d_name[1] == '\0')
984 || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
988 if(de->d_type == DT_DIR) {
990 const char *r = relative_path;
991 if(*r == '\0') r = "/";
993 // do not decent in directories we are not interested
994 int def = simple_pattern_matches(enabled_cgroup_paths, r);
996 // we check for this option here
997 // so that the config will not have settings
998 // for leaf directories
999 char option[FILENAME_MAX + 1];
1000 snprintfz(option, FILENAME_MAX, "search for cgroups under %s", r);
1001 option[FILENAME_MAX] = '\0';
1002 enabled = config_get_boolean("plugin:cgroups", option, def);
1006 char *s = mallocz(dirlen + strlen(de->d_name) + 2);
1009 strcat(s, de->d_name);
1010 int ret2 = find_dir_in_subdirs(base, s, callback);
1011 if(ret2 > 0) ret += ret2;
1021 static inline void mark_all_cgroups_as_not_available() {
1022 debug(D_CGROUP, "marking all cgroups as not available");
1026 // mark all as not available
1027 for(cg = cgroup_root; cg ; cg = cg->next) {
1032 static inline void cleanup_all_cgroups() {
1033 struct cgroup *cg = cgroup_root, *last = NULL;
1036 if(!cg->available) {
1037 // enable the first duplicate cgroup
1040 for(t = cgroup_root; t ; t = t->next) {
1041 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)) {
1042 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);
1044 t->options &= ~CGROUP_OPTIONS_DISABLED_DUPLICATE;
1051 cgroup_root = cg->next;
1053 last->next = cg->next;
1069 static inline void find_all_cgroups() {
1070 debug(D_CGROUP, "searching for cgroups");
1072 mark_all_cgroups_as_not_available();
1074 if(cgroup_enable_cpuacct_stat || cgroup_enable_cpuacct_usage) {
1075 if(find_dir_in_subdirs(cgroup_cpuacct_base, NULL, found_subdir_in_dir) == -1) {
1076 cgroup_enable_cpuacct_stat =
1077 cgroup_enable_cpuacct_usage = CONFIG_ONDEMAND_NO;
1078 error("disabled CGROUP cpu statistics.");
1082 if(cgroup_enable_blkio_io || cgroup_enable_blkio_ops || cgroup_enable_blkio_throttle_io || cgroup_enable_blkio_throttle_ops || cgroup_enable_blkio_merged_ops || cgroup_enable_blkio_queued_ops) {
1083 if(find_dir_in_subdirs(cgroup_blkio_base, NULL, found_subdir_in_dir) == -1) {
1084 cgroup_enable_blkio_io =
1085 cgroup_enable_blkio_ops =
1086 cgroup_enable_blkio_throttle_io =
1087 cgroup_enable_blkio_throttle_ops =
1088 cgroup_enable_blkio_merged_ops =
1089 cgroup_enable_blkio_queued_ops = CONFIG_ONDEMAND_NO;
1090 error("disabled CGROUP blkio statistics.");
1094 if(cgroup_enable_memory || cgroup_enable_detailed_memory || cgroup_enable_swap || cgroup_enable_memory_failcnt) {
1095 if(find_dir_in_subdirs(cgroup_memory_base, NULL, found_subdir_in_dir) == -1) {
1096 cgroup_enable_memory =
1097 cgroup_enable_detailed_memory =
1098 cgroup_enable_swap =
1099 cgroup_enable_memory_failcnt = CONFIG_ONDEMAND_NO;
1100 error("disabled CGROUP memory statistics.");
1104 if(cgroup_search_in_devices) {
1105 if(find_dir_in_subdirs(cgroup_devices_base, NULL, found_subdir_in_dir) == -1) {
1106 cgroup_search_in_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(likely(stat(filename, &buf) != -1)) {
1130 cg->cpuacct_stat.filename = strdupz(filename);
1131 cg->cpuacct_stat.enabled = cgroup_enable_cpuacct_stat;
1132 debug(D_CGROUP, "cpuacct.stat filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_stat.filename);
1135 debug(D_CGROUP, "cpuacct.stat file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1138 if(unlikely(cgroup_enable_cpuacct_usage && !cg->cpuacct_usage.filename && !(cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE))) {
1139 snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.usage_percpu", cgroup_cpuacct_base, cg->id);
1140 if(likely(stat(filename, &buf) != -1)) {
1141 cg->cpuacct_usage.filename = strdupz(filename);
1142 cg->cpuacct_usage.enabled = cgroup_enable_cpuacct_usage;
1143 debug(D_CGROUP, "cpuacct.usage_percpu filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_usage.filename);
1146 debug(D_CGROUP, "cpuacct.usage_percpu file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1149 if(unlikely((cgroup_enable_detailed_memory || cgroup_used_memory_without_cache) && !cg->memory.filename_detailed && (cgroup_used_memory_without_cache || cgroup_enable_systemd_services_detailed_memory || !(cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE)))) {
1150 snprintfz(filename, FILENAME_MAX, "%s%s/memory.stat", cgroup_memory_base, cg->id);
1151 if(likely(stat(filename, &buf) != -1)) {
1152 cg->memory.filename_detailed = strdupz(filename);
1153 cg->memory.enabled_detailed = (cgroup_enable_detailed_memory == CONFIG_ONDEMAND_YES)?CONFIG_ONDEMAND_YES:CONFIG_ONDEMAND_ONDEMAND;
1154 debug(D_CGROUP, "memory.stat filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_detailed);
1157 debug(D_CGROUP, "memory.stat file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1160 if(unlikely(cgroup_enable_memory && !cg->memory.filename_usage_in_bytes)) {
1161 snprintfz(filename, FILENAME_MAX, "%s%s/memory.usage_in_bytes", cgroup_memory_base, cg->id);
1162 if(likely(stat(filename, &buf) != -1)) {
1163 cg->memory.filename_usage_in_bytes = strdupz(filename);
1164 cg->memory.enabled_usage_in_bytes = cgroup_enable_memory;
1165 debug(D_CGROUP, "memory.usage_in_bytes filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_usage_in_bytes);
1168 debug(D_CGROUP, "memory.usage_in_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1171 if(unlikely(cgroup_enable_swap && !cg->memory.filename_msw_usage_in_bytes)) {
1172 snprintfz(filename, FILENAME_MAX, "%s%s/memory.msw_usage_in_bytes", cgroup_memory_base, cg->id);
1173 if(likely(stat(filename, &buf) != -1)) {
1174 cg->memory.filename_msw_usage_in_bytes = strdupz(filename);
1175 cg->memory.enabled_msw_usage_in_bytes = cgroup_enable_swap;
1176 debug(D_CGROUP, "memory.msw_usage_in_bytes filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_msw_usage_in_bytes);
1179 debug(D_CGROUP, "memory.msw_usage_in_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1182 if(unlikely(cgroup_enable_memory_failcnt && !cg->memory.filename_failcnt)) {
1183 snprintfz(filename, FILENAME_MAX, "%s%s/memory.failcnt", cgroup_memory_base, cg->id);
1184 if(likely(stat(filename, &buf) != -1)) {
1185 cg->memory.filename_failcnt = strdupz(filename);
1186 cg->memory.enabled_failcnt = cgroup_enable_memory_failcnt;
1187 debug(D_CGROUP, "memory.failcnt filename for cgroup '%s': '%s'", cg->id, cg->memory.filename_failcnt);
1190 debug(D_CGROUP, "memory.failcnt file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1193 if(unlikely(cgroup_enable_blkio_io && !cg->io_service_bytes.filename)) {
1194 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_service_bytes", cgroup_blkio_base, cg->id);
1195 if(likely(stat(filename, &buf) != -1)) {
1196 cg->io_service_bytes.filename = strdupz(filename);
1197 cg->io_service_bytes.enabled = cgroup_enable_blkio_io;
1198 debug(D_CGROUP, "io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->io_service_bytes.filename);
1201 debug(D_CGROUP, "io_service_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1204 if(unlikely(cgroup_enable_blkio_ops && !cg->io_serviced.filename)) {
1205 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_serviced", cgroup_blkio_base, cg->id);
1206 if(likely(stat(filename, &buf) != -1)) {
1207 cg->io_serviced.filename = strdupz(filename);
1208 cg->io_serviced.enabled = cgroup_enable_blkio_ops;
1209 debug(D_CGROUP, "io_serviced filename for cgroup '%s': '%s'", cg->id, cg->io_serviced.filename);
1212 debug(D_CGROUP, "io_serviced file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1215 if(unlikely(cgroup_enable_blkio_throttle_io && !cg->throttle_io_service_bytes.filename)) {
1216 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_service_bytes", cgroup_blkio_base, cg->id);
1217 if(likely(stat(filename, &buf) != -1)) {
1218 cg->throttle_io_service_bytes.filename = strdupz(filename);
1219 cg->throttle_io_service_bytes.enabled = cgroup_enable_blkio_throttle_io;
1220 debug(D_CGROUP, "throttle_io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_service_bytes.filename);
1223 debug(D_CGROUP, "throttle_io_service_bytes file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1226 if(unlikely(cgroup_enable_blkio_throttle_ops && !cg->throttle_io_serviced.filename)) {
1227 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_serviced", cgroup_blkio_base, cg->id);
1228 if(likely(stat(filename, &buf) != -1)) {
1229 cg->throttle_io_serviced.filename = strdupz(filename);
1230 cg->throttle_io_serviced.enabled = cgroup_enable_blkio_throttle_ops;
1231 debug(D_CGROUP, "throttle_io_serviced filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_serviced.filename);
1234 debug(D_CGROUP, "throttle_io_serviced file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1237 if(unlikely(cgroup_enable_blkio_merged_ops && !cg->io_merged.filename)) {
1238 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_merged", cgroup_blkio_base, cg->id);
1239 if(likely(stat(filename, &buf) != -1)) {
1240 cg->io_merged.filename = strdupz(filename);
1241 cg->io_merged.enabled = cgroup_enable_blkio_merged_ops;
1242 debug(D_CGROUP, "io_merged filename for cgroup '%s': '%s'", cg->id, cg->io_merged.filename);
1245 debug(D_CGROUP, "io_merged file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1248 if(unlikely(cgroup_enable_blkio_queued_ops && !cg->io_queued.filename)) {
1249 snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_queued", cgroup_blkio_base, cg->id);
1250 if(likely(stat(filename, &buf) != -1)) {
1251 cg->io_queued.filename = strdupz(filename);
1252 cg->io_queued.enabled = cgroup_enable_blkio_queued_ops;
1253 debug(D_CGROUP, "io_queued filename for cgroup '%s': '%s'", cg->id, cg->io_queued.filename);
1256 debug(D_CGROUP, "io_queued file for cgroup '%s': '%s' does not exist.", cg->id, filename);
1260 debug(D_CGROUP, "done searching for cgroups");
1264 // ----------------------------------------------------------------------------
1267 #define CHART_TITLE_MAX 300
1269 void update_services_charts(int update_every,
1272 int do_mem_detailed,
1278 int do_throttle_ops,
1284 *st_mem_usage = NULL,
1285 *st_mem_failcnt = NULL,
1286 *st_swap_usage = NULL,
1288 *st_mem_detailed_cache = NULL,
1289 *st_mem_detailed_rss = NULL,
1290 *st_mem_detailed_mapped = NULL,
1291 *st_mem_detailed_writeback = NULL,
1292 *st_mem_detailed_pgfault = NULL,
1293 *st_mem_detailed_pgmajfault = NULL,
1294 *st_mem_detailed_pgpgin = NULL,
1295 *st_mem_detailed_pgpgout = NULL,
1298 *st_io_serviced_read = NULL,
1299 *st_throttle_io_read = NULL,
1300 *st_throttle_ops_read = NULL,
1301 *st_queued_ops_read = NULL,
1302 *st_merged_ops_read = NULL,
1304 *st_io_write = NULL,
1305 *st_io_serviced_write = NULL,
1306 *st_throttle_io_write = NULL,
1307 *st_throttle_ops_write = NULL,
1308 *st_queued_ops_write = NULL,
1309 *st_merged_ops_write = NULL;
1311 // create the charts
1313 if(likely(do_cpu)) {
1314 if(unlikely(!st_cpu)) {
1315 char title[CHART_TITLE_MAX + 1];
1317 st_cpu = rrdset_find_bytype_localhost("services", "cpu");
1318 if(likely(!st_cpu)) {
1319 snprintfz(title, CHART_TITLE_MAX, "Systemd Services CPU utilization (%d%% = %d core%s)", (processors * 100), processors, (processors > 1) ? "s" : "");
1320 st_cpu = rrdset_create("services", "cpu", NULL, "cpu", "services.cpu", title, "%", CHART_PRIORITY_SYSTEMD_SERVICES, update_every, RRDSET_TYPE_STACKED);
1324 rrdset_next(st_cpu);
1327 if(likely(do_mem_usage)) {
1328 if(unlikely(!st_mem_usage)) {
1329 st_mem_usage = rrdset_find_bytype_localhost("services", "mem_usage");
1330 if(likely(!st_mem_usage))
1331 st_mem_usage = rrdset_create("services", "mem_usage", NULL, "mem", "services.mem_usage", (cgroup_used_memory_without_cache)?"Systemd Services Used Memory without Cache":"Systemd Services Used Memory", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 10, update_every, RRDSET_TYPE_STACKED);
1334 rrdset_next(st_mem_usage);
1337 if(likely(do_mem_detailed)) {
1338 if(unlikely(!st_mem_detailed_rss)) {
1339 st_mem_detailed_rss = rrdset_find_bytype_localhost("services", "mem_rss");
1340 if(likely(!st_mem_detailed_rss))
1341 st_mem_detailed_rss = rrdset_create("services", "mem_rss", NULL, "mem", "services.mem_rss", "Systemd Services RSS Memory", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 20, update_every, RRDSET_TYPE_STACKED);
1344 rrdset_next(st_mem_detailed_rss);
1346 if(unlikely(!st_mem_detailed_mapped)) {
1347 st_mem_detailed_mapped = rrdset_find_bytype_localhost("services", "mem_mapped");
1348 if(likely(!st_mem_detailed_mapped))
1349 st_mem_detailed_mapped = rrdset_create("services", "mem_mapped", NULL, "mem", "services.mem_mapped", "Systemd Services Mapped Memory", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 30, update_every, RRDSET_TYPE_STACKED);
1352 rrdset_next(st_mem_detailed_mapped);
1354 if(unlikely(!st_mem_detailed_cache)) {
1355 st_mem_detailed_cache = rrdset_find_bytype_localhost("services", "mem_cache");
1356 if(likely(!st_mem_detailed_cache))
1357 st_mem_detailed_cache = rrdset_create("services", "mem_cache", NULL, "mem", "services.mem_cache", "Systemd Services Cache Memory", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 40, update_every, RRDSET_TYPE_STACKED);
1360 rrdset_next(st_mem_detailed_cache);
1362 if(unlikely(!st_mem_detailed_writeback)) {
1363 st_mem_detailed_writeback = rrdset_find_bytype_localhost("services", "mem_writeback");
1364 if(likely(!st_mem_detailed_writeback))
1365 st_mem_detailed_writeback = rrdset_create("services", "mem_writeback", NULL, "mem", "services.mem_writeback", "Systemd Services Writeback Memory", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 50, update_every, RRDSET_TYPE_STACKED);
1368 rrdset_next(st_mem_detailed_writeback);
1370 if(unlikely(!st_mem_detailed_pgfault)) {
1371 st_mem_detailed_pgfault = rrdset_find_bytype_localhost("services", "mem_pgfault");
1372 if(likely(!st_mem_detailed_pgfault))
1373 st_mem_detailed_pgfault = rrdset_create("services", "mem_pgfault", NULL, "mem", "services.mem_pgfault", "Systemd Services Memory Minor Page Faults", "MB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 60, update_every, RRDSET_TYPE_STACKED);
1376 rrdset_next(st_mem_detailed_pgfault);
1378 if(unlikely(!st_mem_detailed_pgmajfault)) {
1379 st_mem_detailed_pgmajfault = rrdset_find_bytype_localhost("services", "mem_pgmajfault");
1380 if(likely(!st_mem_detailed_pgmajfault))
1381 st_mem_detailed_pgmajfault = rrdset_create("services", "mem_pgmajfault", NULL, "mem", "services.mem_pgmajfault", "Systemd Services Memory Major Page Faults", "MB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 70, update_every, RRDSET_TYPE_STACKED);
1384 rrdset_next(st_mem_detailed_pgmajfault);
1386 if(unlikely(!st_mem_detailed_pgpgin)) {
1387 st_mem_detailed_pgpgin = rrdset_find_bytype_localhost("services", "mem_pgpgin");
1388 if(likely(!st_mem_detailed_pgpgin))
1389 st_mem_detailed_pgpgin = rrdset_create("services", "mem_pgpgin", NULL, "mem", "services.mem_pgpgin", "Systemd Services Memory Charging Activity", "MB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 80, update_every, RRDSET_TYPE_STACKED);
1392 rrdset_next(st_mem_detailed_pgpgin);
1394 if(unlikely(!st_mem_detailed_pgpgout)) {
1395 st_mem_detailed_pgpgout = rrdset_find_bytype_localhost("services", "mem_pgpgout");
1396 if(likely(!st_mem_detailed_pgpgout))
1397 st_mem_detailed_pgpgout = rrdset_create("services", "mem_pgpgout", NULL, "mem", "services.mem_pgpgout", "Systemd Services Memory Uncharging Activity", "MB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 90, update_every, RRDSET_TYPE_STACKED);
1400 rrdset_next(st_mem_detailed_pgpgout);
1403 if(likely(do_mem_failcnt)) {
1404 if(unlikely(!st_mem_failcnt)) {
1405 st_mem_failcnt = rrdset_find_bytype_localhost("services", "mem_failcnt");
1406 if(likely(!st_mem_failcnt))
1407 st_mem_failcnt = rrdset_create("services", "mem_failcnt", NULL, "mem", "services.mem_failcnt", "Systemd Services Memory Limit Failures", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 110, update_every, RRDSET_TYPE_STACKED);
1410 rrdset_next(st_mem_failcnt);
1413 if(likely(do_swap_usage)) {
1414 if(unlikely(!st_swap_usage)) {
1415 st_swap_usage = rrdset_find_bytype_localhost("services", "swap_usage");
1416 if(likely(!st_swap_usage))
1417 st_swap_usage = rrdset_create("services", "swap_usage", NULL, "swap", "services.swap_usage", "Systemd Services Swap Memory Used", "MB", CHART_PRIORITY_SYSTEMD_SERVICES + 100, update_every, RRDSET_TYPE_STACKED);
1420 rrdset_next(st_swap_usage);
1424 if(unlikely(!st_io_read)) {
1425 st_io_read = rrdset_find_bytype_localhost("services", "io_read");
1426 if(likely(!st_io_read))
1427 st_io_read = rrdset_create("services", "io_read", NULL, "disk", "services.io_read", "Systemd Services Disk Read Bandwidth", "KB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 120, update_every, RRDSET_TYPE_STACKED);
1430 rrdset_next(st_io_read);
1432 if(unlikely(!st_io_write)) {
1433 st_io_write = rrdset_find_bytype_localhost("services", "io_write");
1434 if(likely(!st_io_write))
1435 st_io_write = rrdset_create("services", "io_write", NULL, "disk", "services.io_write", "Systemd Services Disk Write Bandwidth", "KB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 130, update_every, RRDSET_TYPE_STACKED);
1438 rrdset_next(st_io_write);
1441 if(likely(do_io_ops)) {
1442 if(unlikely(!st_io_serviced_read)) {
1443 st_io_serviced_read = rrdset_find_bytype_localhost("services", "io_ops_read");
1444 if(likely(!st_io_serviced_read))
1445 st_io_serviced_read = rrdset_create("services", "io_ops_read", NULL, "disk", "services.io_ops_read", "Systemd Services Disk Read Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 140, update_every, RRDSET_TYPE_STACKED);
1448 rrdset_next(st_io_serviced_read);
1450 if(unlikely(!st_io_serviced_write)) {
1451 st_io_serviced_write = rrdset_find_bytype_localhost("services", "io_ops_write");
1452 if(likely(!st_io_serviced_write))
1453 st_io_serviced_write = rrdset_create("services", "io_ops_write", NULL, "disk", "services.io_ops_write", "Systemd Services Disk Write Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 150, update_every, RRDSET_TYPE_STACKED);
1456 rrdset_next(st_io_serviced_write);
1459 if(likely(do_throttle_io)) {
1460 if(unlikely(!st_throttle_io_read)) {
1461 st_throttle_io_read = rrdset_find_bytype_localhost("services", "throttle_io_read");
1462 if(likely(!st_throttle_io_read))
1463 st_throttle_io_read = rrdset_create("services", "throttle_io_read", NULL, "disk", "services.throttle_io_read", "Systemd Services Throttle Disk Read Bandwidth", "KB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 160, update_every, RRDSET_TYPE_STACKED);
1466 rrdset_next(st_throttle_io_read);
1468 if(unlikely(!st_throttle_io_write)) {
1469 st_throttle_io_write = rrdset_find_bytype_localhost("services", "throttle_io_write");
1470 if(likely(!st_throttle_io_write))
1471 st_throttle_io_write = rrdset_create("services", "throttle_io_write", NULL, "disk", "services.throttle_io_write", "Systemd Services Throttle Disk Write Bandwidth", "KB/s", CHART_PRIORITY_SYSTEMD_SERVICES + 170, update_every, RRDSET_TYPE_STACKED);
1474 rrdset_next(st_throttle_io_write);
1477 if(likely(do_throttle_ops)) {
1478 if(unlikely(!st_throttle_ops_read)) {
1479 st_throttle_ops_read = rrdset_find_bytype_localhost("services", "throttle_io_ops_read");
1480 if(likely(!st_throttle_ops_read))
1481 st_throttle_ops_read = rrdset_create("services", "throttle_io_ops_read", NULL, "disk", "services.throttle_io_ops_read", "Systemd Services Throttle Disk Read Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 180, update_every, RRDSET_TYPE_STACKED);
1484 rrdset_next(st_throttle_ops_read);
1486 if(unlikely(!st_throttle_ops_write)) {
1487 st_throttle_ops_write = rrdset_find_bytype_localhost("services", "throttle_io_ops_write");
1488 if(likely(!st_throttle_ops_write))
1489 st_throttle_ops_write = rrdset_create("services", "throttle_io_ops_write", NULL, "disk", "services.throttle_io_ops_write", "Systemd Services Throttle Disk Write Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 190, update_every, RRDSET_TYPE_STACKED);
1492 rrdset_next(st_throttle_ops_write);
1495 if(likely(do_queued_ops)) {
1496 if(unlikely(!st_queued_ops_read)) {
1497 st_queued_ops_read = rrdset_find_bytype_localhost("services", "queued_io_ops_read");
1498 if(likely(!st_queued_ops_read))
1499 st_queued_ops_read = rrdset_create("services", "queued_io_ops_read", NULL, "disk", "services.queued_io_ops_read", "Systemd Services Queued Disk Read Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 200, update_every, RRDSET_TYPE_STACKED);
1502 rrdset_next(st_queued_ops_read);
1504 if(unlikely(!st_queued_ops_write)) {
1505 st_queued_ops_write = rrdset_find_bytype_localhost("services", "queued_io_ops_write");
1506 if(likely(!st_queued_ops_write))
1507 st_queued_ops_write = rrdset_create("services", "queued_io_ops_write", NULL, "disk", "services.queued_io_ops_write", "Systemd Services Queued Disk Write Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 210, update_every, RRDSET_TYPE_STACKED);
1510 rrdset_next(st_queued_ops_write);
1513 if(likely(do_merged_ops)) {
1514 if(unlikely(!st_merged_ops_read)) {
1515 st_merged_ops_read = rrdset_find_bytype_localhost("services", "merged_io_ops_read");
1516 if(likely(!st_merged_ops_read))
1517 st_merged_ops_read = rrdset_create("services", "merged_io_ops_read", NULL, "disk", "services.merged_io_ops_read", "Systemd Services Merged Disk Read Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 220, update_every, RRDSET_TYPE_STACKED);
1520 rrdset_next(st_merged_ops_read);
1522 if(unlikely(!st_merged_ops_write)) {
1523 st_merged_ops_write = rrdset_find_bytype_localhost("services", "merged_io_ops_write");
1524 if(likely(!st_merged_ops_write))
1525 st_merged_ops_write = rrdset_create("services", "merged_io_ops_write", NULL, "disk", "services.merged_io_ops_write", "Systemd Services Merged Disk Write Operations", "operations/s", CHART_PRIORITY_SYSTEMD_SERVICES + 230, update_every, RRDSET_TYPE_STACKED);
1528 rrdset_next(st_merged_ops_write);
1531 // update the values
1533 for(cg = cgroup_root; cg ; cg = cg->next) {
1534 if(unlikely(!cg->available || !cg->enabled || !(cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE)))
1537 if(likely(do_cpu && cg->cpuacct_stat.updated)) {
1538 if(unlikely(!cg->rd_cpu))
1539 cg->rd_cpu = rrddim_add(st_cpu, cg->chart_id, cg->chart_title, 100, hz, RRDDIM_ALGORITHM_INCREMENTAL);
1541 rrddim_set_by_pointer(st_cpu, cg->rd_cpu, cg->cpuacct_stat.user + cg->cpuacct_stat.system);
1544 if(likely(do_mem_usage && cg->memory.updated_usage_in_bytes)) {
1545 if(unlikely(!cg->rd_mem_usage))
1546 cg->rd_mem_usage = rrddim_add(st_mem_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1548 rrddim_set_by_pointer(st_mem_usage, cg->rd_mem_usage, cg->memory.usage_in_bytes - ((cgroup_used_memory_without_cache)?cg->memory.cache:0));
1551 if(likely(do_mem_detailed && cg->memory.updated_detailed)) {
1552 if(unlikely(!cg->rd_mem_detailed_rss))
1553 cg->rd_mem_detailed_rss = rrddim_add(st_mem_detailed_rss, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1554 rrddim_set_by_pointer(st_mem_detailed_rss, cg->rd_mem_detailed_rss, cg->memory.rss + cg->memory.rss_huge);
1556 if(unlikely(!cg->rd_mem_detailed_mapped))
1557 cg->rd_mem_detailed_mapped = rrddim_add(st_mem_detailed_mapped, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1558 rrddim_set_by_pointer(st_mem_detailed_mapped, cg->rd_mem_detailed_mapped, cg->memory.mapped_file);
1560 if(unlikely(!cg->rd_mem_detailed_cache))
1561 cg->rd_mem_detailed_cache = rrddim_add(st_mem_detailed_cache, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1562 rrddim_set_by_pointer(st_mem_detailed_cache, cg->rd_mem_detailed_cache, cg->memory.cache);
1564 if(unlikely(!cg->rd_mem_detailed_writeback))
1565 cg->rd_mem_detailed_writeback = rrddim_add(st_mem_detailed_writeback, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1566 rrddim_set_by_pointer(st_mem_detailed_writeback, cg->rd_mem_detailed_writeback, cg->memory.writeback);
1568 if(unlikely(!cg->rd_mem_detailed_pgfault))
1569 cg->rd_mem_detailed_pgfault = rrddim_add(st_mem_detailed_pgfault, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1570 rrddim_set_by_pointer(st_mem_detailed_pgfault, cg->rd_mem_detailed_pgfault, cg->memory.pgfault);
1572 if(unlikely(!cg->rd_mem_detailed_pgmajfault))
1573 cg->rd_mem_detailed_pgmajfault = rrddim_add(st_mem_detailed_pgmajfault, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1574 rrddim_set_by_pointer(st_mem_detailed_pgmajfault, cg->rd_mem_detailed_pgmajfault, cg->memory.pgmajfault);
1576 if(unlikely(!cg->rd_mem_detailed_pgpgin))
1577 cg->rd_mem_detailed_pgpgin = rrddim_add(st_mem_detailed_pgpgin, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1578 rrddim_set_by_pointer(st_mem_detailed_pgpgin, cg->rd_mem_detailed_pgpgin, cg->memory.pgpgin);
1580 if(unlikely(!cg->rd_mem_detailed_pgpgout))
1581 cg->rd_mem_detailed_pgpgout = rrddim_add(st_mem_detailed_pgpgout, cg->chart_id, cg->chart_title, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1582 rrddim_set_by_pointer(st_mem_detailed_pgpgout, cg->rd_mem_detailed_pgpgout, cg->memory.pgpgout);
1585 if(likely(do_mem_failcnt && cg->memory.updated_failcnt)) {
1586 if(unlikely(!cg->rd_mem_failcnt))
1587 cg->rd_mem_failcnt = rrddim_add(st_mem_failcnt, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1589 rrddim_set_by_pointer(st_mem_failcnt, cg->rd_mem_failcnt, cg->memory.failcnt);
1592 if(likely(do_swap_usage && cg->memory.updated_msw_usage_in_bytes)) {
1593 if(unlikely(!cg->rd_swap_usage))
1594 cg->rd_swap_usage = rrddim_add(st_swap_usage, cg->chart_id, cg->chart_title, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1596 rrddim_set_by_pointer(st_swap_usage, cg->rd_swap_usage, cg->memory.msw_usage_in_bytes);
1599 if(likely(do_io && cg->io_service_bytes.updated)) {
1600 if(unlikely(!cg->rd_io_service_bytes_read))
1601 cg->rd_io_service_bytes_read = rrddim_add(st_io_read, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1603 rrddim_set_by_pointer(st_io_read, cg->rd_io_service_bytes_read, cg->io_service_bytes.Read);
1605 if(unlikely(!cg->rd_io_service_bytes_write))
1606 cg->rd_io_service_bytes_write = rrddim_add(st_io_write, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1608 rrddim_set_by_pointer(st_io_write, cg->rd_io_service_bytes_write, cg->io_service_bytes.Write);
1611 if(likely(do_io_ops && cg->io_serviced.updated)) {
1612 if(unlikely(!cg->rd_io_serviced_read))
1613 cg->rd_io_serviced_read = rrddim_add(st_io_serviced_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1615 rrddim_set_by_pointer(st_io_serviced_read, cg->rd_io_serviced_read, cg->io_serviced.Read);
1617 if(unlikely(!cg->rd_io_serviced_write))
1618 cg->rd_io_serviced_write = rrddim_add(st_io_serviced_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1620 rrddim_set_by_pointer(st_io_serviced_write, cg->rd_io_serviced_write, cg->io_serviced.Write);
1623 if(likely(do_throttle_io && cg->throttle_io_service_bytes.updated)) {
1624 if(unlikely(!cg->rd_throttle_io_read))
1625 cg->rd_throttle_io_read = rrddim_add(st_throttle_io_read, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1627 rrddim_set_by_pointer(st_throttle_io_read, cg->rd_throttle_io_read, cg->throttle_io_service_bytes.Read);
1629 if(unlikely(!cg->rd_throttle_io_write))
1630 cg->rd_throttle_io_write = rrddim_add(st_throttle_io_write, cg->chart_id, cg->chart_title, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1632 rrddim_set_by_pointer(st_throttle_io_write, cg->rd_throttle_io_write, cg->throttle_io_service_bytes.Write);
1635 if(likely(do_throttle_ops && cg->throttle_io_serviced.updated)) {
1636 if(unlikely(!cg->rd_throttle_io_serviced_read))
1637 cg->rd_throttle_io_serviced_read = rrddim_add(st_throttle_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1639 rrddim_set_by_pointer(st_throttle_ops_read, cg->rd_throttle_io_serviced_read, cg->throttle_io_serviced.Read);
1641 if(unlikely(!cg->rd_throttle_io_serviced_write))
1642 cg->rd_throttle_io_serviced_write = rrddim_add(st_throttle_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1644 rrddim_set_by_pointer(st_throttle_ops_write, cg->rd_throttle_io_serviced_write, cg->throttle_io_serviced.Write);
1647 if(likely(do_queued_ops && cg->io_queued.updated)) {
1648 if(unlikely(!cg->rd_io_queued_read))
1649 cg->rd_io_queued_read = rrddim_add(st_queued_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1651 rrddim_set_by_pointer(st_queued_ops_read, cg->rd_io_queued_read, cg->io_queued.Read);
1653 if(unlikely(!cg->rd_io_queued_write))
1654 cg->rd_io_queued_write = rrddim_add(st_queued_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1656 rrddim_set_by_pointer(st_queued_ops_write, cg->rd_io_queued_write, cg->io_queued.Write);
1659 if(likely(do_merged_ops && cg->io_merged.updated)) {
1660 if(unlikely(!cg->rd_io_merged_read))
1661 cg->rd_io_merged_read = rrddim_add(st_merged_ops_read, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1663 rrddim_set_by_pointer(st_merged_ops_read, cg->rd_io_merged_read, cg->io_merged.Read);
1665 if(unlikely(!cg->rd_io_merged_write))
1666 cg->rd_io_merged_write = rrddim_add(st_merged_ops_write, cg->chart_id, cg->chart_title, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1668 rrddim_set_by_pointer(st_merged_ops_write, cg->rd_io_merged_write, cg->io_merged.Write);
1672 // complete the iteration
1674 rrdset_done(st_cpu);
1676 if(likely(do_mem_usage))
1677 rrdset_done(st_mem_usage);
1679 if(unlikely(do_mem_detailed)) {
1680 rrdset_done(st_mem_detailed_cache);
1681 rrdset_done(st_mem_detailed_rss);
1682 rrdset_done(st_mem_detailed_mapped);
1683 rrdset_done(st_mem_detailed_writeback);
1684 rrdset_done(st_mem_detailed_pgfault);
1685 rrdset_done(st_mem_detailed_pgmajfault);
1686 rrdset_done(st_mem_detailed_pgpgin);
1687 rrdset_done(st_mem_detailed_pgpgout);
1690 if(likely(do_mem_failcnt))
1691 rrdset_done(st_mem_failcnt);
1693 if(likely(do_swap_usage))
1694 rrdset_done(st_swap_usage);
1697 rrdset_done(st_io_read);
1698 rrdset_done(st_io_write);
1701 if(likely(do_io_ops)) {
1702 rrdset_done(st_io_serviced_read);
1703 rrdset_done(st_io_serviced_write);
1706 if(likely(do_throttle_io)) {
1707 rrdset_done(st_throttle_io_read);
1708 rrdset_done(st_throttle_io_write);
1711 if(likely(do_throttle_ops)) {
1712 rrdset_done(st_throttle_ops_read);
1713 rrdset_done(st_throttle_ops_write);
1716 if(likely(do_queued_ops)) {
1717 rrdset_done(st_queued_ops_read);
1718 rrdset_done(st_queued_ops_write);
1721 if(likely(do_merged_ops)) {
1722 rrdset_done(st_merged_ops_read);
1723 rrdset_done(st_merged_ops_write);
1727 static inline char *cgroup_chart_type(char *buffer, const char *id, size_t len) {
1728 if(buffer[0]) return buffer;
1730 if(id[0] == '\0' || (id[0] == '/' && id[1] == '\0'))
1731 strncpy(buffer, "cgroup_root", len);
1733 snprintfz(buffer, len, "cgroup_%s", id);
1735 netdata_fix_chart_id(buffer);
1739 void update_cgroup_charts(int update_every) {
1740 debug(D_CGROUP, "updating cgroups charts");
1742 char type[RRD_ID_LENGTH_MAX + 1];
1743 char title[CHART_TITLE_MAX + 1];
1745 int services_do_cpu = 0,
1746 services_do_mem_usage = 0,
1747 services_do_mem_detailed = 0,
1748 services_do_mem_failcnt = 0,
1749 services_do_swap_usage = 0,
1751 services_do_io_ops = 0,
1752 services_do_throttle_io = 0,
1753 services_do_throttle_ops = 0,
1754 services_do_queued_ops = 0,
1755 services_do_merged_ops = 0;
1758 for(cg = cgroup_root; cg ; cg = cg->next) {
1759 if(unlikely(!cg->available || !cg->enabled))
1762 if(likely(cgroup_enable_systemd_services && cg->options & CGROUP_OPTIONS_SYSTEM_SLICE_SERVICE)) {
1763 if(cg->cpuacct_stat.updated && cg->cpuacct_stat.enabled == CONFIG_ONDEMAND_YES) services_do_cpu++;
1765 if(cgroup_enable_systemd_services_detailed_memory && cg->memory.updated_detailed && cg->memory.enabled_detailed) services_do_mem_detailed++;
1766 if(cg->memory.updated_usage_in_bytes && cg->memory.enabled_usage_in_bytes == CONFIG_ONDEMAND_YES) services_do_mem_usage++;
1767 if(cg->memory.updated_failcnt && cg->memory.enabled_failcnt == CONFIG_ONDEMAND_YES) services_do_mem_failcnt++;
1768 if(cg->memory.updated_msw_usage_in_bytes && cg->memory.enabled_msw_usage_in_bytes == CONFIG_ONDEMAND_YES) services_do_swap_usage++;
1770 if(cg->io_service_bytes.updated && cg->io_service_bytes.enabled == CONFIG_ONDEMAND_YES) services_do_io++;
1771 if(cg->io_serviced.updated && cg->io_serviced.enabled == CONFIG_ONDEMAND_YES) services_do_io_ops++;
1772 if(cg->throttle_io_service_bytes.updated && cg->throttle_io_service_bytes.enabled == CONFIG_ONDEMAND_YES) services_do_throttle_io++;
1773 if(cg->throttle_io_serviced.updated && cg->throttle_io_serviced.enabled == CONFIG_ONDEMAND_YES) services_do_throttle_ops++;
1774 if(cg->io_queued.updated && cg->io_queued.enabled == CONFIG_ONDEMAND_YES) services_do_queued_ops++;
1775 if(cg->io_merged.updated && cg->io_merged.enabled == CONFIG_ONDEMAND_YES) services_do_merged_ops++;
1781 if(likely(cg->cpuacct_stat.updated && cg->cpuacct_stat.enabled == CONFIG_ONDEMAND_YES)) {
1782 if(unlikely(!cg->st_cpu)) {
1783 cg->st_cpu = rrdset_find_bytype_localhost(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX)
1785 if(likely(!cg->st_cpu)) {
1786 snprintfz(title, CHART_TITLE_MAX, "CPU Usage (%d%% = %d core%s) for cgroup %s", (processors * 100), processors, (processors > 1) ? "s" : "", cg->chart_title);
1787 cg->st_cpu = rrdset_create(type, "cpu", NULL, "cpu", "cgroup.cpu", title, "%", CHART_PRIORITY_CONTAINERS, update_every, RRDSET_TYPE_STACKED);
1789 rrddim_add(cg->st_cpu, "user", NULL, 100, hz, RRDDIM_ALGORITHM_INCREMENTAL);
1790 rrddim_add(cg->st_cpu, "system", NULL, 100, hz, RRDDIM_ALGORITHM_INCREMENTAL);
1793 rrdset_next(cg->st_cpu);
1795 rrddim_set(cg->st_cpu, "user", cg->cpuacct_stat.user);
1796 rrddim_set(cg->st_cpu, "system", cg->cpuacct_stat.system);
1797 rrdset_done(cg->st_cpu);
1800 if(likely(cg->cpuacct_usage.updated && cg->cpuacct_usage.enabled == CONFIG_ONDEMAND_YES)) {
1801 char id[RRD_ID_LENGTH_MAX + 1];
1804 if(unlikely(!cg->st_cpu_per_core)) {
1805 cg->st_cpu_per_core = rrdset_find_bytype_localhost(
1806 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "cpu_per_core");
1807 if(likely(!cg->st_cpu_per_core)) {
1808 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);
1809 cg->st_cpu_per_core = rrdset_create(type, "cpu_per_core", NULL, "cpu", "cgroup.cpu_per_core", title, "%", CHART_PRIORITY_CONTAINERS + 100, update_every, RRDSET_TYPE_STACKED);
1811 for(i = 0; i < cg->cpuacct_usage.cpus; i++) {
1812 snprintfz(id, CHART_TITLE_MAX, "cpu%u", i);
1813 rrddim_add(cg->st_cpu_per_core, id, NULL, 100, 1000000000, RRDDIM_ALGORITHM_INCREMENTAL);
1817 rrdset_next(cg->st_cpu_per_core);
1819 for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
1820 snprintfz(id, CHART_TITLE_MAX, "cpu%u", i);
1821 rrddim_set(cg->st_cpu_per_core, id, cg->cpuacct_usage.cpu_percpu[i]);
1823 rrdset_done(cg->st_cpu_per_core);
1826 if(likely(cg->memory.updated_detailed && cg->memory.enabled_detailed == CONFIG_ONDEMAND_YES)) {
1827 if(unlikely(!cg->st_mem)) {
1828 cg->st_mem = rrdset_find_bytype_localhost(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX)
1830 if(likely(!cg->st_mem)) {
1831 snprintfz(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_title);
1832 cg->st_mem = rrdset_create(type, "mem", NULL, "mem", "cgroup.mem", title, "MB", CHART_PRIORITY_CONTAINERS + 210, update_every, RRDSET_TYPE_STACKED);
1835 rrddim_add(cg->st_mem, "cache", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1836 rrddim_add(cg->st_mem, "rss", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1837 if(cg->memory.detailed_has_swap)
1838 rrddim_add(cg->st_mem, "swap", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1839 rrddim_add(cg->st_mem, "rss_huge", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1840 rrddim_add(cg->st_mem, "mapped_file", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1843 rrdset_next(cg->st_mem);
1845 rrddim_set(cg->st_mem, "cache", cg->memory.cache);
1846 rrddim_set(cg->st_mem, "rss", cg->memory.rss);
1847 if(cg->memory.detailed_has_swap)
1848 rrddim_set(cg->st_mem, "swap", cg->memory.swap);
1849 rrddim_set(cg->st_mem, "rss_huge", cg->memory.rss_huge);
1850 rrddim_set(cg->st_mem, "mapped_file", cg->memory.mapped_file);
1851 rrdset_done(cg->st_mem);
1853 if(unlikely(!cg->st_writeback)) {
1854 cg->st_writeback = rrdset_find_bytype_localhost(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX)
1856 if(likely(!cg->st_writeback)) {
1857 snprintfz(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_title);
1858 cg->st_writeback = rrdset_create(type, "writeback", NULL, "mem", "cgroup.writeback", title, "MB", CHART_PRIORITY_CONTAINERS + 300, update_every, RRDSET_TYPE_AREA);
1861 if(cg->memory.detailed_has_dirty)
1862 rrddim_add(cg->st_writeback, "dirty", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1863 rrddim_add(cg->st_writeback, "writeback", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1866 rrdset_next(cg->st_writeback);
1868 if(cg->memory.detailed_has_dirty)
1869 rrddim_set(cg->st_writeback, "dirty", cg->memory.dirty);
1870 rrddim_set(cg->st_writeback, "writeback", cg->memory.writeback);
1871 rrdset_done(cg->st_writeback);
1873 if(unlikely(!cg->st_mem_activity)) {
1874 cg->st_mem_activity = rrdset_find_bytype_localhost(
1875 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "mem_activity");
1876 if(likely(!cg->st_mem_activity)) {
1877 snprintfz(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_title);
1878 cg->st_mem_activity = rrdset_create(type, "mem_activity", NULL, "mem", "cgroup.mem_activity", title, "MB/s", CHART_PRIORITY_CONTAINERS + 400, update_every, RRDSET_TYPE_LINE);
1880 rrddim_add(cg->st_mem_activity, "pgpgin", "in", system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1881 rrddim_add(cg->st_mem_activity, "pgpgout", "out", -system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1884 rrdset_next(cg->st_mem_activity);
1886 rrddim_set(cg->st_mem_activity, "pgpgin", cg->memory.pgpgin);
1887 rrddim_set(cg->st_mem_activity, "pgpgout", cg->memory.pgpgout);
1888 rrdset_done(cg->st_mem_activity);
1890 if(unlikely(!cg->st_pgfaults)) {
1891 cg->st_pgfaults = rrdset_find_bytype_localhost(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX)
1893 if(likely(!cg->st_pgfaults)) {
1894 snprintfz(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_title);
1895 cg->st_pgfaults = rrdset_create(type, "pgfaults", NULL, "mem", "cgroup.pgfaults", title, "MB/s", CHART_PRIORITY_CONTAINERS + 500, update_every, RRDSET_TYPE_LINE);
1897 rrddim_add(cg->st_pgfaults, "pgfault", NULL, system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1898 rrddim_add(cg->st_pgfaults, "pgmajfault", "swap", -system_page_size, 1024 * 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1901 rrdset_next(cg->st_pgfaults);
1903 rrddim_set(cg->st_pgfaults, "pgfault", cg->memory.pgfault);
1904 rrddim_set(cg->st_pgfaults, "pgmajfault", cg->memory.pgmajfault);
1905 rrdset_done(cg->st_pgfaults);
1908 if(likely(cg->memory.updated_usage_in_bytes && cg->memory.enabled_usage_in_bytes == CONFIG_ONDEMAND_YES)) {
1909 if(unlikely(!cg->st_mem_usage)) {
1910 cg->st_mem_usage = rrdset_find_bytype_localhost(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX)
1912 if(likely(!cg->st_mem_usage)) {
1913 snprintfz(title, CHART_TITLE_MAX, "Used Memory %sfor cgroup %s", (cgroup_used_memory_without_cache && cg->memory.updated_detailed)?"without Cache ":"", cg->chart_title);
1914 cg->st_mem_usage = rrdset_create(type, "mem_usage", NULL, "mem", "cgroup.mem_usage", title, "MB", CHART_PRIORITY_CONTAINERS + 200, update_every, RRDSET_TYPE_STACKED);
1916 rrddim_add(cg->st_mem_usage, "ram", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1917 rrddim_add(cg->st_mem_usage, "swap", NULL, 1, 1024 * 1024, RRDDIM_ALGORITHM_ABSOLUTE);
1920 rrdset_next(cg->st_mem_usage);
1922 rrddim_set(cg->st_mem_usage, "ram", cg->memory.usage_in_bytes - ((cgroup_used_memory_without_cache)?cg->memory.cache:0));
1923 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);
1924 rrdset_done(cg->st_mem_usage);
1927 if(likely(cg->memory.updated_failcnt && cg->memory.enabled_failcnt == CONFIG_ONDEMAND_YES)) {
1928 if(unlikely(!cg->st_mem_failcnt)) {
1929 cg->st_mem_failcnt = rrdset_find_bytype_localhost(
1930 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "mem_failcnt");
1931 if(likely(!cg->st_mem_failcnt)) {
1932 snprintfz(title, CHART_TITLE_MAX, "Memory Limit Failures for cgroup %s", cg->chart_title);
1933 cg->st_mem_failcnt = rrdset_create(type, "mem_failcnt", NULL, "mem", "cgroup.mem_failcnt", title, "count", CHART_PRIORITY_CONTAINERS + 250, update_every, RRDSET_TYPE_LINE);
1935 rrddim_add(cg->st_mem_failcnt, "failures", NULL, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1938 rrdset_next(cg->st_mem_failcnt);
1940 rrddim_set(cg->st_mem_failcnt, "failures", cg->memory.failcnt);
1941 rrdset_done(cg->st_mem_failcnt);
1944 if(likely(cg->io_service_bytes.updated && cg->io_service_bytes.enabled == CONFIG_ONDEMAND_YES)) {
1945 if(unlikely(!cg->st_io)) {
1946 cg->st_io = rrdset_find_bytype_localhost(cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "io");
1947 if(likely(!cg->st_io)) {
1948 snprintfz(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1949 cg->st_io = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_AREA);
1951 rrddim_add(cg->st_io, "read", NULL, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1952 rrddim_add(cg->st_io, "write", NULL, -1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1955 rrdset_next(cg->st_io);
1957 rrddim_set(cg->st_io, "read", cg->io_service_bytes.Read);
1958 rrddim_set(cg->st_io, "write", cg->io_service_bytes.Write);
1959 rrdset_done(cg->st_io);
1962 if(likely(cg->io_serviced.updated && cg->io_serviced.enabled == CONFIG_ONDEMAND_YES)) {
1963 if(unlikely(!cg->st_serviced_ops)) {
1964 cg->st_serviced_ops = rrdset_find_bytype_localhost(
1965 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "serviced_ops");
1966 if(likely(!cg->st_serviced_ops)) {
1967 snprintfz(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1968 cg->st_serviced_ops = rrdset_create(type, "serviced_ops", NULL, "disk", "cgroup.serviced_ops", title, "operations/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_LINE);
1970 rrddim_add(cg->st_serviced_ops, "read", NULL, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1971 rrddim_add(cg->st_serviced_ops, "write", NULL, -1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
1974 rrdset_next(cg->st_serviced_ops);
1976 rrddim_set(cg->st_serviced_ops, "read", cg->io_serviced.Read);
1977 rrddim_set(cg->st_serviced_ops, "write", cg->io_serviced.Write);
1978 rrdset_done(cg->st_serviced_ops);
1981 if(likely(cg->throttle_io_service_bytes.updated && cg->throttle_io_service_bytes.enabled == CONFIG_ONDEMAND_YES)) {
1982 if(unlikely(!cg->st_throttle_io)) {
1983 cg->st_throttle_io = rrdset_find_bytype_localhost(
1984 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "throttle_io");
1985 if(likely(!cg->st_throttle_io)) {
1986 snprintfz(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1987 cg->st_throttle_io = rrdset_create(type, "throttle_io", NULL, "disk", "cgroup.throttle_io", title, "KB/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_AREA);
1989 rrddim_add(cg->st_throttle_io, "read", NULL, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1990 rrddim_add(cg->st_throttle_io, "write", NULL, -1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
1993 rrdset_next(cg->st_throttle_io);
1995 rrddim_set(cg->st_throttle_io, "read", cg->throttle_io_service_bytes.Read);
1996 rrddim_set(cg->st_throttle_io, "write", cg->throttle_io_service_bytes.Write);
1997 rrdset_done(cg->st_throttle_io);
2000 if(likely(cg->throttle_io_serviced.updated && cg->throttle_io_serviced.enabled == CONFIG_ONDEMAND_YES)) {
2001 if(unlikely(!cg->st_throttle_serviced_ops)) {
2002 cg->st_throttle_serviced_ops = rrdset_find_bytype_localhost(
2003 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "throttle_serviced_ops");
2004 if(likely(!cg->st_throttle_serviced_ops)) {
2005 snprintfz(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
2006 cg->st_throttle_serviced_ops = rrdset_create(type, "throttle_serviced_ops", NULL, "disk", "cgroup.throttle_serviced_ops", title, "operations/s", CHART_PRIORITY_CONTAINERS + 1200, update_every, RRDSET_TYPE_LINE);
2008 rrddim_add(cg->st_throttle_serviced_ops, "read", NULL, 1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
2009 rrddim_add(cg->st_throttle_serviced_ops, "write", NULL, -1, 1, RRDDIM_ALGORITHM_INCREMENTAL);
2012 rrdset_next(cg->st_throttle_serviced_ops);
2014 rrddim_set(cg->st_throttle_serviced_ops, "read", cg->throttle_io_serviced.Read);
2015 rrddim_set(cg->st_throttle_serviced_ops, "write", cg->throttle_io_serviced.Write);
2016 rrdset_done(cg->st_throttle_serviced_ops);
2019 if(likely(cg->io_queued.updated && cg->io_queued.enabled == CONFIG_ONDEMAND_YES)) {
2020 if(unlikely(!cg->st_queued_ops)) {
2021 cg->st_queued_ops = rrdset_find_bytype_localhost(
2022 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "queued_ops");
2023 if(likely(!cg->st_queued_ops)) {
2024 snprintfz(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_title);
2025 cg->st_queued_ops = rrdset_create(type, "queued_ops", NULL, "disk", "cgroup.queued_ops", title, "operations", CHART_PRIORITY_CONTAINERS + 2000, update_every, RRDSET_TYPE_LINE);
2027 rrddim_add(cg->st_queued_ops, "read", NULL, 1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
2028 rrddim_add(cg->st_queued_ops, "write", NULL, -1, 1, RRDDIM_ALGORITHM_ABSOLUTE);
2031 rrdset_next(cg->st_queued_ops);
2033 rrddim_set(cg->st_queued_ops, "read", cg->io_queued.Read);
2034 rrddim_set(cg->st_queued_ops, "write", cg->io_queued.Write);
2035 rrdset_done(cg->st_queued_ops);
2038 if(likely(cg->io_merged.updated && cg->io_merged.enabled == CONFIG_ONDEMAND_YES)) {
2039 if(unlikely(!cg->st_merged_ops)) {
2040 cg->st_merged_ops = rrdset_find_bytype_localhost(
2041 cgroup_chart_type(type, cg->chart_id, RRD_ID_LENGTH_MAX), "merged_ops");
2042 if(likely(!cg->st_merged_ops)) {
2043 snprintfz(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_title);
2044 cg->st_merged_ops = rrdset_create(type, "merged_ops", NULL, "disk", "cgroup.merged_ops", title, "operations/s", CHART_PRIORITY_CONTAINERS + 2100, update_every, RRDSET_TYPE_LINE);
2046 rrddim_add(cg->st_merged_ops, "read", NULL, 1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
2047 rrddim_add(cg->st_merged_ops, "write", NULL, -1, 1024, RRDDIM_ALGORITHM_INCREMENTAL);
2050 rrdset_next(cg->st_merged_ops);
2052 rrddim_set(cg->st_merged_ops, "read", cg->io_merged.Read);
2053 rrddim_set(cg->st_merged_ops, "write", cg->io_merged.Write);
2054 rrdset_done(cg->st_merged_ops);
2058 if(likely(cgroup_enable_systemd_services))
2059 update_services_charts(update_every,
2061 services_do_mem_usage,
2062 services_do_mem_detailed,
2063 services_do_mem_failcnt,
2064 services_do_swap_usage,
2067 services_do_throttle_io,
2068 services_do_throttle_ops,
2069 services_do_queued_ops,
2070 services_do_merged_ops
2073 debug(D_CGROUP, "done updating cgroups charts");
2076 // ----------------------------------------------------------------------------
2079 void *cgroups_main(void *ptr) {
2080 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
2082 info("CGROUP Plugin thread created with task id %d", gettid());
2084 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
2085 error("Cannot set pthread cancel type to DEFERRED.");
2087 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
2088 error("Cannot set pthread cancel state to ENABLE.");
2090 struct rusage thread;
2092 // when ZERO, attempt to do it
2093 int vdo_cpu_netdata = config_get_boolean("plugin:cgroups", "cgroups plugin resource charts", 1);
2095 read_cgroup_plugin_configuration();
2097 RRDSET *stcpu_thread = NULL;
2100 heartbeat_init(&hb);
2101 usec_t step = cgroup_update_every * USEC_PER_SEC;
2102 usec_t find_every = cgroup_check_for_new_every * USEC_PER_SEC, find_dt = 0;
2104 usec_t hb_dt = heartbeat_next(&hb, step);
2105 if(unlikely(netdata_exit)) break;
2107 // BEGIN -- the job to be done
2110 if(unlikely(find_dt >= find_every)) {
2115 read_all_cgroups(cgroup_root);
2116 update_cgroup_charts(cgroup_update_every);
2118 // END -- the job is done
2120 // --------------------------------------------------------------------
2122 if(vdo_cpu_netdata) {
2123 getrusage(RUSAGE_THREAD, &thread);
2125 if(unlikely(!stcpu_thread)) {
2126 stcpu_thread = rrdset_find_localhost("netdata.plugin_cgroups_cpu");
2127 if(unlikely(!stcpu_thread))
2128 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);
2130 rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_ALGORITHM_INCREMENTAL);
2131 rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_ALGORITHM_INCREMENTAL);
2134 rrdset_next(stcpu_thread);
2136 rrddim_set(stcpu_thread, "user" , thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
2137 rrddim_set(stcpu_thread, "system", thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
2138 rrdset_done(stcpu_thread);
2142 info("CGROUP thread exiting");
2144 static_thread->enabled = 0;