cgroups: allow the charts to have a more human readable name
Costa Tsaousis committed
Apr 30, 2016 at 03:25 UTC
e42407b110ecabcad4e34e4944ca6a5d2ea47074
1 file changed
+28
-18
src/sys_fs_cgroup.c
+28
-18
@@ -162,6 +162,7 @@ struct cgroup {
162
uint32_t hash;
163
164
char *chart_id;
165
+ char *chart_title;
166
167
struct cpuacct_stat cpuacct_stat;
168
struct cpuacct_usage cpuacct_usage;
@@ -604,13 +605,20 @@ void cgroup_get_chart_id(struct cgroup *cg) {
605
debug(D_CGROUP, "cgroup '%s' should be renamed to '%s'", cg->id, s);
606
607
trim(s);
608
+
609
+ free(cg->chart_title);
610
+ cg->chart_title = strdup(s);
611
+ if(!cg->chart_title)
612
+ fatal("CGROUP: Cannot allocate memory for chart name of cgroup '%s' chart name: '%s'", cg->id, s);
613
+
614
netdata_fix_chart_id(s);
615
+
616
free(cg->chart_id);
617
cg->chart_id = strdup(s);
618
if(!cg->chart_id)
619
fatal("CGROUP: Cannot allocate memory for chart id of cgroup '%s' chart id: '%s'", cg->id, s);
620
613
- debug(D_CGROUP, "cgroup '%s' renamed to '%s'", cg->id, cg->chart_id);
621
+ debug(D_CGROUP, "cgroup '%s' renamed to '%s' (title: '%s')", cg->id, cg->chart_id, cg->chart_title);
622
}
623
else debug(D_CGROUP, "cgroup '%s' is not to be renamed (will be shown as '%s')", cg->id, cg->chart_id);
624
}
@@ -661,6 +669,9 @@ struct cgroup *cgroup_add(const char *id) {
669
cg->chart_id = strdup(chart_id);
670
if(!cg->chart_id) fatal("Cannot allocate memory for cgroup '%s'", id);
671
672
+ cg->chart_title = strdup(chart_id);
673
+ if(!cg->chart_title) fatal("Cannot allocate memory for cgroup '%s'", id);
674
+
675
if(!cgroup_root)
676
cgroup_root = cg;
677
else {
@@ -676,12 +687,10 @@ struct cgroup *cgroup_add(const char *id) {
687
cgroup_get_chart_id(cg);
688
689
char option[FILENAME_MAX + 1];
679
- snprintf(option, FILENAME_MAX, "enable cgroup %s", chart_id);
690
+ snprintf(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
691
cg->enabled = config_get_boolean("plugin:cgroups", option, def);
692
682
- // FIXME
683
- // switch this to debug(D_CGROUP, ...
684
- info("Added cgroup '%s' with chart id '%s' as %s (default was %s)", cg->id, cg->chart_id, (cg->enabled)?"enabled":"disabled", (def)?"enabled":"disabled");
693
+ 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");
694
695
return cg;
696
}
@@ -707,6 +716,7 @@ void cgroup_free(struct cgroup *cg) {
716
717
free(cg->id);
718
free(cg->chart_id);
719
+ free(cg->chart_title);
720
free(cg);
721
722
cgroup_root_count--;
@@ -950,7 +960,7 @@ void update_cgroup_charts(int update_every) {
960
if(cg->id[0] == '\0')
961
strcpy(type, "cgroup_host");
962
else if(cg->id[0] == '/')
953
- snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
963
+ snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", "host");
964
else
965
snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
966
@@ -959,7 +969,7 @@ void update_cgroup_charts(int update_every) {
969
if(cg->cpuacct_stat.updated) {
970
st = rrdset_find_bytype(type, "cpu");
971
if(!st) {
962
- snprintf(title, CHART_TITLE_MAX, "CPU Usage for cgroup %s", cg->chart_id);
972
+ snprintf(title, CHART_TITLE_MAX, "CPU Usage for cgroup %s", cg->chart_title);
973
st = rrdset_create(type, "cpu", NULL, "cpu", "cgroup.cpu", title, "%", 40000, update_every, RRDSET_TYPE_STACKED);
974
975
rrddim_add(st, "user", NULL, 100, hz, RRDDIM_INCREMENTAL);
@@ -978,7 +988,7 @@ void update_cgroup_charts(int update_every) {
988
989
st = rrdset_find_bytype(type, "cpu_per_core");
990
if(!st) {
981
- snprintf(title, CHART_TITLE_MAX, "CPU Usage Per Core for cgroup %s", cg->chart_id);
991
+ snprintf(title, CHART_TITLE_MAX, "CPU Usage Per Core for cgroup %s", cg->chart_title);
992
st = rrdset_create(type, "cpu_per_core", NULL, "cpu", "cgroup.cpu_per_core", title, "%", 40100, update_every, RRDSET_TYPE_STACKED);
993
994
for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
@@ -999,7 +1009,7 @@ void update_cgroup_charts(int update_every) {
1009
if(cg->memory.cache + cg->memory.rss + cg->memory.rss_huge + cg->memory.mapped_file > 0) {
1010
st = rrdset_find_bytype(type, "mem");
1011
if(!st) {
1002
- snprintf(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_id);
1012
+ snprintf(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_title);
1013
st = rrdset_create(type, "mem", NULL, "mem", "cgroup.mem", title, "MB", 40200, update_every,
1014
RRDSET_TYPE_STACKED);
1015
@@ -1023,7 +1033,7 @@ void update_cgroup_charts(int update_every) {
1033
1034
st = rrdset_find_bytype(type, "writeback");
1035
if(!st) {
1026
- snprintf(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_id);
1036
+ snprintf(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_title);
1037
st = rrdset_create(type, "writeback", NULL, "mem", "cgroup.writeback", title, "MB", 40300,
1038
update_every, RRDSET_TYPE_AREA);
1039
@@ -1041,7 +1051,7 @@ void update_cgroup_charts(int update_every) {
1051
if(cg->memory.pgpgin + cg->memory.pgpgout > 0) {
1052
st = rrdset_find_bytype(type, "mem_activity");
1053
if(!st) {
1044
- snprintf(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_id);
1054
+ snprintf(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_title);
1055
st = rrdset_create(type, "mem_activity", NULL, "mem", "cgroup.mem_activity", title, "MB/s",
1056
40400, update_every, RRDSET_TYPE_LINE);
1057
@@ -1058,7 +1068,7 @@ void update_cgroup_charts(int update_every) {
1068
if(cg->memory.pgfault + cg->memory.pgmajfault > 0) {
1069
st = rrdset_find_bytype(type, "pgfaults");
1070
if(!st) {
1061
- snprintf(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_id);
1071
+ snprintf(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_title);
1072
st = rrdset_create(type, "pgfaults", NULL, "mem", "cgroup.pgfaults", title, "MB/s", 40500,
1073
update_every, RRDSET_TYPE_LINE);
1074
@@ -1076,7 +1086,7 @@ void update_cgroup_charts(int update_every) {
1086
if(cg->io_service_bytes.updated && cg->io_service_bytes.Read + cg->io_service_bytes.Write > 0) {
1087
st = rrdset_find_bytype(type, "io");
1088
if(!st) {
1079
- snprintf(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_id);
1089
+ snprintf(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1090
st = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200,
1091
update_every, RRDSET_TYPE_LINE);
1092
@@ -1093,7 +1103,7 @@ void update_cgroup_charts(int update_every) {
1103
if(cg->io_serviced.updated && cg->io_serviced.Read + cg->io_serviced.Write > 0) {
1104
st = rrdset_find_bytype(type, "serviced_ops");
1105
if(!st) {
1096
- snprintf(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_id);
1106
+ snprintf(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1107
st = rrdset_create(type, "serviced_ops", NULL, "disk", "cgroup.serviced_ops", title, "operations/s", 41200,
1108
update_every, RRDSET_TYPE_LINE);
1109
@@ -1110,7 +1120,7 @@ void update_cgroup_charts(int update_every) {
1120
if(cg->throttle_io_service_bytes.updated && cg->throttle_io_service_bytes.Read + cg->throttle_io_service_bytes.Write > 0) {
1121
st = rrdset_find_bytype(type, "io");
1122
if(!st) {
1113
- snprintf(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_id);
1123
+ snprintf(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1124
st = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200,
1125
update_every, RRDSET_TYPE_LINE);
1126
@@ -1128,7 +1138,7 @@ void update_cgroup_charts(int update_every) {
1138
if(cg->throttle_io_serviced.updated && cg->throttle_io_serviced.Read + cg->throttle_io_serviced.Write > 0) {
1139
st = rrdset_find_bytype(type, "throttle_serviced_ops");
1140
if(!st) {
1131
- snprintf(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_id);
1141
+ snprintf(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1142
st = rrdset_create(type, "throttle_serviced_ops", NULL, "disk", "cgroup.throttle_serviced_ops", title, "operations/s", 41200,
1143
update_every, RRDSET_TYPE_LINE);
1144
@@ -1145,7 +1155,7 @@ void update_cgroup_charts(int update_every) {
1155
if(cg->io_queued.updated) {
1156
st = rrdset_find_bytype(type, "queued_ops");
1157
if(!st) {
1148
- snprintf(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_id);
1158
+ snprintf(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_title);
1159
st = rrdset_create(type, "queued_ops", NULL, "disk", "cgroup.queued_ops", title, "operations", 42000,
1160
update_every, RRDSET_TYPE_LINE);
1161
@@ -1162,7 +1172,7 @@ void update_cgroup_charts(int update_every) {
1172
if(cg->io_merged.updated && cg->io_merged.Read + cg->io_merged.Write > 0) {
1173
st = rrdset_find_bytype(type, "merged_ops");
1174
if(!st) {
1165
- snprintf(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_id);
1175
+ snprintf(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_title);
1176
st = rrdset_create(type, "merged_ops", NULL, "disk", "cgroup.merged_ops", title, "operations/s", 42100,
1177
update_every, RRDSET_TYPE_LINE);
1178