diff options
Diffstat (limited to 'collectors/cgroups.plugin/cgroup-network.c')
-rw-r--r-- | collectors/cgroups.plugin/cgroup-network.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/collectors/cgroups.plugin/cgroup-network.c b/collectors/cgroups.plugin/cgroup-network.c index 385672295e..87cb5ef121 100644 --- a/collectors/cgroups.plugin/cgroup-network.c +++ b/collectors/cgroups.plugin/cgroup-network.c @@ -86,13 +86,18 @@ unsigned int read_iface_ifindex(const char *prefix, const char *iface) { return (unsigned int)ifindex; } -struct iface *read_proc_net_dev(const char *prefix) { +struct iface *read_proc_net_dev(const char *scope, const char *prefix) { if(!prefix) prefix = ""; procfile *ff = NULL; char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s%s", prefix, (*prefix)?"/proc/1/net/dev":"/proc/net/dev"); + +#ifdef NETDATA_INTERNAL_CHECKS + info("parsing '%s'", filename); +#endif + ff = procfile_open(filename, " \t,:|", PROCFILE_FLAG_DEFAULT); if(unlikely(!ff)) { error("Cannot open file '%s'", filename); @@ -117,6 +122,10 @@ struct iface *read_proc_net_dev(const char *prefix) { t->iflink = read_iface_iflink(prefix, t->device); t->next = root; root = t; + +#ifdef NETDATA_INTERNAL_CHECKS + info("added %s interface '%s', ifindex %u, iflink %u", scope, t->device, t->ifindex, t->iflink); +#endif } procfile_close(ff); @@ -323,6 +332,11 @@ 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); +#endif + return pid; } @@ -380,6 +394,10 @@ struct found_device { } *detected_devices = NULL; void add_device(const char *host, const char *guest) { +#ifdef NETDATA_INTERNAL_CHECKS + info("adding device with host '%s', guest '%s'", host, guest); +#endif + uint32_t hash = simple_hash(host); if(guest && (!*guest || strcmp(host, guest) == 0)) @@ -387,10 +405,12 @@ void add_device(const char *host, const char *guest) { struct found_device *f; for(f = detected_devices; f ; f = f->next) { - if(f->host_device_hash == hash && strcmp(host, f->host_device) == 0) { + if(f->host_device_hash == hash && !strcmp(host, f->host_device)) { - if(guest && !f->guest_device) + if(guest && (!f->guest_device || !strcmp(f->host_device, f->guest_device))) { + if(f->guest_device) freez((void *)f->guest_device); f->guest_device = strdupz(guest); + } return; } @@ -425,7 +445,7 @@ void detect_veth_interfaces(pid_t pid) { struct iface *cgroup = NULL; struct iface *host, *h, *c; - host = read_proc_net_dev(netdata_configured_host_prefix); + host = read_proc_net_dev("host", netdata_configured_host_prefix); if(!host) { errno = 0; error("cannot read host interface list."); @@ -444,7 +464,11 @@ void detect_veth_interfaces(pid_t pid) { goto cleanup; } - cgroup = read_proc_net_dev(NULL); +#ifdef NETDATA_INTERNAL_CHECKS + 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."); |