13 #include "appconfig.h"
20 // ----------------------------------------------------------------------------
23 static int cgroup_enable_cpuacct_stat = CONFIG_ONDEMAND_ONDEMAND;
24 static int cgroup_enable_cpuacct_usage = CONFIG_ONDEMAND_ONDEMAND;
25 static int cgroup_enable_memory = CONFIG_ONDEMAND_ONDEMAND;
26 static int cgroup_enable_blkio = CONFIG_ONDEMAND_ONDEMAND;
27 static int cgroup_enable_new_cgroups_detected_at_runtime = 1;
28 static int cgroup_check_for_new_every = 10;
29 static char *cgroup_cpuacct_base = NULL;
30 static char *cgroup_blkio_base = NULL;
31 static char *cgroup_memory_base = NULL;
33 static int cgroup_root_count = 0;
34 static int cgroup_root_max = 50;
35 static int cgroup_max_depth = 0;
37 void read_cgroup_plugin_configuration() {
38 cgroup_check_for_new_every = config_get_number("plugin:cgroups", "check for new plugin every", cgroup_check_for_new_every);
40 cgroup_enable_cpuacct_stat = config_get_boolean_ondemand("plugin:cgroups", "enable cpuacct stat", cgroup_enable_cpuacct_stat);
41 cgroup_enable_cpuacct_usage = config_get_boolean_ondemand("plugin:cgroups", "enable cpuacct usage", cgroup_enable_cpuacct_usage);
42 cgroup_enable_memory = config_get_boolean_ondemand("plugin:cgroups", "enable memory", cgroup_enable_memory);
43 cgroup_enable_blkio = config_get_boolean_ondemand("plugin:cgroups", "enable blkio", cgroup_enable_blkio);
45 char filename[FILENAME_MAX + 1];
46 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/fs/cgroup/cpuacct");
47 cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
49 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/fs/cgroup/blkio");
50 cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
52 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/fs/cgroup/memory");
53 cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
55 cgroup_root_max = config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
56 cgroup_max_depth = config_get_number("plugin:cgroups", "max cgroups depth to monitor", cgroup_max_depth);
58 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);
61 // ----------------------------------------------------------------------------
69 unsigned long long Read;
70 unsigned long long Write;
72 unsigned long long Sync;
73 unsigned long long Async;
74 unsigned long long Total;
78 // https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
86 unsigned long long cache;
87 unsigned long long rss;
88 unsigned long long rss_huge;
89 unsigned long long mapped_file;
90 unsigned long long writeback;
91 unsigned long long dirty;
92 unsigned long long swap;
93 unsigned long long pgpgin;
94 unsigned long long pgpgout;
95 unsigned long long pgfault;
96 unsigned long long pgmajfault;
98 unsigned long long inactive_anon;
99 unsigned long long active_anon;
100 unsigned long long inactive_file;
101 unsigned long long active_file;
102 unsigned long long unevictable;
103 unsigned long long hierarchical_memory_limit;
104 unsigned long long total_cache;
105 unsigned long long total_rss;
106 unsigned long long total_rss_huge;
107 unsigned long long total_mapped_file;
108 unsigned long long total_writeback;
109 unsigned long long total_dirty;
110 unsigned long long total_swap;
111 unsigned long long total_pgpgin;
112 unsigned long long total_pgpgout;
113 unsigned long long total_pgfault;
114 unsigned long long total_pgmajfault;
115 unsigned long long total_inactive_anon;
116 unsigned long long total_active_anon;
117 unsigned long long total_inactive_file;
118 unsigned long long total_active_file;
119 unsigned long long total_unevictable;
123 // https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
124 struct cpuacct_stat {
129 unsigned long long user;
130 unsigned long long system;
133 // https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
134 struct cpuacct_usage {
140 unsigned long long *cpu_percpu;
152 struct cpuacct_stat cpuacct_stat;
153 struct cpuacct_usage cpuacct_usage;
155 struct memory memory;
157 struct blkio io_service_bytes; // bytes
158 struct blkio io_serviced; // operations
160 struct blkio throttle_io_service_bytes; // bytes
161 struct blkio throttle_io_serviced; // operations
163 struct blkio io_merged; // operations
164 struct blkio io_queued; // operations
168 } *cgroup_root = NULL;
170 // ----------------------------------------------------------------------------
171 // read values from /sys
173 void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) {
174 static procfile *ff = NULL;
176 static uint32_t user_hash = 0;
177 static uint32_t system_hash = 0;
179 if(unlikely(user_hash == 0)) {
180 user_hash = simple_hash("user");
181 system_hash = simple_hash("system");
186 ff = procfile_reopen(ff, cp->filename, NULL, PROCFILE_FLAG_DEFAULT);
189 ff = procfile_readall(ff);
192 unsigned long i, lines = procfile_lines(ff);
195 error("File '%s' should have 1+ lines.", cp->filename);
199 for(i = 0; i < lines ; i++) {
200 char *s = procfile_lineword(ff, i, 0);
201 uint32_t hash = simple_hash(s);
203 if(hash == user_hash && !strcmp(s, "user"))
204 cp->user = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
206 else if(hash == system_hash && !strcmp(s, "system"))
207 cp->system = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
212 // fprintf(stderr, "READ '%s': user: %llu, system: %llu\n", cp->filename, cp->user, cp->system);
216 void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) {
217 static procfile *ff = NULL;
221 ff = procfile_reopen(ff, ca->filename, NULL, PROCFILE_FLAG_DEFAULT);
224 ff = procfile_readall(ff);
227 if(procfile_lines(ff) < 1) {
228 error("File '%s' should have 1+ lines but has %d.", ca->filename, procfile_lines(ff));
232 unsigned long i = procfile_linewords(ff, 0);
235 // we may have 1 more CPU reported
237 char *s = procfile_lineword(ff, 0, i - 1);
243 free(ca->cpu_percpu);
245 ca->cpu_percpu = malloc(sizeof(unsigned long long) * i);
247 fatal("Cannot allocate memory (%z bytes)", sizeof(unsigned long long) * i);
251 for(i = 0; i < ca->cpus ;i++) {
252 ca->cpu_percpu[i] = strtoull(procfile_lineword(ff, 0, i), NULL, 10);
253 // fprintf(stderr, "READ '%s': cpu%d/%d: %llu ('%s')\n", ca->filename, i, ca->cpus, ca->cpu_percpu[i], procfile_lineword(ff, 0, i));
260 void cgroup_read_blkio(struct blkio *io) {
261 static procfile *ff = NULL;
263 static uint32_t Read_hash = 0;
264 static uint32_t Write_hash = 0;
266 static uint32_t Sync_hash = 0;
267 static uint32_t Async_hash = 0;
268 static uint32_t Total_hash = 0;
271 if(unlikely(Read_hash == 0)) {
272 Read_hash = simple_hash("Read");
273 Write_hash = simple_hash("Write");
275 Sync_hash = simple_hash("Sync");
276 Async_hash = simple_hash("Async");
277 Total_hash = simple_hash("Total");
283 ff = procfile_reopen(ff, io->filename, NULL, PROCFILE_FLAG_DEFAULT);
286 ff = procfile_readall(ff);
289 unsigned long i, lines = procfile_lines(ff);
292 error("File '%s' should have 1+ lines.", io->filename);
304 for(i = 0; i < lines ; i++) {
305 char *s = procfile_lineword(ff, i, 1);
306 uint32_t hash = simple_hash(s);
308 if(hash == Read_hash && !strcmp(s, "Read"))
309 io->Read += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
311 else if(hash == Write_hash && !strcmp(s, "Write"))
312 io->Write += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
315 else if(hash == Sync_hash && !strcmp(s, "Sync"))
316 io->Sync += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
318 else if(hash == Async_hash && !strcmp(s, "Async"))
319 io->Async += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
321 else if(hash == Total_hash && !strcmp(s, "Total"))
322 io->Total += strtoull(procfile_lineword(ff, i, 2), NULL, 10);
327 // 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);
331 void cgroup_read_memory(struct memory *mem) {
332 static procfile *ff = NULL;
334 static uint32_t cache_hash = 0;
335 static uint32_t rss_hash = 0;
336 static uint32_t rss_huge_hash = 0;
337 static uint32_t mapped_file_hash = 0;
338 static uint32_t writeback_hash = 0;
339 static uint32_t dirty_hash = 0;
340 static uint32_t swap_hash = 0;
341 static uint32_t pgpgin_hash = 0;
342 static uint32_t pgpgout_hash = 0;
343 static uint32_t pgfault_hash = 0;
344 static uint32_t pgmajfault_hash = 0;
346 static uint32_t inactive_anon_hash = 0;
347 static uint32_t active_anon_hash = 0;
348 static uint32_t inactive_file_hash = 0;
349 static uint32_t active_file_hash = 0;
350 static uint32_t unevictable_hash = 0;
351 static uint32_t hierarchical_memory_limit_hash = 0;
352 static uint32_t total_cache_hash = 0;
353 static uint32_t total_rss_hash = 0;
354 static uint32_t total_rss_huge_hash = 0;
355 static uint32_t total_mapped_file_hash = 0;
356 static uint32_t total_writeback_hash = 0;
357 static uint32_t total_dirty_hash = 0;
358 static uint32_t total_swap_hash = 0;
359 static uint32_t total_pgpgin_hash = 0;
360 static uint32_t total_pgpgout_hash = 0;
361 static uint32_t total_pgfault_hash = 0;
362 static uint32_t total_pgmajfault_hash = 0;
363 static uint32_t total_inactive_anon_hash = 0;
364 static uint32_t total_active_anon_hash = 0;
365 static uint32_t total_inactive_file_hash = 0;
366 static uint32_t total_active_file_hash = 0;
367 static uint32_t total_unevictable_hash = 0;
369 if(unlikely(cache_hash == 0)) {
370 cache_hash = simple_hash("cache");
371 rss_hash = simple_hash("rss");
372 rss_huge_hash = simple_hash("rss_huge");
373 mapped_file_hash = simple_hash("mapped_file");
374 writeback_hash = simple_hash("writeback");
375 dirty_hash = simple_hash("dirty");
376 swap_hash = simple_hash("swap");
377 pgpgin_hash = simple_hash("pgpgin");
378 pgpgout_hash = simple_hash("pgpgout");
379 pgfault_hash = simple_hash("pgfault");
380 pgmajfault_hash = simple_hash("pgmajfault");
382 inactive_anon_hash = simple_hash("inactive_anon");
383 active_anon_hash = simple_hash("active_anon");
384 inactive_file_hash = simple_hash("inactive_file");
385 active_file_hash = simple_hash("active_file");
386 unevictable_hash = simple_hash("unevictable");
387 hierarchical_memory_limit_hash = simple_hash("hierarchical_memory_limit");
388 total_cache_hash = simple_hash("total_cache");
389 total_rss_hash = simple_hash("total_rss");
390 total_rss_huge_hash = simple_hash("total_rss_huge");
391 total_mapped_file_hash = simple_hash("total_mapped_file");
392 total_writeback_hash = simple_hash("total_writeback");
393 total_dirty_hash = simple_hash("total_dirty");
394 total_swap_hash = simple_hash("total_swap");
395 total_pgpgin_hash = simple_hash("total_pgpgin");
396 total_pgpgout_hash = simple_hash("total_pgpgout");
397 total_pgfault_hash = simple_hash("total_pgfault");
398 total_pgmajfault_hash = simple_hash("total_pgmajfault");
399 total_inactive_anon_hash = simple_hash("total_inactive_anon");
400 total_active_anon_hash = simple_hash("total_active_anon");
401 total_inactive_file_hash = simple_hash("total_inactive_file");
402 total_active_file_hash = simple_hash("total_active_file");
403 total_unevictable_hash = simple_hash("total_unevictable");
409 ff = procfile_reopen(ff, mem->filename, NULL, PROCFILE_FLAG_DEFAULT);
412 ff = procfile_readall(ff);
415 unsigned long i, lines = procfile_lines(ff);
418 error("File '%s' should have 1+ lines.", mem->filename);
422 for(i = 0; i < lines ; i++) {
423 char *s = procfile_lineword(ff, i, 0);
424 uint32_t hash = simple_hash(s);
426 if(hash == cache_hash && !strcmp(s, "cache"))
427 mem->cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
429 else if(hash == rss_hash && !strcmp(s, "rss"))
430 mem->rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
432 else if(hash == rss_huge_hash && !strcmp(s, "rss_huge"))
433 mem->rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
435 else if(hash == mapped_file_hash && !strcmp(s, "mapped_file"))
436 mem->mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
438 else if(hash == writeback_hash && !strcmp(s, "writeback"))
439 mem->writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
441 else if(hash == dirty_hash && !strcmp(s, "dirty")) {
442 mem->dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
443 mem->has_dirty_swap = 1;
446 else if(hash == swap_hash && !strcmp(s, "swap")) {
447 mem->swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
448 mem->has_dirty_swap = 1;
451 else if(hash == pgpgin_hash && !strcmp(s, "pgpgin"))
452 mem->pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
454 else if(hash == pgpgout_hash && !strcmp(s, "pgpgout"))
455 mem->pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
457 else if(hash == pgfault_hash && !strcmp(s, "pgfault"))
458 mem->pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
460 else if(hash == pgmajfault_hash && !strcmp(s, "pgmajfault"))
461 mem->pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
464 else if(hash == inactive_anon_hash && !strcmp(s, "inactive_anon"))
465 mem->inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
467 else if(hash == active_anon_hash && !strcmp(s, "active_anon"))
468 mem->active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
470 else if(hash == inactive_file_hash && !strcmp(s, "inactive_file"))
471 mem->inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
473 else if(hash == active_file_hash && !strcmp(s, "active_file"))
474 mem->active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
476 else if(hash == unevictable_hash && !strcmp(s, "unevictable"))
477 mem->unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
479 else if(hash == hierarchical_memory_limit_hash && !strcmp(s, "hierarchical_memory_limit"))
480 mem->hierarchical_memory_limit = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
482 else if(hash == total_cache_hash && !strcmp(s, "total_cache"))
483 mem->total_cache = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
485 else if(hash == total_rss_hash && !strcmp(s, "total_rss"))
486 mem->total_rss = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
488 else if(hash == total_rss_huge_hash && !strcmp(s, "total_rss_huge"))
489 mem->total_rss_huge = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
491 else if(hash == total_mapped_file_hash && !strcmp(s, "total_mapped_file"))
492 mem->total_mapped_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
494 else if(hash == total_writeback_hash && !strcmp(s, "total_writeback"))
495 mem->total_writeback = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
497 else if(hash == total_dirty_hash && !strcmp(s, "total_dirty"))
498 mem->total_dirty = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
500 else if(hash == total_swap_hash && !strcmp(s, "total_swap"))
501 mem->total_swap = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
503 else if(hash == total_pgpgin_hash && !strcmp(s, "total_pgpgin"))
504 mem->total_pgpgin = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
506 else if(hash == total_pgpgout_hash && !strcmp(s, "total_pgpgout"))
507 mem->total_pgpgout = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
509 else if(hash == total_pgfault_hash && !strcmp(s, "total_pgfault"))
510 mem->total_pgfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
512 else if(hash == total_pgmajfault_hash && !strcmp(s, "total_pgmajfault"))
513 mem->total_pgmajfault = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
515 else if(hash == total_inactive_anon_hash && !strcmp(s, "total_inactive_anon"))
516 mem->total_inactive_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
518 else if(hash == total_active_anon_hash && !strcmp(s, "total_active_anon"))
519 mem->total_active_anon = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
521 else if(hash == total_inactive_file_hash && !strcmp(s, "total_inactive_file"))
522 mem->total_inactive_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
524 else if(hash == total_active_file_hash && !strcmp(s, "total_active_file"))
525 mem->total_active_file = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
527 else if(hash == total_unevictable_hash && !strcmp(s, "total_unevictable"))
528 mem->total_unevictable = strtoull(procfile_lineword(ff, i, 1), NULL, 10);
532 // 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);
538 void cgroup_read(struct cgroup *cg) {
539 debug(D_CGROUP, "reading metrics for cgroups '%s'", cg->id);
541 cgroup_read_cpuacct_stat(&cg->cpuacct_stat);
542 cgroup_read_cpuacct_usage(&cg->cpuacct_usage);
543 cgroup_read_memory(&cg->memory);
544 cgroup_read_blkio(&cg->io_service_bytes);
545 cgroup_read_blkio(&cg->io_serviced);
546 cgroup_read_blkio(&cg->throttle_io_service_bytes);
547 cgroup_read_blkio(&cg->throttle_io_serviced);
548 cgroup_read_blkio(&cg->io_merged);
549 cgroup_read_blkio(&cg->io_queued);
552 void read_all_cgroups(struct cgroup *root) {
553 debug(D_CGROUP, "reading metrics for all cgroups");
557 for(cg = root; cg ; cg = cg->next)
562 // ----------------------------------------------------------------------------
563 // add/remove/find cgroup objects
565 #define CGROUP_CHARTID_LINE_MAX 1024
567 void cgroup_get_chart_id(struct cgroup *cg) {
568 debug(D_CGROUP, "getting the name of cgroup '%s'", cg->id);
571 char buffer[CGROUP_CHARTID_LINE_MAX + 1];
573 snprintf(buffer, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'",
574 config_get("plugin:cgroups", "script to get cgroup names", PLUGINS_DIR "/cgroup-name.sh"), cg->chart_id);
576 debug(D_CGROUP, "executing command '%s' for cgroup '%s'", buffer, cg->id);
577 FILE *fp = mypopen(buffer, &cgroup_pid);
579 error("CGROUP: Cannot popen(\"%s\", \"r\").", buffer);
582 debug(D_CGROUP, "reading from command '%s' for cgroup '%s'", buffer, cg->id);
583 char *s = fgets(buffer, CGROUP_CHARTID_LINE_MAX, fp);
584 debug(D_CGROUP, "closing command for cgroup '%s'", cg->id);
585 mypclose(fp, cgroup_pid);
586 debug(D_CGROUP, "closed command for cgroup '%s'", cg->id);
588 if(s && *s && *s != '\n') {
589 debug(D_CGROUP, "cgroup '%s' should be renamed to '%s'", cg->id, s);
592 netdata_fix_chart_id(s);
594 cg->chart_id = strdup(s);
596 fatal("CGROUP: Cannot allocate memory for chart id of cgroup '%s' chart id: '%s'", cg->id, s);
598 debug(D_CGROUP, "cgroup '%s' renamed to '%s'", cg->id, cg->chart_id);
600 else debug(D_CGROUP, "cgroup '%s' is not to be renamed (will be shown as '%s')", cg->id, cg->chart_id);
603 struct cgroup *cgroup_add(const char *id) {
604 debug(D_CGROUP, "adding cgroup '%s'", id);
606 if(cgroup_root_count >= cgroup_root_max) {
607 info("Maximum number of cgroups reached (%d). Not adding cgroup '%s'", cgroup_root_count, id);
611 int def = cgroup_enable_new_cgroups_detected_at_runtime;
612 const char *chart_id = id;
616 // disable by default the host cgroup
618 debug(D_CGROUP, "cgroup '%s' is the host container (by default %s)", id, (def)?"enabled":"disabled");
621 if(*chart_id == '/') chart_id++;
623 // disable by default the parent cgroup
624 // for known cgroup managers
625 if(!strcmp(chart_id, "lxc") || !strcmp(chart_id, "docker")) {
627 debug(D_CGROUP, "cgroup '%s' is container manager (by default %s)", id, (def)?"enabled":"disabled");
631 struct cgroup *cg = calloc(1, sizeof(struct cgroup));
632 if(!cg) fatal("Cannot allocate memory for cgroup '%s'", id);
634 debug(D_CGROUP, "adding cgroup '%s'", id);
637 if(!cg->id) fatal("Cannot allocate memory for cgroup '%s'", id);
639 cg->hash = simple_hash(cg->id);
641 cg->chart_id = strdup(chart_id);
642 if(!cg->chart_id) fatal("Cannot allocate memory for cgroup '%s'", id);
649 for(e = cgroup_root; e->next ;e = e->next) ;
655 // fprintf(stderr, " > added cgroup No %d, with id '%s' (%u) and name '%s'\n", cgroup_root_count, cg->id, cg->hash, cg->name);
657 // fix the name by calling the external script
658 cgroup_get_chart_id(cg);
660 char option[FILENAME_MAX + 1];
661 snprintf(option, FILENAME_MAX, "enable cgroup %s", cg->chart_id);
662 cg->enabled = config_get_boolean("plugin:cgroups", option, def);
663 debug(D_CGROUP, "finally: new cgroup '%s' is named '%s' and is %s (default was %s)", cg->id, cg->chart_id, (cg->enabled)?"enabled":"disabled", (def)?"enabled":"disabled");
668 void cgroup_remove(struct cgroup *cg) {
669 debug(D_CGROUP, "removing cgroup '%s'", cg->id);
671 if(cg == cgroup_root) {
672 cgroup_root = cg->next;
676 for(e = cgroup_root; e->next ;e = e->next)
677 if(unlikely(e->next == cg)) break;
680 error("Cannot find cgroup '%s' in list of cgroups", cg->id);
688 free(cg->cpuacct_usage.cpu_percpu);
690 free(cg->cpuacct_stat.filename);
691 free(cg->cpuacct_usage.filename);
692 free(cg->memory.filename);
693 free(cg->io_service_bytes.filename);
694 free(cg->io_serviced.filename);
695 free(cg->throttle_io_service_bytes.filename);
696 free(cg->throttle_io_serviced.filename);
697 free(cg->io_merged.filename);
698 free(cg->io_queued.filename);
705 // find if a given cgroup exists
706 struct cgroup *cgroup_find(const char *id) {
707 debug(D_CGROUP, "searching for cgroup '%s'", id);
709 uint32_t hash = simple_hash(id);
711 // fprintf(stderr, " > searching for '%s' (%u)\n", id, hash);
714 for(cg = cgroup_root; cg ; cg = cg->next) {
715 if(hash == cg->hash && strcmp(id, cg->id) == 0)
719 debug(D_CGROUP, "cgroup '%s' %s", id, (cg)?"found":"not found");
723 // ----------------------------------------------------------------------------
724 // detect running cgroups
726 // callback for find_file_in_subdirs()
727 void found_dir_in_subdir(const char *dir) {
728 debug(D_CGROUP, "examining cgroup dir '%s'", dir);
730 struct cgroup *cg = cgroup_find(dir);
732 if(*dir && cgroup_max_depth > 0) {
736 for(s = dir; *s ;s++)
737 if(unlikely(*s == '/'))
740 if(depth > cgroup_max_depth) {
741 info("cgroup '%s' is too deep (%d, while max is %d)", dir, depth, cgroup_max_depth);
745 debug(D_CGROUP, "will add dir '%s' as cgroup", dir);
746 cg = cgroup_add(dir);
749 if(cg) cg->available = 1;
752 void find_dir_in_subdirs(const char *base, const char *this, void (*callback)(const char *)) {
753 if(!this) this = base;
754 size_t dirlen = strlen(this), baselen = strlen(base);
756 DIR *dir = opendir(this);
759 callback(&this[baselen]);
761 struct dirent *de = NULL;
762 while((de = readdir(dir))) {
763 if(de->d_type == DT_DIR
765 (de->d_name[0] == '.' && de->d_name[1] == '\0')
766 || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
770 debug(D_CGROUP, "examining '%s/%s'", this, de->d_name);
772 if(de->d_type == DT_DIR) {
773 char *s = malloc(dirlen + strlen(de->d_name) + 2);
777 strcat(s, de->d_name);
778 find_dir_in_subdirs(base, s, callback);
787 void mark_all_cgroups_as_not_available() {
788 debug(D_CGROUP, "marking all cgroups as not available");
792 // mark all as not available
793 for(cg = cgroup_root; cg ; cg = cg->next)
797 struct cgroup *find_all_cgroups() {
798 debug(D_CGROUP, "searching for cgroups");
800 mark_all_cgroups_as_not_available();
802 if(cgroup_enable_cpuacct_stat || cgroup_enable_cpuacct_usage)
803 find_dir_in_subdirs(cgroup_cpuacct_base, NULL, found_dir_in_subdir);
805 if(cgroup_enable_blkio)
806 find_dir_in_subdirs(cgroup_blkio_base, NULL, found_dir_in_subdir);
808 if(cgroup_enable_memory)
809 find_dir_in_subdirs(cgroup_memory_base, NULL, found_dir_in_subdir);
812 for(cg = cgroup_root; cg ; cg = cg->next) {
813 // fprintf(stderr, " >>> CGROUP '%s' (%u - %s) with name '%s'\n", cg->id, cg->hash, cg->available?"available":"stopped", cg->name);
816 // do not remove the cgroup
817 // it will be added back on the next scan
818 // cgroup_remove(cg);
822 debug(D_CGROUP, "checking paths for cgroup '%s'", cg->id);
824 // check for newly added cgroups
825 // and update the filenames they read
826 char filename[FILENAME_MAX + 1];
827 if(cgroup_enable_cpuacct_stat && !cg->cpuacct_stat.filename) {
828 snprintf(filename, FILENAME_MAX, "%s%s/cpuacct.stat", cgroup_cpuacct_base, cg->id);
829 cg->cpuacct_stat.filename = strdup(filename);
830 debug(D_CGROUP, "cpuacct.stat filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_stat.filename);
832 if(cgroup_enable_cpuacct_usage && !cg->cpuacct_usage.filename) {
833 snprintf(filename, FILENAME_MAX, "%s%s/cpuacct.usage_percpu", cgroup_cpuacct_base, cg->id);
834 cg->cpuacct_usage.filename = strdup(filename);
835 debug(D_CGROUP, "cpuacct.usage_percpu filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_usage.filename);
837 if(cgroup_enable_memory && !cg->memory.filename) {
838 snprintf(filename, FILENAME_MAX, "%s%s/memory.stat", cgroup_memory_base, cg->id);
839 cg->memory.filename = strdup(filename);
840 debug(D_CGROUP, "memory.stat filename for cgroup '%s': '%s'", cg->id, cg->memory.filename);
842 if(cgroup_enable_blkio) {
843 if(!cg->io_service_bytes.filename) {
844 snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_service_bytes", cgroup_blkio_base, cg->id);
845 cg->io_service_bytes.filename = strdup(filename);
846 debug(D_CGROUP, "io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->io_service_bytes.filename);
848 if(!cg->io_serviced.filename) {
849 snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_serviced", cgroup_blkio_base, cg->id);
850 cg->io_serviced.filename = strdup(filename);
851 debug(D_CGROUP, "io_serviced filename for cgroup '%s': '%s'", cg->id, cg->io_serviced.filename);
853 if(!cg->throttle_io_service_bytes.filename) {
854 snprintf(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_service_bytes", cgroup_blkio_base, cg->id);
855 cg->throttle_io_service_bytes.filename = strdup(filename);
856 debug(D_CGROUP, "throttle_io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_service_bytes.filename);
858 if(!cg->throttle_io_serviced.filename) {
859 snprintf(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_serviced", cgroup_blkio_base, cg->id);
860 cg->throttle_io_serviced.filename = strdup(filename);
861 debug(D_CGROUP, "throttle_io_serviced filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_serviced.filename);
863 if(!cg->io_merged.filename) {
864 snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_merged", cgroup_blkio_base, cg->id);
865 cg->io_merged.filename = strdup(filename);
866 debug(D_CGROUP, "io_merged filename for cgroup '%s': '%s'", cg->id, cg->io_merged.filename);
868 if(!cg->io_queued.filename) {
869 snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_queued", cgroup_blkio_base, cg->id);
870 cg->io_queued.filename = strdup(filename);
871 debug(D_CGROUP, "io_queued filename for cgroup '%s': '%s'", cg->id, cg->io_queued.filename);
876 debug(D_CGROUP, "done searching for cgroups");
880 // ----------------------------------------------------------------------------
883 #define CHART_TITLE_MAX 300
885 void update_cgroup_charts(int update_every) {
886 debug(D_CGROUP, "updating cgroups charts");
888 char type[RRD_ID_LENGTH_MAX + 1];
889 char title[CHART_TITLE_MAX + 1];
894 for(cg = cgroup_root; cg ; cg = cg->next) {
895 if(!cg->available || !cg->enabled) continue;
897 if(cg->id[0] == '\0')
898 strcpy(type, "cgroup_host");
899 else if(cg->id[0] == '/')
900 snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
902 snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
904 netdata_fix_chart_id(type);
906 if(cg->cpuacct_stat.updated) {
907 st = rrdset_find_bytype(type, "cpu");
909 snprintf(title, CHART_TITLE_MAX, "CPU Usage for cgroup %s", cg->chart_id);
910 st = rrdset_create(type, "cpu", NULL, "cpu", "cgroup.cpu", title, "%", 40000, update_every, RRDSET_TYPE_STACKED);
912 rrddim_add(st, "user", NULL, 100, hz, RRDDIM_INCREMENTAL);
913 rrddim_add(st, "system", NULL, 100, hz, RRDDIM_INCREMENTAL);
915 else rrdset_next(st);
917 rrddim_set(st, "user", cg->cpuacct_stat.user);
918 rrddim_set(st, "system", cg->cpuacct_stat.system);
922 if(cg->cpuacct_usage.updated) {
923 char id[RRD_ID_LENGTH_MAX + 1];
926 st = rrdset_find_bytype(type, "cpu_per_core");
928 snprintf(title, CHART_TITLE_MAX, "CPU Usage Per Core for cgroup %s", cg->chart_id);
929 st = rrdset_create(type, "cpu_per_core", NULL, "cpu", "cgroup.cpu_per_core", title, "%", 40100, update_every, RRDSET_TYPE_STACKED);
931 for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
932 snprintf(id, CHART_TITLE_MAX, "cpu%d", i);
933 rrddim_add(st, id, NULL, 100, 1000000, RRDDIM_INCREMENTAL);
936 else rrdset_next(st);
938 for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
939 snprintf(id, CHART_TITLE_MAX, "cpu%d", i);
940 rrddim_set(st, id, cg->cpuacct_usage.cpu_percpu[i]);
945 if(cg->memory.updated) {
946 if(cg->memory.cache + cg->memory.rss + cg->memory.rss_huge + cg->memory.mapped_file > 0) {
947 st = rrdset_find_bytype(type, "mem");
949 snprintf(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_id);
950 st = rrdset_create(type, "mem", NULL, "mem", "cgroup.mem", title, "MB", 40200, update_every,
951 RRDSET_TYPE_STACKED);
953 rrddim_add(st, "cache", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
954 rrddim_add(st, "rss", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
955 if(cg->memory.has_dirty_swap)
956 rrddim_add(st, "swap", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
957 rrddim_add(st, "rss_huge", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
958 rrddim_add(st, "mapped_file", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
960 else rrdset_next(st);
962 rrddim_set(st, "cache", cg->memory.cache);
963 rrddim_set(st, "rss", cg->memory.rss);
964 if(cg->memory.has_dirty_swap)
965 rrddim_set(st, "swap", cg->memory.swap);
966 rrddim_set(st, "rss_huge", cg->memory.rss_huge);
967 rrddim_set(st, "mapped_file", cg->memory.mapped_file);
971 st = rrdset_find_bytype(type, "writeback");
973 snprintf(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_id);
974 st = rrdset_create(type, "writeback", NULL, "mem", "cgroup.writeback", title, "MB", 40300,
975 update_every, RRDSET_TYPE_AREA);
977 if(cg->memory.has_dirty_swap)
978 rrddim_add(st, "dirty", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
979 rrddim_add(st, "writeback", NULL, 1, 1024 * 1024, RRDDIM_ABSOLUTE);
981 else rrdset_next(st);
983 if(cg->memory.has_dirty_swap)
984 rrddim_set(st, "dirty", cg->memory.dirty);
985 rrddim_set(st, "writeback", cg->memory.writeback);
988 if(cg->memory.pgpgin + cg->memory.pgpgout > 0) {
989 st = rrdset_find_bytype(type, "mem_activity");
991 snprintf(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_id);
992 st = rrdset_create(type, "mem_activity", NULL, "mem", "cgroup.mem_activity", title, "MB/s",
993 40400, update_every, RRDSET_TYPE_LINE);
995 rrddim_add(st, "pgpgin", "in", sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
996 rrddim_add(st, "pgpgout", "out", -sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
998 else rrdset_next(st);
1000 rrddim_set(st, "pgpgin", cg->memory.pgpgin);
1001 rrddim_set(st, "pgpgout", cg->memory.pgpgout);
1005 if(cg->memory.pgfault + cg->memory.pgmajfault > 0) {
1006 st = rrdset_find_bytype(type, "pgfaults");
1008 snprintf(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_id);
1009 st = rrdset_create(type, "pgfaults", NULL, "mem", "cgroup.pgfaults", title, "MB/s", 40500,
1010 update_every, RRDSET_TYPE_LINE);
1012 rrddim_add(st, "pgfault", NULL, sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
1013 rrddim_add(st, "pgmajfault", "swap", -sysconf(_SC_PAGESIZE), 1024 * 1024, RRDDIM_INCREMENTAL);
1015 else rrdset_next(st);
1017 rrddim_set(st, "pgfault", cg->memory.pgfault);
1018 rrddim_set(st, "pgmajfault", cg->memory.pgmajfault);
1023 if(cg->io_service_bytes.updated && cg->io_service_bytes.Read + cg->io_service_bytes.Write > 0) {
1024 st = rrdset_find_bytype(type, "io");
1026 snprintf(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_id);
1027 st = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200,
1028 update_every, RRDSET_TYPE_LINE);
1030 rrddim_add(st, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
1031 rrddim_add(st, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
1033 else rrdset_next(st);
1035 rrddim_set(st, "read", cg->io_service_bytes.Read);
1036 rrddim_set(st, "write", cg->io_service_bytes.Write);
1040 if(cg->io_serviced.updated && cg->io_serviced.Read + cg->io_serviced.Write > 0) {
1041 st = rrdset_find_bytype(type, "serviced_ops");
1043 snprintf(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_id);
1044 st = rrdset_create(type, "serviced_ops", NULL, "disk", "cgroup.serviced_ops", title, "operations/s", 41200,
1045 update_every, RRDSET_TYPE_LINE);
1047 rrddim_add(st, "read", NULL, 1, 1, RRDDIM_INCREMENTAL);
1048 rrddim_add(st, "write", NULL, -1, 1, RRDDIM_INCREMENTAL);
1050 else rrdset_next(st);
1052 rrddim_set(st, "read", cg->io_serviced.Read);
1053 rrddim_set(st, "write", cg->io_serviced.Write);
1057 if(cg->throttle_io_service_bytes.updated && cg->throttle_io_service_bytes.Read + cg->throttle_io_service_bytes.Write > 0) {
1058 st = rrdset_find_bytype(type, "io");
1060 snprintf(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_id);
1061 st = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200,
1062 update_every, RRDSET_TYPE_LINE);
1064 rrddim_add(st, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
1065 rrddim_add(st, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
1067 else rrdset_next(st);
1069 rrddim_set(st, "read", cg->throttle_io_service_bytes.Read);
1070 rrddim_set(st, "write", cg->throttle_io_service_bytes.Write);
1075 if(cg->throttle_io_serviced.updated && cg->throttle_io_serviced.Read + cg->throttle_io_serviced.Write > 0) {
1076 st = rrdset_find_bytype(type, "throttle_serviced_ops");
1078 snprintf(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_id);
1079 st = rrdset_create(type, "throttle_serviced_ops", NULL, "disk", "cgroup.throttle_serviced_ops", title, "operations/s", 41200,
1080 update_every, RRDSET_TYPE_LINE);
1082 rrddim_add(st, "read", NULL, 1, 1, RRDDIM_INCREMENTAL);
1083 rrddim_add(st, "write", NULL, -1, 1, RRDDIM_INCREMENTAL);
1085 else rrdset_next(st);
1087 rrddim_set(st, "read", cg->throttle_io_serviced.Read);
1088 rrddim_set(st, "write", cg->throttle_io_serviced.Write);
1092 if(cg->io_queued.updated) {
1093 st = rrdset_find_bytype(type, "queued_ops");
1095 snprintf(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_id);
1096 st = rrdset_create(type, "queued_ops", NULL, "disk", "cgroup.queued_ops", title, "operations", 42000,
1097 update_every, RRDSET_TYPE_LINE);
1099 rrddim_add(st, "read", NULL, 1, 1, RRDDIM_ABSOLUTE);
1100 rrddim_add(st, "write", NULL, -1, 1, RRDDIM_ABSOLUTE);
1102 else rrdset_next(st);
1104 rrddim_set(st, "read", cg->io_queued.Read);
1105 rrddim_set(st, "write", cg->io_queued.Write);
1109 if(cg->io_merged.updated && cg->io_merged.Read + cg->io_merged.Write > 0) {
1110 st = rrdset_find_bytype(type, "merged_ops");
1112 snprintf(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_id);
1113 st = rrdset_create(type, "merged_ops", NULL, "disk", "cgroup.merged_ops", title, "operations/s", 42100,
1114 update_every, RRDSET_TYPE_LINE);
1116 rrddim_add(st, "read", NULL, 1, 1024, RRDDIM_INCREMENTAL);
1117 rrddim_add(st, "write", NULL, -1, 1024, RRDDIM_INCREMENTAL);
1119 else rrdset_next(st);
1121 rrddim_set(st, "read", cg->io_merged.Read);
1122 rrddim_set(st, "write", cg->io_merged.Write);
1127 debug(D_CGROUP, "done updating cgroups charts");
1130 // ----------------------------------------------------------------------------
1133 int do_sys_fs_cgroup(int update_every, unsigned long long dt) {
1134 static int cgroup_global_config_read = 0;
1135 static time_t last_run = 0;
1136 time_t now = time(NULL);
1140 if(unlikely(!cgroup_global_config_read)) {
1141 read_cgroup_plugin_configuration();
1142 cgroup_global_config_read = 1;
1145 if(unlikely(cgroup_enable_new_cgroups_detected_at_runtime && now - last_run > cgroup_check_for_new_every)) {
1150 read_all_cgroups(cgroup_root);
1151 update_cgroup_charts(update_every);
1156 void *cgroups_main(void *ptr)
1160 info("CGROUP Plugin thread created with task id %d", gettid());
1162 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
1163 error("Cannot set pthread cancel type to DEFERRED.");
1165 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
1166 error("Cannot set pthread cancel state to ENABLE.");
1168 struct rusage thread;
1170 // when ZERO, attempt to do it
1171 int vdo_sys_fs_cgroup = 0;
1172 int vdo_cpu_netdata = !config_get_boolean("plugin:cgroups", "netdata server resources", 1);
1174 // keep track of the time each module was called
1175 unsigned long long sutime_sys_fs_cgroup = 0ULL;
1177 // the next time we will run - aligned properly
1178 unsigned long long sunext = (time(NULL) - (time(NULL) % rrd_update_every) + rrd_update_every) * 1000000ULL;
1179 unsigned long long sunow;
1181 RRDSET *stcpu_thread = NULL;
1184 if(unlikely(netdata_exit)) break;
1186 // delay until it is our time to run
1187 while((sunow = timems()) < sunext)
1188 usleep((useconds_t)(sunext - sunow));
1190 // find the next time we need to run
1191 while(timems() > sunext)
1192 sunext += rrd_update_every * 1000000ULL;
1194 if(unlikely(netdata_exit)) break;
1196 // BEGIN -- the job to be done
1198 if(!vdo_sys_fs_cgroup) {
1199 debug(D_PROCNETDEV_LOOP, "PROCNETDEV: calling do_sys_fs_cgroup().");
1201 vdo_sys_fs_cgroup = do_sys_fs_cgroup(rrd_update_every, (sutime_sys_fs_cgroup > 0)?sunow - sutime_sys_fs_cgroup:0ULL);
1202 sutime_sys_fs_cgroup = sunow;
1204 if(unlikely(netdata_exit)) break;
1206 // END -- the job is done
1208 // --------------------------------------------------------------------
1210 if(!vdo_cpu_netdata) {
1211 getrusage(RUSAGE_THREAD, &thread);
1213 if(!stcpu_thread) stcpu_thread = rrdset_find("netdata.plugin_cgroups_cpu");
1215 stcpu_thread = rrdset_create("netdata", "plugin_cgroups_cpu", NULL, "proc.internal", NULL, "NetData CGroups Plugin CPU usage", "milliseconds/s", 131000, rrd_update_every, RRDSET_TYPE_STACKED);
1217 rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL);
1218 rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
1220 else rrdset_next(stcpu_thread);
1222 rrddim_set(stcpu_thread, "user" , thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
1223 rrddim_set(stcpu_thread, "system", thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
1224 rrdset_done(stcpu_thread);