diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2023-01-25 19:04:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 19:04:07 +0000 |
commit | 3e3ff4bee83363dca7cfb838baf1cf316960ed1b (patch) | |
tree | c62e0f721eb67856aeb7043ba4326af38159c850 /collectors | |
parent | bf38a22f323be8fa2b35bf782068d903064530ed (diff) |
Add Collector log (#14309)
Diffstat (limited to 'collectors')
52 files changed, 684 insertions, 677 deletions
diff --git a/collectors/apps.plugin/apps_plugin.c b/collectors/apps.plugin/apps_plugin.c index 565d99c48b..4081dbe80f 100644 --- a/collectors/apps.plugin/apps_plugin.c +++ b/collectors/apps.plugin/apps_plugin.c @@ -4850,6 +4850,7 @@ void *reader_main(void *arg __maybe_unused) { int main(int argc, char **argv) { // debug_flags = D_PROCFILE; + stderror = stderr; clocks_init(); diff --git a/collectors/cgroups.plugin/cgroup-network.c b/collectors/cgroups.plugin/cgroup-network.c index 0b66ea475b..a490df3945 100644 --- a/collectors/cgroups.plugin/cgroup-network.c +++ b/collectors/cgroups.plugin/cgroup-network.c @@ -43,7 +43,7 @@ unsigned int read_iface_iflink(const char *prefix, const char *iface) { unsigned long long iflink = 0; int ret = read_single_number_file(filename, &iflink); - if(ret) error("Cannot read '%s'.", filename); + if(ret) collector_error("Cannot read '%s'.", filename); return (unsigned int)iflink; } @@ -56,7 +56,7 @@ unsigned int read_iface_ifindex(const char *prefix, const char *iface) { unsigned long long ifindex = 0; int ret = read_single_number_file(filename, &ifindex); - if(ret) error("Cannot read '%s'.", filename); + if(ret) collector_error("Cannot read '%s'.", filename); return (unsigned int)ifindex; } @@ -70,18 +70,18 @@ struct iface *read_proc_net_dev(const char *scope __maybe_unused, const char *pr snprintfz(filename, FILENAME_MAX, "%s%s", prefix, (*prefix)?"/proc/1/net/dev":"/proc/net/dev"); #ifdef NETDATA_INTERNAL_CHECKS - info("parsing '%s'", filename); + collector_info("parsing '%s'", filename); #endif ff = procfile_open(filename, " \t,:|", PROCFILE_FLAG_DEFAULT); if(unlikely(!ff)) { - error("Cannot open file '%s'", filename); + collector_error("Cannot open file '%s'", filename); return NULL; } ff = procfile_readall(ff); if(unlikely(!ff)) { - error("Cannot read file '%s'", filename); + collector_error("Cannot read file '%s'", filename); return NULL; } @@ -99,7 +99,7 @@ struct iface *read_proc_net_dev(const char *scope __maybe_unused, const char *pr root = t; #ifdef NETDATA_INTERNAL_CHECKS - info("added %s interface '%s', ifindex %u, iflink %u", scope, t->device, t->ifindex, t->iflink); + collector_info("added %s interface '%s', ifindex %u, iflink %u", scope, t->device, t->ifindex, t->iflink); #endif } @@ -145,7 +145,7 @@ static void continue_as_child(void) { pid_t ret; if (child < 0) - error("fork() failed"); + collector_error("fork() failed"); /* Only the child returns */ if (child == 0) @@ -180,7 +180,7 @@ int proc_pid_fd(const char *prefix, const char *ns, pid_t pid) { int fd = open(filename, O_RDONLY); if(fd == -1) - error("Cannot open proc_pid_fd() file '%s'", filename); + collector_error("Cannot open proc_pid_fd() file '%s'", filename); return fd; } @@ -230,7 +230,7 @@ int switch_namespace(const char *prefix, pid_t pid) { if(setns(all_ns[i].fd, all_ns[i].nstype) == -1) { if(pass == 1) { all_ns[i].status = 0; - error("Cannot switch to %s namespace of pid %d", all_ns[i].name, (int) pid); + collector_error("Cannot switch to %s namespace of pid %d", all_ns[i].name, (int) pid); } } else @@ -243,17 +243,17 @@ int switch_namespace(const char *prefix, pid_t pid) { if(root_fd != -1) { if(fchdir(root_fd) < 0) - error("Cannot fchdir() to pid %d root directory", (int)pid); + collector_error("Cannot fchdir() to pid %d root directory", (int)pid); if(chroot(".") < 0) - error("Cannot chroot() to pid %d root directory", (int)pid); + collector_error("Cannot chroot() to pid %d root directory", (int)pid); close(root_fd); } if(cwd_fd != -1) { if(fchdir(cwd_fd) < 0) - error("Cannot fchdir() to pid %d current working directory", (int)pid); + collector_error("Cannot fchdir() to pid %d current working directory", (int)pid); close(cwd_fd); } @@ -277,7 +277,7 @@ int switch_namespace(const char *prefix, pid_t pid) { #else errno = ENOSYS; - error("setns() is missing on this system."); + collector_error("setns() is missing on this system."); return 1; #endif @@ -286,13 +286,13 @@ int switch_namespace(const char *prefix, pid_t pid) { pid_t read_pid_from_cgroup_file(const char *filename) { int fd = open(filename, procfile_open_flags); if(fd == -1) { - error("Cannot open pid_from_cgroup() file '%s'.", filename); + collector_error("Cannot open pid_from_cgroup() file '%s'.", filename); return 0; } FILE *fp = fdopen(fd, "r"); if(!fp) { - error("Cannot upgrade fd to fp for file '%s'.", filename); + collector_error("Cannot upgrade fd to fp for file '%s'.", filename); return 0; } @@ -308,7 +308,7 @@ pid_t read_pid_from_cgroup_file(const char *filename) { fclose(fp); #ifdef NETDATA_INTERNAL_CHECKS - if(pid > 0) info("found pid %d on file '%s'", pid, filename); + if(pid > 0) collector_info("found pid %d on file '%s'", pid, filename); #endif return pid; @@ -331,7 +331,7 @@ pid_t read_pid_from_cgroup(const char *path) { DIR *dir = opendir(path); if (!dir) { - error("cannot read directory '%s'", path); + collector_error("cannot read directory '%s'", path); return 0; } @@ -369,7 +369,7 @@ struct found_device { void add_device(const char *host, const char *guest) { #ifdef NETDATA_INTERNAL_CHECKS - info("adding device with host '%s', guest '%s'", host, guest); + collector_info("adding device with host '%s', guest '%s'", host, guest); #endif uint32_t hash = simple_hash(host); @@ -422,36 +422,36 @@ void detect_veth_interfaces(pid_t pid) { host = read_proc_net_dev("host", netdata_configured_host_prefix); if(!host) { errno = 0; - error("cannot read host interface list."); + collector_error("cannot read host interface list."); goto cleanup; } if(!eligible_ifaces(host)) { errno = 0; - info("there are no double-linked host interfaces available."); + collector_info("there are no double-linked host interfaces available."); goto cleanup; } if(switch_namespace(netdata_configured_host_prefix, pid)) { errno = 0; - error("cannot switch to the namespace of pid %u", (unsigned int) pid); + collector_error("cannot switch to the namespace of pid %u", (unsigned int) pid); goto cleanup; } #ifdef NETDATA_INTERNAL_CHECKS - info("switched to namespaces of pid %d", pid); + collector_info("switched to namespaces of pid %d", pid); #endif cgroup = read_proc_net_dev("cgroup", NULL); if(!cgroup) { errno = 0; - error("cannot read cgroup interface list."); + collector_error("cannot read cgroup interface list."); goto cleanup; } if(!eligible_ifaces(cgroup)) { errno = 0; - error("there are not double-linked cgroup interfaces available."); + collector_error("there are not double-linked cgroup interfaces available."); goto cleanup; } @@ -495,7 +495,7 @@ cleanup: #define CGROUP_NETWORK_INTERFACE_MAX_LINE 2048 void call_the_helper(pid_t pid, const char *cgroup) { if(setresuid(0, 0, 0) == -1) - error("setresuid(0, 0, 0) failed."); + collector_error("setresuid(0, 0, 0) failed."); char command[CGROUP_NETWORK_INTERFACE_MAX_LINE + 1]; if(cgroup) @@ -503,7 +503,7 @@ void call_the_helper(pid_t pid, const char *cgroup) { else snprintfz(command, CGROUP_NETWORK_INTERFACE_MAX_LINE, "exec " PLUGINS_DIR "/cgroup-network-helper.sh --pid %d", pid); - info("running: %s", command); + collector_info("running: %s", command); pid_t cgroup_pid; FILE *fp_child_input, *fp_child_output; @@ -539,7 +539,7 @@ void call_the_helper(pid_t pid, const char *cgroup) { netdata_pclose(fp_child_input, fp_child_output, cgroup_pid); } else - error("cannot execute cgroup-network helper script: %s", command); + collector_error("cannot execute cgroup-network helper script: %s", command); } int is_valid_path_symbol(char c) { @@ -570,33 +570,33 @@ int verify_path(const char *path) { const char *s = path; while((c = *s++)) { if(!( isalnum(c) || is_valid_path_symbol(c) )) { - error("invalid character in path '%s'", path); + collector_error("invalid character in path '%s'", path); return -1; } } if(strstr(path, "\\") && !strstr(path, "\\x")) { - error("invalid escape sequence in path '%s'", path); + collector_error("invalid escape sequence in path '%s'", path); return 1; } if(strstr(path, "/../")) { - error("invalid parent path sequence detected in '%s'", path); + collector_error("invalid parent path sequence detected in '%s'", path); return 1; } if(path[0] != '/') { - error("only absolute path names are supported - invalid path '%s'", path); + collector_error("only absolute path names are supported - invalid path '%s'", path); return -1; } if (stat(path, &sb) == -1) { - error("cannot stat() path '%s'", path); + collector_error("cannot stat() path '%s'", path); return -1; } if((sb.st_mode & S_IFMT) != S_IFDIR) { - error("path '%s' is not a directory", path); + collector_error("path '%s' is not a directory", path); return -1; } @@ -618,10 +618,10 @@ char *fix_path_variable(void) { char *s = strsep(&ptr, ":"); if(s && *s) { if(verify_path(s) == -1) { - error("the PATH variable includes an invalid path '%s' - removed it.", s); + collector_error("the PATH variable includes an invalid path '%s' - removed it.", s); } else { - info("the PATH variable includes a valid path '%s'.", s); + collector_info("the PATH variable includes a valid path '%s'.", s); if(added) strcat(safe_path, ":"); strcat(safe_path, s); added++; @@ -629,8 +629,8 @@ char *fix_path_variable(void) { } } - info("unsafe PATH: '%s'.", path); - info(" safe PATH: '%s'.", safe_path); + collector_info("unsafe PATH: '%s'.", path); + collector_info(" safe PATH: '%s'.", safe_path); freez(p); return safe_path; @@ -646,6 +646,7 @@ void usage(void) { } int main(int argc, char **argv) { + stderror = stderr; pid_t pid = 0; program_name = argv[0]; @@ -690,7 +691,7 @@ int main(int argc, char **argv) { if(pid <= 0) { errno = 0; - error("Invalid pid %d given", (int) pid); + collector_error("Invalid pid %d given", (int) pid); return 2; } @@ -699,7 +700,7 @@ int main(int argc, char **argv) { else if(!strcmp(argv[arg], "--cgroup")) { char *cgroup = argv[arg+1]; if(verify_path(cgroup) == -1) { - error("cgroup '%s' does not exist or is not valid.", cgroup); + collector_error("cgroup '%s' does not exist or is not valid.", cgroup); return 1; } @@ -708,7 +709,7 @@ int main(int argc, char **argv) { if(pid <= 0 && !detected_devices) { errno = 0; - error("Cannot find a cgroup PID from cgroup '%s'", cgroup); + collector_error("Cannot find a cgroup PID from cgroup '%s'", cgroup); } } else diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.c b/collectors/cgroups.plugin/sys_fs_cgroup.c index f9dc085b46..9f9178c367 100644 --- a/collectors/cgroups.plugin/sys_fs_cgroup.c +++ b/collectors/cgroups.plugin/sys_fs_cgroup.c @@ -174,9 +174,9 @@ static enum cgroups_systemd_setting cgroups_detect_systemd(const char *exec) } if (ret == -1) { - error("Failed to get the output of \"%s\"", exec); + collector_error("Failed to get the output of \"%s\"", exec); } else if (ret == 0) { - info("Cannot get the output of \"%s\" within %"PRId64" seconds", exec, (int64_t)timeout.tv_sec); + collector_info("Cannot get the output of \"%s\" within %"PRId64" seconds", exec, (int64_t)timeout.tv_sec); } else { while (fgets(buf, MAXSIZE_PROC_CMDLINE, fp_child_output) != NULL) { if ((begin = strstr(buf, SYSTEMD_HIERARCHY_STRING))) { @@ -214,7 +214,7 @@ static enum cgroups_type cgroups_try_detect_version() FILE *fp_child_input; FILE *fp_child_output = netdata_popen("grep cgroup /proc/filesystems", &command_pid, &fp_child_input); if (!fp_child_output) { - error("popen failed"); + collector_error("popen failed"); return CGROUPS_AUTODETECT_FAIL; } while (fgets(buf, MAXSIZE_PROC_CMDLINE, fp_child_output) != NULL) { @@ -258,12 +258,12 @@ static enum cgroups_type cgroups_try_detect_version() // check kernel command line flag that can override that setting FILE *fp = fopen("/proc/cmdline", "r"); if (!fp) { - error("Error reading kernel boot commandline parameters"); + collector_error("Error reading kernel boot commandline parameters"); return CGROUPS_AUTODETECT_FAIL; } if (!fgets(buf, MAXSIZE_PROC_CMDLINE, fp)) { - error("couldn't read all cmdline params into buffer"); + collector_error("couldn't read all cmdline params into buffer"); fclose(fp); return CGROUPS_AUTODETECT_FAIL; } @@ -271,7 +271,7 @@ static enum cgroups_type cgroups_try_detect_version() fclose(fp); if (strstr(buf, "systemd.unified_cgroup_hierarchy=0")) { - info("cgroups v2 (unified cgroups) is available but are disabled on this system."); + collector_info("cgroups v2 (unified cgroups) is available but are disabled on this system."); return CGROUPS_V1; } return CGROUPS_V2; @@ -311,7 +311,7 @@ void read_cgroup_plugin_configuration() { if(cgroup_use_unified_cgroups == CONFIG_BOOLEAN_AUTO) cgroup_use_unified_cgroups = (cgroups_try_detect_version() == CGROUPS_V2); - info("use unified cgroups %s", cgroup_use_unified_cgroups ? "true" : "false"); + collector_info("use unified cgroups %s", cgroup_use_unified_cgroups ? "true" : "false"); cgroup_containers_chart_priority = (int)config_get_number("plugin:cgroups", "containers priority", cgroup_containers_chart_priority); if(cgroup_containers_chart_priority < 1) @@ -361,7 +361,7 @@ void read_cgroup_plugin_configuration() { mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuacct"); if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "cpuacct"); if(!mi) { - error("CGROUP: cannot find cpuacct mountinfo. Assuming default: /sys/fs/cgroup/cpuacct"); + collector_error("CGROUP: cannot find cpuacct mountinfo. Assuming default: /sys/fs/cgroup/cpuacct"); s = "/sys/fs/cgroup/cpuacct"; } else s = mi->mount_point; @@ -371,7 +371,7 @@ void read_cgroup_plugin_configuration() { mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuset"); if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "cpuset"); if(!mi) { - error("CGROUP: cannot find cpuset mountinfo. Assuming default: /sys/fs/cgroup/cpuset"); + collector_error("CGROUP: cannot find cpuset mountinfo. Assuming default: /sys/fs/cgroup/cpuset"); s = "/sys/fs/cgroup/cpuset"; } else s = mi->mount_point; @@ -381,7 +381,7 @@ void read_cgroup_plugin_configuration() { mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio"); if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "blkio"); if(!mi) { - error("CGROUP: cannot find blkio mountinfo. Assuming default: /sys/fs/cgroup/blkio"); + collector_error("CGROUP: cannot find blkio mountinfo. Assuming default: /sys/fs/cgroup/blkio"); s = "/sys/fs/cgroup/blkio"; } else s = mi->mount_point; @@ -391,7 +391,7 @@ void read_cgroup_plugin_configuration() { mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory"); if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "memory"); if(!mi) { - error("CGROUP: cannot find memory mountinfo. Assuming default: /sys/fs/cgroup/memory"); + collector_error("CGROUP: cannot find memory mountinfo. Assuming default: /sys/fs/cgroup/memory"); s = "/sys/fs/cgroup/memory"; } else s = mi->mount_point; @@ -401,7 +401,7 @@ void read_cgroup_plugin_configuration() { mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "devices"); if(!mi) mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "devices"); if(!mi) { - error("CGROUP: cannot find devices mountinfo. Assuming default: /sys/fs/cgroup/devices"); + collector_error("CGROUP: cannot find devices mountinfo. Assuming default: /sys/fs/cgroup/devices"); s = "/sys/fs/cgroup/devices"; } else s = mi->mount_point; @@ -433,7 +433,7 @@ void read_cgroup_plugin_configuration() { if(mi) debug(D_CGROUP, "found unified cgroup root using mountsource info, with path: '%s'", mi->mount_point); } if(!mi) { - error("CGROUP: cannot find cgroup2 mountinfo. Assuming default: /sys/fs/cgroup"); + collector_error("CGROUP: cannot find cgroup2 mountinfo. Assuming default: /sys/fs/cgroup"); s = "/sys/fs/cgroup"; } else s = mi->mount_point; @@ -575,13 +575,13 @@ void netdata_cgroup_ebpf_initialize_shm() { shm_fd_cgroup_ebpf = shm_open(NETDATA_SHARED_MEMORY_EBPF_CGROUP_NAME, O_CREAT | O_RDWR, 0660); if (shm_fd_cgroup_ebpf < 0) { - error("Cannot initialize shared memory used by cgroup and eBPF, integration won't happen."); + collector_error("Cannot initialize shared memory used by cgroup and eBPF, integration won't happen."); return; } size_t length = sizeof(netdata_ebpf_cgroup_shm_header_t) + cgroup_root_max * sizeof(netdata_ebpf_cgroup_shm_body_t); if (ftruncate(shm_fd_cgroup_ebpf, length)) { - error("Cannot set size for shared memory."); + collector_error("Cannot set size for shared memory."); goto end_init_shm; } @@ -590,7 +590,7 @@ void netdata_cgroup_ebpf_initialize_shm() shm_fd_cgroup_ebpf, 0); if (!shm_cgroup_ebpf.header) { - error("Cannot map shared memory used between cgroup and eBPF, integration won't happen"); + collector_error("Cannot map shared memory used between cgroup and eBPF, integration won't happen"); goto end_init_shm; } shm_cgroup_ebpf.body = (netdata_ebpf_cgroup_shm_body_t *) ((char *)shm_cgroup_ebpf.header + @@ -604,7 +604,7 @@ void netdata_cgroup_ebpf_initialize_shm() return; } - error("Cannot create semaphore, integration between eBPF and cgroup won't happen"); + collector_error("Cannot create semaphore, integration between eBPF and cgroup won't happen"); munmap(shm_cgroup_ebpf.header, length); end_init_shm: @@ -1077,7 +1077,7 @@ static inline void cgroup_read_cpuacct_stat(struct cpuacct_stat *cp) { unsigned long i, lines = procfile_lines(ff); if(unlikely(lines < 1)) { - error("CGROUP: file '%s' should have 1+ lines.", cp->filename); + collector_error("CGROUP: file '%s' should have 1+ lines.", cp->filename); cp->updated = 0; return; } @@ -1123,7 +1123,7 @@ static inline void cgroup_read_cpuacct_cpu_stat(struct cpuacct_cpu_throttling *c unsigned long lines = procfile_lines(ff); if (unlikely(lines < 3)) { - error("CGROUP: file '%s' should have 3 lines.", cp->filename); + collector_error("CGROUP: file '%s' should have 3 lines.", cp->filename); cp->updated = 0; return; } @@ -1180,7 +1180,7 @@ static inline void cgroup2_read_cpuacct_cpu_stat(struct cpuacct_stat *cp, struct unsigned long lines = procfile_lines(ff); if (unlikely(lines < 3)) { - error("CGROUP: file '%s' should have at least 3 lines.", cp->filename); + collector_error("CGROUP: file '%s' should have |