From: Chieh-Min Wang <chiehmin18@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Chieh-Min Wang <chiehmin18@gmail.com>
Subject: [PATCH conntrack-tools] conntrack: Show multiple CPUs stats from proc
Date: Mon, 21 Aug 2017 22:38:26 +0800 [thread overview]
Message-ID: <1503326306-23437-1-git-send-email-chiehmin18@gmail.com> (raw)
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(-)
diff --git a/src/conntrack.c b/src/conntrack.c
index 8d19cca..3ec10d6 100644
--- a/src/conntrack.c
+++ b/src/conntrack.c
@@ -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;
--
2.7.4
next reply other threads:[~2017-08-21 14:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-21 14:38 Chieh-Min Wang [this message]
2017-08-24 14:56 ` [PATCH conntrack-tools] conntrack: Show multiple CPUs stats from proc Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1503326306-23437-1-git-send-email-chiehmin18@gmail.com \
--to=chiehmin18@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).