conntrack: Show multiple CPUs stats from proc
PATCH 1/1 conntrack: Show multiple CPUs stats from proc
When read cpu conntrack stats from /proc/net/stat/nf_conntrack, it only shows stats from cpu0.
This patch list all cpus' conntrack stats like what nfexp_stats_cb did.
--- src/conntrack.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
src/conntrack.c +18 -15
@@ -1794,6 +1794,7 @@ static int display_proc_conntrack_stats(void)char buf[4096 ], *token, *nl;char output[CT_STATS_ENTRIES_MAX ][CT_STATS_STRING_MAX ];unsigned int value[CT_STATS_ENTRIES_MAX ], i, max; +int cpu; fd =fopen (CT_STATS_PROC ,"r" );if (fd ==NULL )
@@ -1817,25 +1818,27 @@ static int display_proc_conntrack_stats(void) } max = i; -if (fgets (buf,sizeof (buf), fd) ==NULL ) { - ret =-1 ; - goto out_err; - } - - nl =strchr (buf,'\n' ); -while (nl !=NULL ) { - *nl ='\0' ; +for (cpu=0 ;fgets (buf,sizeof (buf), fd) !=NULL ; cpu++) { nl =strchr (buf,'\n' ); +while (nl !=NULL ) { + *nl ='\0' ; + nl =strchr (buf,'\n' ); + } + token =strtok (buf," " ); +for (i=0 ; token !=NULL && i<CT_STATS_ENTRIES_MAX ; i++) { + value[i] = (unsigned int )strtol (token, (char **)NULL ,16 ); + token =strtok (NULL ," " ); + } + +printf ("cpu=%-4u\t" , cpu); +for (i=0 ; i<max; i++) +printf ("%s=%u " , output[i], value[i]); +printf ("\n" ); } - token =strtok (buf," " ); -for (i=0 ; token !=NULL && i<CT_STATS_ENTRIES_MAX ; i++) { - value[i] = (unsigned int )strtol (token, (char **)NULL ,16 ); - token =strtok (NULL ," " ); +if (cpu ==0 ) { + ret =-1 ; } -for (i=0 ; i<max; i++) -printf ("%-10s\t\t%-8u\n" , output[i], value[i]); - out_err:fclose (fd);return ret;
Signature · 1 line
2.7.4
Quoted 4 lines · Chieh-Min Wang
When read cpu conntrack stats from
/proc/net/stat/nf_conntrack, it only shows stats from cpu0.This patch list all cpus' conntrack stats like what
nfexp_stats_cbdid.
Applied, thanks.