diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-08-12 07:26:11 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-08-12 07:26:11 +0000 |
commit | 3c315f0fff93aa072472abc10815963ac0035268 (patch) | |
tree | a95f6a96e0e7bd139c010f8dc60b40e5b3062a99 /collectors/cgroups.plugin | |
parent | Adding upstream version 1.35.1. (diff) | |
download | netdata-3c315f0fff93aa072472abc10815963ac0035268.tar.xz netdata-3c315f0fff93aa072472abc10815963ac0035268.zip |
Adding upstream version 1.36.0.upstream/1.36.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'collectors/cgroups.plugin')
-rwxr-xr-x | collectors/cgroups.plugin/cgroup-name.sh | 54 | ||||
-rw-r--r-- | collectors/cgroups.plugin/sys_fs_cgroup.c | 303 | ||||
-rw-r--r-- | collectors/cgroups.plugin/sys_fs_cgroup.h | 2 | ||||
-rw-r--r-- | collectors/cgroups.plugin/tests/test_cgroups_plugin.c | 87 | ||||
-rw-r--r-- | collectors/cgroups.plugin/tests/test_doubles.c | 29 |
5 files changed, 272 insertions, 203 deletions
diff --git a/collectors/cgroups.plugin/cgroup-name.sh b/collectors/cgroups.plugin/cgroup-name.sh index 00d7e614c..d1277b745 100755 --- a/collectors/cgroups.plugin/cgroup-name.sh +++ b/collectors/cgroups.plugin/cgroup-name.sh @@ -45,11 +45,24 @@ fatal() { exit 1 } +function parse_docker_like_inspect_output() { + local output="${1}" + eval "$(grep -E "^(NOMAD_NAMESPACE|NOMAD_JOB_NAME|NOMAD_TASK_NAME|NOMAD_SHORT_ALLOC_ID|CONT_NAME)=" <<<"$output")" + if [ -n "$NOMAD_NAMESPACE" ] && [ -n "$NOMAD_JOB_NAME" ] && [ -n "$NOMAD_TASK_NAME" ] && [ -n "$NOMAD_SHORT_ALLOC_ID" ]; then + echo "${NOMAD_NAMESPACE}-${NOMAD_JOB_NAME}-${NOMAD_TASK_NAME}-${NOMAD_SHORT_ALLOC_ID}" + else + echo "${CONT_NAME}" | sed 's|^/||' + fi +} + function docker_like_get_name_command() { local command="${1}" local id="${2}" - info "Running command: ${command} ps --filter=id=\"${id}\" --format=\"{{.Names}}\"" - NAME="$(${command} ps --filter=id="${id}" --format="{{.Names}}")" + info "Running command: ${command} inspect --format='{{range .Config.Env}}{{println .}}{{end}}CONT_NAME={{ .Name}}' \"${id}\"" + if OUTPUT="$(${command} inspect --format='{{range .Config.Env}}{{println .}}{{end}}CONT_NAME={{ .Name}}' "${id}")" && + [ -n "$OUTPUT" ]; then + NAME="$(parse_docker_like_inspect_output "$OUTPUT")" + fi return 0 } @@ -61,7 +74,7 @@ function docker_like_get_name_api() { warning "No ${host_var} is set" return 1 fi - if ! command -v jq > /dev/null 2>&1; then + if ! command -v jq >/dev/null 2>&1; then warning "Can't find jq command line tool. jq is required for netdata to retrieve container name using ${host} API, falling back to docker ps" return 1 fi @@ -72,7 +85,9 @@ function docker_like_get_name_api() { info "Running API command: curl \"${host}${path}\"" JSON=$(curl -sS "${host}${path}") fi - NAME=$(echo "${JSON}" | jq -r .Name,.Config.Hostname | grep -v null | head -n1 | sed 's|^/||') + if OUTPUT=$(echo "${JSON}" | jq -r '.Config.Env[],"CONT_NAME=\(.Name)"') && [ -n "$OUTPUT" ]; then + NAME="$(parse_docker_like_inspect_output "$OUTPUT")" + fi return 0 } @@ -185,6 +200,13 @@ function k8s_get_kubepod_name() { # | | |-- kubepods-besteffort-pod10fb5647_c724_400c_b9cc_0e6eae3110e7.slice # | | | |-- docker-36e5eb5056dfdf6dbb75c0c44a1ecf23217fe2c50d606209d8130fcbb19fb5a7.scope # + # kind v0.14.0 + # |-- kubelet.slice + # | |-- kubelet-kubepods.slice + # | | |-- kubelet-kubepods-besteffort.slice + # | | | |-- kubelet-kubepods-besteffort-pod7881ed9e_c63e_4425_b5e0_ac55a08ae939.slice + # | | | | |-- cri-containerd-00c7939458bffc416bb03451526e9fde13301d6654cfeadf5b4964a7fb5be1a9.scope + # # NOTE: cgroups plugin # - uses '_' to join dir names (so it is <parent>_<child>_<child>_...) # - replaces '.' with '-' @@ -193,7 +215,7 @@ function k8s_get_kubepod_name() { local cgroup_path="${1}" local id="${2}" - if [[ ! $id =~ ^kubepods ]]; then + if [[ ! $id =~ ^.*kubepods.* ]]; then warning "${fn}: '${id}' is not kubepod cgroup." return 1 fi @@ -371,7 +393,7 @@ function k8s_get_kubepod_name() { name+="_$(get_lbl_val "$labels" pod_name)" labels=$(add_lbl_prefix "$labels" "k8s_") name+=" $labels" - else + else return 2 fi fi @@ -393,7 +415,7 @@ function k8s_get_name() { local id="${2}" NAME=$(k8s_get_kubepod_name "$cgroup_path" "$id") - + case "$?" in 0) NAME="k8s_${NAME}" @@ -511,6 +533,11 @@ if [ -z "${NAME}" ]; then #shellcheck disable=SC1117 DOCKERID="$(echo "${CGROUP}" | sed "s|^.*ecs[-_/].*[-_/]\([a-fA-F0-9]\+\)[-_\.]\?.*$|\1|")" docker_validate_id "${DOCKERID}" + elif [[ ${CGROUP} =~ system.slice_containerd.service_cpuset_[a-fA-F0-9]+[-_\.]?.*$ ]]; then + # docker containers under containerd + #shellcheck disable=SC1117 + DOCKERID="$(echo "${CGROUP}" | sed "s|^.*ystem.slice_containerd.service_cpuset_\([a-fA-F0-9]\+\)[-_\.]\?.*$|\1|")" + docker_validate_id "${DOCKERID}" elif [[ ${CGROUP} =~ ^.*libpod-[a-fA-F0-9]+.*$ ]]; then # Podman PODMANID="$(echo "${CGROUP}" | sed "s|^.*libpod-\([a-fA-F0-9]\+\).*$|\1|")" @@ -522,16 +549,13 @@ if [ -z "${NAME}" ]; then elif [[ ${CGROUP} =~ machine.slice_machine.*-lxc ]]; then # libvirtd / lxc containers - # examples: - # before: machine.slice machine-lxc/x2d969/x2dhubud0xians01.scope - # after: lxc/hubud0xians01 - # before: machine.slice_machine-lxc/x2d969/x2dhubud0xians01.scope/libvirt_init.scope - # after: lxc/hubud0xians01/libvirt_init - NAME="lxc/$(echo "${CGROUP}" | sed 's/machine.slice_machine.*-lxc//; s/\/x2d[[:digit:]]*//; s/\/x2d//g; s/\.scope//g')" + # machine.slice machine-lxc/x2d969/x2dhubud0xians01.scope => lxc/hubud0xians01 + # machine.slice_machine-lxc/x2d969/x2dhubud0xians01.scope/libvirt_init.scope => lxc/hubud0xians01/libvirt_init + NAME="lxc/$(echo "${CGROUP}" | sed 's/machine.slice_machine.*-lxc//; s/[\/_]x2d[[:digit:]]*//; s/[\/_]x2d//g; s/\.scope//g')" elif [[ ${CGROUP} =~ machine.slice_machine.*-qemu ]]; then # libvirtd / qemu virtual machines - # NAME="$(echo ${CGROUP} | sed 's/machine.slice_machine.*-qemu//; s/\/x2d//; s/\/x2d/\-/g; s/\.scope//g')" - NAME="qemu_$(echo "${CGROUP}" | sed 's/machine.slice_machine.*-qemu//; s/\/x2d[[:digit:]]*//; s/\/x2d//g; s/\.scope//g')" + # machine.slice_machine-qemu_x2d1_x2dopnsense.scope => qemu_opnsense + NAME="qemu_$(echo "${CGROUP}" | sed 's/machine.slice_machine.*-qemu//; s/[\/_]x2d[[:digit:]]*//; s/[\/_]x2d//g; s/\.scope//g')" elif [[ ${CGROUP} =~ machine_.*\.libvirt-qemu ]]; then # libvirtd / qemu virtual machines diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.c b/collectors/cgroups.plugin/sys_fs_cgroup.c index 5676ef8ca..330562173 100644 --- a/collectors/cgroups.plugin/sys_fs_cgroup.c +++ b/collectors/cgroups.plugin/sys_fs_cgroup.c @@ -6,6 +6,12 @@ #define PLUGIN_CGROUPS_MODULE_SYSTEMD_NAME "systemd" #define PLUGIN_CGROUPS_MODULE_CGROUPS_NAME "/sys/fs/cgroup" +#ifdef NETDATA_INTERNAL_CHECKS +#define CGROUP_PROCFILE_FLAG PROCFILE_FLAG_DEFAULT +#else +#define CGROUP_PROCFILE_FLAG PROCFILE_FLAG_NO_ERROR_ON_FILE_IO +#endif + // main cgroups thread worker jobs #define WORKER_CGROUPS_LOCK 0 #define WORKER_CGROUPS_READ 1 @@ -446,12 +452,17 @@ void read_cgroup_plugin_configuration() { // ---------------------------------------------------------------- " /machine.slice/*.service " // #3367 systemd-nspawn - " /kubepods/pod*/* " // k8s containers - " /kubepods/*/pod*/* " // k8s containers // ---------------------------------------------------------------- - " !/kubepods* " // all other k8s cgroups + " */kubepods/pod*/* " // k8s containers + " */kubepods/*/pod*/* " // k8s containers + " */*-kubepods-pod*/* " // k8s containers + " */*-kubepods-*-pod*/* " // k8s containers + " !*kubepods* !*kubelet* " // all other k8s cgroups + + // ---------------------------------------------------------------- + " !*/vcpu* " // libvirtd adds these sub-cgroups " !*/emulator " // libvirtd adds these sub-cgroups " !*.mount " @@ -523,9 +534,11 @@ void read_cgroup_plugin_configuration() { " *docker* " " *lxc* " " *qemu* " - " /kubepods/pod*/* " // k8s containers - " /kubepods/*/pod*/* " // k8s containers - " !/kubepods* " // all other k8s cgroups + " */kubepods/pod*/* " // k8s containers + " */kubepods/*/pod*/* " // k8s containers + " */*-kubepods-pod*/* " // k8s containers + " */*-kubepods-*-pod*/* " // k8s containers + " !*kubepods* !*kubelet* " // all other k8s cgroups " *.libvirt-qemu " // #3010 " * " ), NULL, SIMPLE_PATTERN_EXACT); @@ -755,6 +768,12 @@ struct cgroup_network_interface { struct cgroup_network_interface *next; }; +enum cgroups_container_orchestrator { + CGROUPS_ORCHESTRATOR_UNSET, + CGROUPS_ORCHESTRATOR_UNKNOWN, + CGROUPS_ORCHESTRATOR_K8S +}; + // *** WARNING *** The fields are not thread safe. Take care of safe usage. struct cgroup { uint32_t options; @@ -776,7 +795,9 @@ struct cgroup { char *chart_title; - struct label *chart_labels; + DICTIONARY *chart_labels; + + int container_orchestrator; struct cpuacct_stat cpuacct_stat; struct cpuacct_usage cpuacct_usage; @@ -835,7 +856,7 @@ struct cgroup { unsigned long long cpu_cfs_quota; RRDSETVAR *chart_var_cpu_limit; - calculated_number prev_cpu_usage; + NETDATA_DOUBLE prev_cpu_usage; char *filename_memory_limit; unsigned long long memory_limit; @@ -922,6 +943,10 @@ static inline int is_cgroup_systemd_service(struct cgroup *cg) { } // --------------------------------------------------------------------------------------------- +static int k8s_is_kubepod(struct cgroup *cg) { + return cg->container_orchestrator == CGROUPS_ORCHESTRATOR_K8S; +} + static int k8s_is_container(const char *id) { // examples: // https://github.com/netdata/netdata/blob/0fc101679dcd12f1cb8acdd07bb4c85d8e553e53/collectors/cgroups.plugin/cgroup-name.sh#L121-L147 @@ -949,7 +974,7 @@ static int k8s_get_container_first_proc_comm(const char *id, char *comm) { char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/%s/cgroup.procs", cgroup_cpuacct_base, id); - ff = procfile_reopen(ff, filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, filename, NULL, CGROUP_PROCFILE_FLAG); if (unlikely(!ff)) { debug(D_CGROUP, "CGROUP: k8s_is_pause_container(): cannot open file '%s'.", filename); return 1; @@ -1012,7 +1037,7 @@ static unsigned long long calc_percentage(unsigned long long value, unsigned lon if (total == 0) { return 0; } - return (calculated_number)value / (calculated_number)total * 100; + return (NETDATA_DOUBLE)value / (NETDATA_DOUBLE)total * 100; } static int calc_cgroup_depth(const char *id) { @@ -1031,7 +1056,7 @@ static inline void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) { static procfile *ff = NULL; if(likely(cp->filename)) { - ff = procfile_reopen(ff, cp->filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, cp->filename, NULL, CGROUP_PROCFILE_FLAG); if(unlikely(!ff)) { cp->updated = 0; cgroups_check = 1; @@ -1078,7 +1103,7 @@ static inline void cgroup_read_cpuacct_cpu_stat(struct cpuacct_cpu_throttling *c } static procfile *ff = NULL; - ff = procfile_reopen(ff, cp->filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, cp->filename, NULL, CGROUP_PROCFILE_FLAG); if (unlikely(!ff)) { cp->updated = 0; cgroups_check = 1; @@ -1134,7 +1159,7 @@ static inline void cgroup2_read_cpuacct_cpu_stat(struct cpuacct_stat *cp, struct return; } - ff = procfile_reopen(ff, cp->filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, cp->filename, NULL, CGROUP_PROCFILE_FLAG); if (unlikely(!ff)) { cp->updated = 0; cgroups_check = 1; @@ -1217,7 +1242,7 @@ static inline void cgroup_read_cpuacct_usage(struct cpuacct_usage *ca) { static procfile *ff = NULL; if(likely(ca->filename)) { - ff = procfile_reopen(ff, ca->filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, ca->filename, NULL, CGROUP_PROCFILE_FLAG); if(unlikely(!ff)) { ca->updated = 0; cgroups_check = 1; @@ -1280,7 +1305,7 @@ static inline void cgroup_read_blkio(struct blkio *io) { if(likely(io->filename)) { static procfile *ff = NULL; - ff = procfile_reopen(ff, io->filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, io->filename, NULL, CGROUP_PROCFILE_FLAG); if(unlikely(!ff)) { io->updated = 0; cgroups_check = 1; @@ -1352,7 +1377,7 @@ static inline void cgroup2_read_blkio(struct blkio *io, unsigned int word_offset if(likely(io->filename)) { static procfile *ff = NULL; - ff = procfile_reopen(ff, io->filename, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, io->filename, NULL, CGROUP_PROCFILE_FLAG); if(unlikely(!ff)) { io->updated = 0; cgroups_check = 1; @@ -1397,7 +1422,7 @@ static inline void cgroup2_read_pressure(struct pressure *res) { static procfile *ff = NULL; if (likely(res->filename)) { - ff = procfile_reopen(ff, res->filename, " =", PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, res->filename, " =", CGROUP_PROCFILE_FLAG); if (unlikely(!ff)) { res->updated = 0; cgroups_check = 1; @@ -1454,7 +1479,7 @@ static inline void cgroup_read_memory(struct memory *mem, char parent_cg_is_unif goto memory_next; } - ff = procfile_reopen(ff, mem->filename_detailed, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, mem->filename_detailed, NULL, CGROUP_PROCFILE_FLAG); if(unlikely(!ff)) { mem->updated_detailed = 0; cgroups_check = 1; @@ -1677,7 +1702,8 @@ static inline void read_cgroup_network_interfaces(struct cgroup *cg) { info("CGROUP: cgroup '%s' has network interface '%s' as '%s'", cg->id, i->host_device, i->container_device); // register a device rename to proc_net_dev.c - netdev_rename_device_add(i->host_device, i->container_device, cg->chart_id, cg->chart_labels); + netdev_rename_device_add( + i->host_device, i->container_device, cg->chart_id, cg->chart_labels, k8s_is_kubepod(cg) ? "k8s." : ""); } } @@ -1735,34 +1761,24 @@ static inline void substitute_dots_in_id(char *s) { } } -char *k8s_parse_resolved_name(struct label **labels, char *data) { - char *name = mystrsep(&data, " "); - - if (!data) { - return name; - } - - while (data) { - char *key = mystrsep(&data, "="); - - char *value; - if (data && *data == ',') { - value = ""; - *data++ = '\0'; - } else { - value = mystrsep(&data, ","); - } - value = strip_double_quotes(value, 1); +// ---------------------------------------------------------------------------- +// parse k8s labels - if (!key || *key == '\0' || !value || *value == '\0') - continue; +char *k8s_parse_resolved_name_and_labels(DICTIONARY *labels, char *data) { + // the first word, up to the first space is the name + char *name = mystrsep(&data, " "); - *labels = add_label_to_list(*labels, key, value, LABEL_SOURCE_KUBERNETES); + // the rest are key=value pairs separated by comma + while(data) { + char *pair = mystrsep(&data, ","); + rrdlabels_add_pair(labels, pair, RRDLABEL_SRC_AUTO| RRDLABEL_SRC_K8S); } return name; } +// ---------------------------------------------------------------------------- + static inline void free_pressure(struct pressure *res) { if (res->some.share_time.st) rrdset_is_obsolete(res->some.share_time.st); if (res->some.total_time.st) rrdset_is_obsolete(res->some.total_time.st); @@ -1834,7 +1850,7 @@ static inline void cgroup_free(struct cgroup *cg) { freez(cg->chart_id); freez(cg->chart_title); - free_label_list(cg->chart_labels); + rrdlabels_destroy(cg->chart_labels); freez(cg); @@ -1870,31 +1886,33 @@ static inline void discovery_rename_cgroup(struct cgroup *cg) { case 0: cg->pending_renames = 0; break; + case 3: cg->pending_renames = 0; cg->processed = 1; break; } - if (cg->pending_renames || cg->processed) { - return; - } - if (!(new_name && *new_name && *new_name != '\n')) { - return; - } - new_name = trim(new_name); - if (!(new_name)) { - return; - } + if(cg->pending_renames || cg->processed) return; + if(!new_name || !*new_name || *new_name == '\n') return; + if(!(new_name = trim(new_name))) return; + char *name = new_name; if (!strncmp(new_name, "k8s_", 4)) { - free_label_list(cg->chart_labels); - name = k8s_parse_resolved_name(&cg->chart_labels, new_name); + if(!cg->chart_labels) cg->chart_labels = rrdlabels_create(); + + // read the new labels and remove the obsolete ones + rrdlabels_unmark_all(cg->chart_labels); + name = k8s_parse_resolved_name_and_labels(cg->chart_labels, new_name); + rrdlabels_remove_all_unmarked(cg->chart_labels); } + freez(cg->chart_title); cg->chart_title = cgroup_title_strdupz(name); + freez(cg->chart_id); cg->chart_id = cgroup_chart_id_strdupz(name); + substitute_dots_in_id(cg->chart_id); cg->hash_chart = simple_hash(cg->chart_id); } @@ -2584,6 +2602,14 @@ static inline void discovery_process_first_time_seen_cgroup(struct cgroup *cg) { char comm[TASK_COMM_LEN]; + if (cg->container_orchestrator == CGROUPS_ORCHESTRATOR_UNSET) { + if (strstr(cg->id, "kubepods")) { + cg->container_orchestrator = CGROUPS_ORCHESTRATOR_K8S; + } else { + cg->container_orchestrator = CGROUPS_ORCHESTRATOR_UNKNOWN; + } + } + if (is_inside_k8s && !k8s_get_container_first_proc_comm(cg->id, comm)) { // container initialization may take some time when CPU % is high // seen on GKE: comm is '6' before 'runc:[2:INIT]' (dunno if it could be another number) @@ -2656,6 +2682,11 @@ static inline void discovery_process_cgroup(struct cgroup *cg) { cg->processed = 1; + if (strlen(cg->chart_id) >= RRD_ID_LENGTH_MAX) { + info("cgroup '%s' (chart id '%s') disabled because chart_id exceeds the limit (RRD_ID_LENGTH_MAX)", cg->id, cg->chart_id); + return; + } + if (is_cgroup_systemd_service(cg)) { cg->enabled = 1; return; @@ -3638,7 +3669,7 @@ static inline void update_cpu_limits2(struct cgroup *cg) { if(cg->filename_cpu_cfs_quota){ static procfile *ff = NULL; - ff = procfile_reopen(ff, cg->filename_cpu_cfs_quota, NULL, PROCFILE_FLAG_DEFAULT); + ff = procfile_reopen(ff, cg->filename_cpu_cfs_quota, NULL, CGROUP_PROCFILE_FLAG); if(unlikely(!ff)) { goto cpu_limits2_err; } @@ -3694,7 +3725,7 @@ static inline int update_memory_limits(char **filename, RRDSETVAR **chart_var, u *filename = NULL; } else { - rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024))); + rrdsetvar_custom_chart_variable_set(*chart_var, (NETDATA_DOUBLE)(*value / (1024 * 1024))); return 1; } } else { @@ -3709,11 +3740,11 @@ static inline int update_memory_limits(char **filename, RRDSETVAR **chart_var, u char *s = "max\n\0"; if(strcmp(s, buffer) == 0){ *value = UINT64_MAX; - rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024))); + rrdsetvar_custom_chart_variable_set(*chart_var, (NETDATA_DOUBLE)(*value / (1024 * 1024))); return 1; } *value = str2ull(buffer); - rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024))); + rrdsetvar_custom_chart_variable_set(*chart_var, (NETDATA_DOUBLE)(*value / (1024 * 1024))); return 1; } } @@ -3772,7 +3803,7 @@ void update_cgroup_charts(int update_every) { , "cpu" , NULL , "cpu" - , "cgroup.cpu" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu" : "cgroup.cpu" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -3782,7 +3813,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_STACKED ); - rrdset_update_labels(cg->st_cpu, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_cpu, cg->chart_labels); if(!(cg->options & CGROUP_OPTIONS_IS_UNIFIED)) { rrddim_add(cg->st_cpu, "user", NULL, 100, system_hz, RRD_ALGORITHM_INCREMENTAL); @@ -3822,17 +3853,17 @@ void update_cgroup_charts(int update_every) { } } else { - calculated_number value = 0, quota = 0; + NETDATA_DOUBLE value = 0, quota = 0; if(likely( ((!(cg->options & CGROUP_OPTIONS_IS_UNIFIED)) && (cg->filename_cpuset_cpus || (cg->filename_cpu_cfs_period && cg->filename_cpu_cfs_quota))) || ((cg->options & CGROUP_OPTIONS_IS_UNIFIED) && cg->filename_cpu_cfs_quota))) { if(unlikely(cg->cpu_cfs_quota > 0)) - quota = (calculated_number)cg->cpu_cfs_quota / (calculated_number)cg->cpu_cfs_period; + quota = (NETDATA_DOUBLE)cg->cpu_cfs_quota / (NETDATA_DOUBLE)cg->cpu_cfs_period; if(unlikely(quota > 0 && quota < cg->cpuset_cpus)) value = quota * 100; else - value = (calculated_number)cg->cpuset_cpus * 100; + value = (NETDATA_DOUBLE)cg->cpuset_cpus * 100; } if(likely(value)) { rrdsetvar_custom_chart_variable_set(cg->chart_var_cpu_limit, value); @@ -3845,7 +3876,7 @@ void update_cgroup_charts(int update_every) { , "cpu_limit" , NULL , "cpu" - , "cgroup.cpu_limit" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_limit" : "cgroup.cpu_limit" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -3855,20 +3886,20 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_cpu_limit, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_cpu_limit, cg->chart_labels); if(!(cg->options & CGROUP_OPTIONS_IS_UNIFIED)) rrddim_add(cg->st_cpu_limit, "used", NULL, 1, system_hz, RRD_ALGORITHM_ABSOLUTE); else rrddim_add(cg->st_cpu_limit, "used", NULL, 1, 1000000, RRD_ALGORITHM_ABSOLUTE); - cg->prev_cpu_usage = (calculated_number)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100; + cg->prev_cpu_usage = (NETDATA_DOUBLE)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100; } else rrdset_next(cg->st_cpu_limit); - calculated_number cpu_usage = 0; - cpu_usage = (calculated_number)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100; - calculated_number cpu_used = 100 * (cpu_usage - cg->prev_cpu_usage) / (value * update_every); + NETDATA_DOUBLE cpu_usage = 0; + cpu_usage = (NETDATA_DOUBLE)(cg->cpuacct_stat.user + cg->cpuacct_stat.system) * 100; + NETDATA_DOUBLE cpu_used = 100 * (cpu_usage - cg->prev_cpu_usage) / (value * update_every); rrdset_isnot_obsolete(cg->st_cpu_limit); @@ -3898,7 +3929,7 @@ void update_cgroup_charts(int update_every) { , "throttled" , NULL , "cpu" - , "cgroup.throttled" + , k8s_is_kubepod(cg) ? "k8s.cgroup.throttled" : "cgroup.throttled" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -3908,7 +3939,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_cpu_nr_throttled, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_cpu_nr_throttled, cg->chart_labels); rrddim_add(cg->st_cpu_nr_throttled, "throttled", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else { rrdset_next(cg->st_cpu_nr_throttled); @@ -3924,7 +3955,7 @@ void update_cgroup_charts(int update_every) { , "throttled_duration" , NULL , "cpu" - , "cgroup.throttled_duration" + , k8s_is_kubepod(cg) ? "k8s.cgroup.throttled_duration" : "cgroup.throttled_duration" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -3934,7 +3965,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_cpu_throttled_time, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_cpu_throttled_time, cg->chart_labels); rrddim_add(cg->st_cpu_throttled_time, "duration", NULL, 1, 1000000, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(cg->st_cpu_throttled_time); @@ -3952,7 +3983,7 @@ void update_cgroup_charts(int update_every) { , "cpu_shares" , NULL , "cpu" - , "cgroup.cpu_shares" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_shares" : "cgroup.cpu_shares" , title , "shares" , PLUGIN_CGROUPS_NAME @@ -3962,7 +3993,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_cpu_shares, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_cpu_shares, cg->chart_labels); rrddim_add(cg->st_cpu_shares, "shares", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else { rrdset_next(cg->st_cpu_shares); @@ -3983,7 +4014,7 @@ void update_cgroup_charts(int update_every) { , "cpu_per_core" , NULL , "cpu" - , "cgroup.cpu_per_core" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_per_core" : "cgroup.cpu_per_core" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -3993,7 +4024,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_STACKED ); - rrdset_update_labels(cg->st_cpu_per_core, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_cpu_per_core, cg->chart_labels); for(i = 0; i < cg->cpuacct_usage.cpus; i++) { snprintfz(id, RRD_ID_LENGTH_MAX, "cpu%u", i); @@ -4019,7 +4050,7 @@ void update_cgroup_charts(int update_every) { , "mem" , NULL , "mem" - , "cgroup.mem" + , k8s_is_kubepod(cg) ? "k8s.cgroup.mem" : "cgroup.mem" , title , "MiB" , PLUGIN_CGROUPS_NAME @@ -4028,8 +4059,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_STACKED ); - - rrdset_update_labels(cg->st_mem, cg->chart_labels); + + rrdset_update_rrdlabels(cg->st_mem, cg->chart_labels); if(!(cg->options & CGROUP_OPTIONS_IS_UNIFIED)) { rrddim_add(cg->st_mem, "cache", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); @@ -4079,7 +4110,7 @@ void update_cgroup_charts(int update_every) { , "writeback" , NULL , "mem" - , "cgroup.writeback" + , k8s_is_kubepod(cg) ? "k8s.cgroup.writeback" : "cgroup.writeback" , title , "MiB" , PLUGIN_CGROUPS_NAME @@ -4089,7 +4120,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_AREA ); - rrdset_update_labels(cg->st_writeback, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_writeback, cg->chart_labels); if(cg->memory.detailed_has_dirty) rrddim_add(cg->st_writeback, "dirty", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); @@ -4114,7 +4145,7 @@ void update_cgroup_charts(int update_every) { , "mem_activity" , NULL , "mem" - , "cgroup.mem_activity" + , k8s_is_kubepod(cg) ? "k8s.cgroup.mem_activity" : "cgroup.mem_activity" , title , "MiB/s" , PLUGIN_CGROUPS_NAME @@ -4124,7 +4155,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_mem_activity, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_mem_activity, cg->chart_labels); rrddim_add(cg->st_mem_activity, "pgpgin", "in", system_page_size, 1024 * 1024, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_mem_activity, "pgpgout", "out", -system_page_size, 1024 * 1024, RRD_ALGORITHM_INCREMENTAL); @@ -4145,7 +4176,7 @@ void update_cgroup_charts(int update_every) { , "pgfaults" , NULL , "mem" - , "cgroup.pgfaults" + , k8s_is_kubepod(cg) ? "k8s.cgroup.pgfaults" : "cgroup.pgfaults" , title , "MiB/s" , PLUGIN_CGROUPS_NAME @@ -4155,7 +4186,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_pgfaults, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_pgfaults, cg->chart_labels); rrddim_add(cg->st_pgfaults, "pgfault", NULL, system_page_size, 1024 * 1024, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_pgfaults, "pgmajfault", "swap", -system_page_size, 1024 * 1024, RRD_ALGORITHM_INCREMENTAL); @@ -4177,7 +4208,7 @@ void update_cgroup_charts(int update_every) { , "mem_usage" , NULL , "mem" - , "cgroup.mem_usage" + , k8s_is_kubepod(cg) ? "k8s.cgroup.mem_usage" : "cgroup.mem_usage" , title , "MiB" , PLUGIN_CGROUPS_NAME @@ -4187,7 +4218,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_STACKED ); - rrdset_update_labels(cg->st_mem_usage, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_mem_usage, cg->chart_labels); rrddim_add(cg->st_mem_usage, "ram", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); rrddim_add(cg->st_mem_usage, "swap", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); @@ -4244,7 +4275,7 @@ void update_cgroup_charts(int update_every) { , "mem_usage_limit" , NULL , "mem" - , "cgroup.mem_usage_limit" + , k8s_is_kubepod(cg) ? "k8s.cgroup.mem_usage_limit": "cgroup.mem_usage_limit" , title , "MiB" , PLUGIN_CGROUPS_NAME @@ -4254,7 +4285,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_STACKED ); - rrdset_update_labels(cg->st_mem_usage_limit, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_mem_usage_limit, cg->chart_labels); rrddim_add(cg->st_mem_usage_limit, "available", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); rrddim_add(cg->st_mem_usage_limit, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); @@ -4276,7 +4307,7 @@ void update_cgroup_charts(int update_every) { , "mem_utilization" , NULL , "mem" - , "cgroup.mem_utilization" + , k8s_is_kubepod(cg) ? "k8s.cgroup.mem_utilization" : "cgroup.mem_utilization" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4286,7 +4317,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_AREA ); - rrdset_update_labels(cg->st_mem_utilization, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_mem_utilization, cg->chart_labels); rrddim_add(cg->st_mem_utilization, "utilization", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } else @@ -4325,7 +4356,7 @@ void update_cgroup_charts(int update_every) { , "mem_failcnt" , NULL , "mem" - , "cgroup.mem_failcnt" + , k8s_is_kubepod(cg) ? "k8s.cgroup.mem_failcnt" : "cgroup.mem_failcnt" , title , "count" , PLUGIN_CGROUPS_NAME @@ -4334,8 +4365,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - - rrdset_update_labels(cg->st_mem_failcnt, cg->chart_labels); + + rrdset_update_rrdlabels(cg->st_mem_failcnt, cg->chart_labels); rrddim_add(cg->st_mem_failcnt, "failures", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } @@ -4355,7 +4386,7 @@ void update_cgroup_charts(int update_every) { , "io" , NULL , "disk" - , "cgroup.io" + , k8s_is_kubepod(cg) ? "k8s.cgroup.io" : "cgroup.io" , title , "KiB/s" , PLUGIN_CGROUPS_NAME @@ -4365,7 +4396,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_AREA ); - rrdset_update_labels(cg->st_io, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_io, cg->chart_labels); rrddim_add(cg->st_io, "read", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_io, "write", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL); @@ -4387,7 +4418,7 @@ void update_cgroup_charts(int update_every) { , "serviced_ops" , NULL , "disk" - , "cgroup.serviced_ops" + , k8s_is_kubepod(cg) ? "k8s.cgroup.serviced_ops" : "cgroup.serviced_ops" , title , "operations/s" , PLUGIN_CGROUPS_NAME @@ -4397,7 +4428,7 @@ void update_cgroup_charts(int update_every) { , RRDSET_TYPE_LINE ); - rrdset_update_labels(cg->st_serviced_ops, cg->chart_labels); + rrdset_update_rrdlabels(cg->st_serviced_ops, cg->chart_labels); rrddim_add(cg->st_serviced_ops, "read", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_serviced_ops, "write", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); @@ -4419,7 +4450,7 @@ void update_cgroup_charts(int update_every) { , "throttle_io" , NULL , "disk" - , "cgroup.throttle_io" + , k8s_is_kubepod(cg) ? "k8s.cgroup.throttle_io" : "cgroup.throttle_io" , title , "KiB/s" , PLUGIN_CGROUPS_NAME @@ -4428,8 +4459,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_AREA ); - - rrdset_update_labels(cg->st_throttle_io, cg->chart_labels); + + rrdset_update_rrdlabels(cg->st_throttle_io, cg->chart_labels); rrddim_add(cg->st_throttle_io, "read", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_throttle_io, "write", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL); @@ -4451,7 +4482,7 @@ void update_cgroup_charts(int update_every) { , "throttle_serviced_ops" , NULL , "disk" - , "cgroup.throttle_serviced_ops" + , k8s_is_kubepod(cg) ? "k8s.cgroup.throttle_serviced_ops" : "cgroup.throttle_serviced_ops" , title , "operations/s" , PLUGIN_CGROUPS_NAME @@ -4460,8 +4491,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - - rrdset_update_labels(cg->st_throttle_serviced_ops, cg->chart_labels); + + rrdset_update_rrdlabels(cg->st_throttle_serviced_ops, cg->chart_labels); rrddim_add(cg->st_throttle_serviced_ops, "read", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_throttle_serviced_ops, "write", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); @@ -4483,7 +4514,7 @@ void update_cgroup_charts(int update_every) { , "queued_ops" , NULL , "disk" - , "cgroup.queued_ops" + , k8s_is_kubepod(cg) ? "k8s.cgroup.queued_ops" : "cgroup.queued_ops" , title , "operations" , PLUGIN_CGROUPS_NAME @@ -4492,8 +4523,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - - rrdset_update_labels(cg->st_queued_ops, cg->chart_labels); + + rrdset_update_rrdlabels(cg->st_queued_ops, cg->chart_labels); rrddim_add(cg->st_queued_ops, "read", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rrddim_add(cg->st_queued_ops, "write", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -4515,7 +4546,7 @@ void update_cgroup_charts(int update_every) { , "merged_ops" , NULL , "disk" - , "cgroup.merged_ops" + , k8s_is_kubepod(cg) ? "k8s.cgroup.merged_ops" : "cgroup.merged_ops" , title , "operations/s" , PLUGIN_CGROUPS_NAME @@ -4524,8 +4555,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - - rrdset_update_labels(cg->st_merged_ops, cg->chart_labels); + + rrdset_update_rrdlabels(cg->st_merged_ops, cg->chart_labels); rrddim_add(cg->st_merged_ops, "read", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL); rrddim_add(cg->st_merged_ops, "write", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL); @@ -4553,7 +4584,7 @@ void update_cgroup_charts(int update_every) { , "cpu_some_pressure" , NULL , "cpu" - , "cgroup.cpu_some_pressure" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_some_pressure" : "cgroup.cpu_some_pressure" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4562,7 +4593,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->share_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->share_time.st, cg->chart_labels); pcs->share_time.rd10 = rrddim_add(chart, "some 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd60 = rrddim_add(chart, "some 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd300 = rrddim_add(chart, "some 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); @@ -4577,7 +4608,7 @@ void update_cgroup_charts(int update_every) { , "cpu_some_pressure_stall_time" , NULL , "cpu" - , "cgroup.cpu_some_pressure_stall_time" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_some_pressure_stall_time" : "cgroup.cpu_some_pressure_stall_time" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -4586,7 +4617,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->total_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->total_time.st, cg->chart_labels); pcs->total_time.rdtotal = rrddim_add(chart, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(pcs->total_time.st); @@ -4605,7 +4636,7 @@ void update_cgroup_charts(int update_every) { , "cpu_full_pressure" , NULL , "cpu" - , "cgroup.cpu_full_pressure" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_full_pressure" : "cgroup.cpu_full_pressure" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4614,7 +4645,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->share_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->share_time.st, cg->chart_labels); pcs->share_time.rd10 = rrddim_add(chart, "full 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd60 = rrddim_add(chart, "full 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd300 = rrddim_add(chart, "full 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); @@ -4629,7 +4660,7 @@ void update_cgroup_charts(int update_every) { , "cpu_full_pressure_stall_time" , NULL , "cpu" - , "cgroup.cpu_full_pressure_stall_time" + , k8s_is_kubepod(cg) ? "k8s.cgroup.cpu_full_pressure_stall_time" : "cgroup.cpu_full_pressure_stall_time" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -4638,7 +4669,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->total_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->total_time.st, cg->chart_labels); pcs->total_time.rdtotal = rrddim_add(chart, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(pcs->total_time.st); @@ -4660,7 +4691,7 @@ void update_cgroup_charts(int update_every) { , "mem_some_pressure" , NULL , "mem" - , "cgroup.memory_some_pressure" + , k8s_is_kubepod(cg) ? "k8s.cgroup.memory_some_pressure" : "cgroup.memory_some_pressure" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4668,8 +4699,8 @@ void update_cgroup_charts(int update_every) { , cgroup_containers_chart_priority + 2300 , update_every , RRDSET_TYPE_LINE - ); - rrdset_update_labels(chart = pcs->share_time.st, cg->chart_labels); + ); + rrdset_update_rrdlabels(chart = pcs->share_time.st, cg->chart_labels); pcs->share_time.rd10 = rrddim_add(chart, "some 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd60 = rrddim_add(chart, "some 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd300 = rrddim_add(chart, "some 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); @@ -4684,7 +4715,7 @@ void update_cgroup_charts(int update_every) { , "memory_some_pressure_stall_time" , NULL , "mem" - , "cgroup.memory_some_pressure_stall_time" + , k8s_is_kubepod(cg) ? "k8s.cgroup.memory_some_pressure_stall_time" : "cgroup.memory_some_pressure_stall_time" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -4693,7 +4724,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->total_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->total_time.st, cg->chart_labels); pcs->total_time.rdtotal = rrddim_add(chart, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(pcs->total_time.st); @@ -4714,7 +4745,7 @@ void update_cgroup_charts(int update_every) { , "mem_full_pressure" , NULL , "mem" - , "cgroup.memory_full_pressure" + , k8s_is_kubepod(cg) ? "k8s.cgroup.memory_full_pressure" : "cgroup.memory_full_pressure" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4723,8 +4754,8 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - - rrdset_update_labels(chart = pcs->share_time.st, cg->chart_labels); + + rrdset_update_rrdlabels(chart = pcs->share_time.st, cg->chart_labels); pcs->share_time.rd10 = rrddim_add(chart, "full 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd60 = rrddim_add(chart, "full 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd300 = rrddim_add(chart, "full 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); @@ -4739,7 +4770,7 @@ void update_cgroup_charts(int update_every) { , "memory_full_pressure_stall_time" , NULL , "mem" - , "cgroup.memory_full_pressure_stall_time" + , k8s_is_kubepod(cg) ? "k8s.cgroup.memory_full_pressure_stall_time" : "cgroup.memory_full_pressure_stall_time" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -4748,7 +4779,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->total_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->total_time.st, cg->chart_labels); pcs->total_time.rdtotal = rrddim_add(chart, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(pcs->total_time.st); @@ -4770,7 +4801,7 @@ void update_cgroup_charts(int update_every) { , "io_some_pressure" , NULL , "disk" - , "cgroup.io_some_pressure" + , k8s_is_kubepod(cg) ? "k8s.cgroup.io_some_pressure" : "cgroup.io_some_pressure" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4779,7 +4810,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->share_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->share_time.st, cg->chart_labels); pcs->share_time.rd10 = rrddim_add(chart, "some 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd60 = rrddim_add(chart, "some 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd300 = rrddim_add(chart, "some 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); @@ -4794,7 +4825,7 @@ void update_cgroup_charts(int update_every) { , "io_some_pressure_stall_time" , NULL , "disk" - , "cgroup.io_some_pressure_stall_time" + , k8s_is_kubepod(cg) ? "k8s.cgroup.io_some_pressure_stall_time" : "cgroup.io_some_pressure_stall_time" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -4803,7 +4834,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->total_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->total_time.st, cg->chart_labels); pcs->total_time.rdtotal = rrddim_add(chart, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(pcs->total_time.st); @@ -4823,7 +4854,7 @@ void update_cgroup_charts(int update_every) { , "io_full_pressure" , NULL , "disk" - , "cgroup.io_full_pressure" + , k8s_is_kubepod(cg) ? "k8s.cgroup.io_full_pressure" : "cgroup.io_full_pressure" , title , "percentage" , PLUGIN_CGROUPS_NAME @@ -4832,7 +4863,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->share_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->share_time.st, cg->chart_labels); pcs->share_time.rd10 = rrddim_add(chart, "full 10", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd60 = rrddim_add(chart, "full 60", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); pcs->share_time.rd300 = rrddim_add(chart, "full 300", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); @@ -4847,7 +4878,7 @@ void update_cgroup_charts(int update_every) { , "io_full_pressure_stall_time" , NULL , "disk" - , "cgroup.io_full_pressure_stall_time" + , k8s_is_kubepod(cg) ? "k8s.cgroup.io_full_pressure_stall_time" : "cgroup.io_full_pressure_stall_time" , title , "ms" , PLUGIN_CGROUPS_NAME @@ -4856,7 +4887,7 @@ void update_cgroup_charts(int update_every) { , update_every , RRDSET_TYPE_LINE ); - rrdset_update_labels(chart = pcs->total_time.st, cg->chart_labels); + rrdset_update_rrdlabels(chart = pcs->total_time.st, cg->chart_labels); pcs->total_time.rdtotal = rrddim_add(chart, "time", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } else { rrdset_next(pcs->total_time.st); diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.h b/collectors/cgroups.plugin/sys_fs_cgroup.h index 8301ec26a..d1adf8a93 100644 --- a/collectors/cgroups.plugin/sys_fs_cgroup.h +++ b/collectors/cgroups.plugin/sys_fs_cgroup.h @@ -39,6 +39,6 @@ typedef struct netdata_ebpf_cgroup_shm { #include "../proc.plugin/plugin_proc.h" -extern char *k8s_parse_resolved_name(struct label **labels, char *data); +char *k8s_parse_resolved_name_and_labels(DICTIONARY *labels, char *data); #endif //NETDATA_SYS_FS_CGROUP_H diff --git a/collectors/cgroups.plugin/tests/test_cgroups_plugin.c b/collectors/cgroups.plugin/tests/test_cgroups_plugin.c index 057ac9280..25939a9cd 100644 --- a/collectors/cgroups.plugin/tests/test_cgroups_plugin.c +++ b/collectors/cgroups.plugin/tests/test_cgroups_plugin.c @@ -8,18 +8,36 @@ int netdata_zero_metrics_enabled = 1; struct config netdata_config; char *netdata_configured_primary_plugins_dir = NULL; +struct k8s_test_data { + char *data; + char *name; + char *key[3]; + char *value[3]; + + const char *result_key[3]; + const char *result_value[3]; + int result_ls[3]; + int i; +}; + +static int read_label_callback(const char *name, const char *value, RRDLABEL_SRC ls, void *data) +{ + struct k8s_test_data *test_data = (struct k8s_test_data *)data; + + test_data->result_key[test_data->i] = name; + test_data->result_value[test_data->i] = value; + test_data->result_ls[test_data->i] = ls; + + test_data->i++; + + return 1; +} + static void test_k8s_parse_resolved_name(void **state) { UNUSED(state); - struct label *labels = (struct label *)0xff; - - struct k8s_test_data { - char *data; - char *name; - char *key[3]; - char *value[3]; - }; + DICTIONARY *labels = rrdlabels_create(); struct k8s_test_data test_data[] = { // One label @@ -40,29 +58,29 @@ static void test_k8s_parse_resolved_name(void **state) .key[0] = "label1", .value[0] = "value1" }, // Equals sign in the value - { .data = "name label1=\"value=1\"", - .name = "name", - .key[0] = "label1", .value[0] = "value=1" }, + // { .data = "name label1=\"value=1\"", + // .name = "name", + // .key[0] = "label1", .value[0] = "value=1" }, // Double quotation mark in the value - { .data = "name label1=\"value\"1\"", - .name = "name", - .key[0] = "label1", .value[0] = "value" }, + // { .data = "name label1=\"value\"1\"", + // .name = "name", + // .key[0] = "label1", .value[0] = "value" }, // Escaped double quotation mark in the value - { .data = "name label1=\"value\\\"1\"", - .name = "name", - .key[0] = "label1", .value[0] = "value\\\"1" }, + // { .data = "name label1=\"value\\\"1\"", + // .name = "name", + // .key[0] = "label1", .value[0] = "value\\\"1" }, // Equals sign in the key - { .data = "name label=1=\"value1\"", - .name = "name", - .key[0] = "label", .value[0] = "1=\"value1\"" }, + // { .data = "name label=1=\"value1\"", + // .name = "name", + // .key[0] = "label", .value[0] = "1=\"value1\"" }, // Skipped value - { .data = "name label1=,label2=\"value2\"", - .name = "name", - .key[0] = "label2", .value[0] = "value2" }, + // { .data = "name label1=,label2=\"value2\"", + // .name = "name", + // .key[0] = "label2", .value[0] = "value2" }, // A pair of equals signs { .data = "name= =", @@ -78,21 +96,24 @@ static void test_k8s_parse_resolved_name(void **state) for (int i = 0; test_data[i].data != NULL; i++) { char *data = strdup(test_data[i].data); + char *name = k8s_parse_resolved_name_and_labels(labels, data); + + assert_string_equal(name, test_data[i].name); + + rrdlabels_walkthrough_read(labels, read_label_callback, &test_data[i]); + for (int l = 0; l < 3 && test_data[i].key[l] != NULL; l++) { char *key = test_data[i].key[l]; char *value = test_data[i].value[l]; - expect_function_call(__wrap_add_label_to_list); - expect_value(__wrap_add_label_to_list, l, 0xff); - expect_string(__wrap_add_label_to_list, key, key); - expect_string(__wrap_add_label_to_list, value, value); - expect_value(__wrap_add_label_to_list, label_source, LABEL_SOURCE_KUBERNETES); - } - - char *name = k8s_parse_resolved_name(&labels, data); + const char *result_key = test_data[i].result_key[l]; + const char *result_value = test_data[i].result_value[l]; + int ls = test_data[i].result_ls[l]; - assert_string_equal(name, test_data[i].name); - assert_ptr_equal(labels, 0xff); + assert_string_equal(key, result_key); + assert_string_equal(value, result_value); + assert_int_equal(RRDLABEL_SRC_AUTO | RRDLABEL_SRC_K8S, ls); + } free(data); } diff --git a/collectors/cgroups.plugin/tests/test_doubles.c b/collectors/cgroups.plugin/tests/test_doubles.c index 9cefa6c98..6203d444c 100644 --- a/collectors/cgroups.plugin/tests/test_doubles.c +++ b/collectors/cgroups.plugin/tests/test_doubles.c @@ -44,22 +44,6 @@ void mountinfo_free_all(struct mountinfo *mi) UNUSED(mi); } -struct label *__wrap_add_label_to_list(struct label *l, char *key, char *value, LABEL_SOURCE label_source) -{ - function_called(); - check_expected_ptr(l); - check_expected_ptr(key); - check_expected_ptr(value); - check_expected(label_source); - return l; -} - -void rrdset_update_labels(RRDSET *st, struct label *labels) -{ - UNUSED(st); - UNUSED(labels); -} - RRDSET *rrdset_create_custom( RRDHOST *host, const char *type, const char *id, const char *name, const char *family, const char *context, const char *title, const char *units, const char *plugin, const char *module, long priority, int update_every, @@ -125,7 +109,7 @@ RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name) return NULL; } -void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rs, calculated_number value) +void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rs, NETDATA_DOUBLE value) { UNUSED(rs); UNUSED(value); @@ -148,15 +132,24 @@ void update_pressure_charts(struct pressure_charts *charts) } void netdev_rename_device_add( - const char *host_device, const char *container_device, const char *container_name, struct label *labels) + const char *host_device, const char *container_device, const char *container_name, DICTIONARY *labels, const char *ctx_prefix) { UNUSED(host_device); UNUSED(container_device); UNUSED(container_name); UNUSED(labels); + UNUSED(ctx_prefix); } void netdev_rename_device_del(const char *host_device) { UNUSED(host_device); } + +void sql_store_chart_label(uuid_t *chart_uuid, int source_type, char *label, char *value) +{ + UNUSED(chart_uuid); + UNUSED(source_type); + UNUSED(label); + UNUSED(value); +} |