Skip to content

Commit

Permalink
Collect statistics from other network namespace
Browse files Browse the repository at this point in the history
This patch implements how to collect statistics for other netns
by using `setns` to switch to another netns to read /proc files,
and then use shared memory for parent-child IPC.

Combined with actual needs and performance considerations, this
patch only collects other netns's physical network devices stats.
Virtual devices are ignored except the 'lo'.

Signed-off-by: Fei Li <[email protected]>
  • Loading branch information
ShirleyFei committed Mar 13, 2023
1 parent fd4ba50 commit befa9a2
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PMPATH2 = /usr/lib64/pm-utils/sleep.d
PMPATHD = /usr/lib/systemd/system-sleep

CFLAGS += -O2 -I. -Wall -Wno-stringop-truncation -Wmissing-prototypes -Wmissing-declarations # -DNOPERFEVENT # -DHTTPSTATS
LDFLAGS = -lpthread
OBJMOD0 = version.o
OBJMOD1 = various.o deviate.o procdbase.o
OBJMOD2 = acctproc.o photoproc.o photosyst.o rawlog.o ifprop.o parseable.o
Expand Down
26 changes: 24 additions & 2 deletions ifprop.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ typedef __u8 u8;
#include "photosyst.h"

static int calcbucket(char *);
static int getphysprop(struct ifprop *);

/*
** hash table for linked lists with *all* interfaces
Expand Down Expand Up @@ -304,7 +303,7 @@ calcbucket(char *p)
**
** return value reflects true (success) or false (unknown interface type)
*/
static int
int
getphysprop(struct ifprop *p)
{
int sockfd;
Expand Down Expand Up @@ -440,3 +439,26 @@ getphysprop(struct ifprop *p)

return 1;
}

int getbusinfo(struct ifprop *p) {
int sockfd, ret = 0;
struct ifreq ifreq;
struct ethtool_drvinfo drv;

if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1 )
return 0;

memset(&ifreq, 0, sizeof ifreq);
strncpy((void *)&ifreq.ifr_ifrn.ifrn_name, p->name,
sizeof ifreq.ifr_ifrn.ifrn_name - 1);

drv.cmd = ETHTOOL_GDRVINFO;
ifreq.ifr_ifru.ifru_data = (void *)&drv;
if ( ioctl(sockfd, SIOCETHTOOL, &ifreq) == 0 )
if ( strlen(drv.bus_info) > 0 )
ret = 1;

close(sockfd);

return ret;
}
2 changes: 2 additions & 0 deletions ifprop.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ struct ifprop {

int getifprop(struct ifprop *);
void initifprop(void);
int getphysprop(struct ifprop *);
int getbusinfo(struct ifprop *);
Loading

0 comments on commit befa9a2

Please sign in to comment.