From: Anton Danilov <littlesmilingcloud@gmail.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, Anton Danilov <littlesmilingcloud@gmail.com>
Subject: [PATCH iproute2] nstat: case-insensitive pattern matching
Date: Wed, 8 Jul 2020 15:38:02 +0300 [thread overview]
Message-ID: <20200708123801.878-1-littlesmilingcloud@gmail.com> (raw)
The option 'nocase' allows ignore case in the pattern matching.
Examples:
nstat --nocase *drop*
nstat -azi icmp*
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
man/man8/rtacct.8 | 8 +++++++-
misc/nstat.c | 14 ++++++++++----
2 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/man/man8/rtacct.8 b/man/man8/rtacct.8
index ccdbf6ca..cb6ac912 100644
--- a/man/man8/rtacct.8
+++ b/man/man8/rtacct.8
@@ -4,7 +4,7 @@
nstat, rtacct - network statistics tools.
.SH SYNOPSIS
-Usage: nstat [ -h?vVzrnasd:t:jp ] [ PATTERN [ PATTERN ] ]
+Usage: nstat [ -h?vVzrnasd:t:jpi ] [ PATTERN [ PATTERN ] ]
.br
Usage: rtacct [ -h?vVzrnasd:t: ] [ ListOfRealms ]
@@ -14,6 +14,9 @@ and
.B rtacct
are simple tools to monitor kernel snmp counters and network interface statistics.
+.B nstat
+can filter kernel snmp counters by name with one or several specified wildcards.
+
.SH OPTIONS
.B \-h, \-\-help
Print help
@@ -44,6 +47,9 @@ When combined with
.BR \-\-json ,
pretty print the output.
.TP
+.B \-i, \-\-nocase
+Ignore case in pattern matching.
+.TP
.B \-d, \-\-scan <INTERVAL>
Run in daemon mode collecting statistics. <INTERVAL> is interval between measurements in seconds.
.TP
diff --git a/misc/nstat.c b/misc/nstat.c
index 425e75ef..243caebe 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -43,6 +43,7 @@ int time_constant;
double W;
char **patterns;
int npatterns;
+int nocase;
char info_source[128];
int source_mismatch;
@@ -114,7 +115,7 @@ static int match(const char *id)
return 1;
for (i = 0; i < npatterns; i++) {
- if (!fnmatch(patterns[i], id, 0))
+ if (!fnmatch(patterns[i], id, nocase ? FNM_CASEFOLD : 0))
return 1;
}
return 0;
@@ -551,6 +552,7 @@ static void usage(void)
" -h, --help this message\n"
" -a, --ignore ignore history\n"
" -d, --scan=SECS sample every statistics every SECS\n"
+ " -i, --nocase ignore case in pattern matching\n"
" -j, --json format output in JSON\n"
" -n, --nooutput do history only\n"
" -p, --pretty pretty print\n"
@@ -566,11 +568,12 @@ static const struct option longopts[] = {
{ "help", 0, 0, 'h' },
{ "ignore", 0, 0, 'a' },
{ "scan", 1, 0, 'd'},
- { "nooutput", 0, 0, 'n' },
+ { "nocase", 0, 0, 'i' },
{ "json", 0, 0, 'j' },
+ { "nooutput", 0, 0, 'n' },
+ { "pretty", 0, 0, 'p' },
{ "reset", 0, 0, 'r' },
{ "noupdate", 0, 0, 's' },
- { "pretty", 0, 0, 'p' },
{ "interval", 1, 0, 't' },
{ "version", 0, 0, 'V' },
{ "zeros", 0, 0, 'z' },
@@ -585,7 +588,7 @@ int main(int argc, char *argv[])
int ch;
int fd;
- while ((ch = getopt_long(argc, argv, "h?vVzrnasd:t:jp",
+ while ((ch = getopt_long(argc, argv, "h?vVzrnasd:t:jpi",
longopts, NULL)) != EOF) {
switch (ch) {
case 'z':
@@ -619,6 +622,9 @@ int main(int argc, char *argv[])
case 'p':
pretty = 1;
break;
+ case 'i':
+ nocase = 1;
+ break;
case 'v':
case 'V':
printf("nstat utility, iproute2-ss%s\n", SNAPSHOT);
--
2.26.2
next reply other threads:[~2020-07-08 12:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-08 12:38 Anton Danilov [this message]
2020-07-08 15:28 ` [PATCH iproute2] nstat: case-insensitive pattern matching Stephen Hemminger
2020-07-09 15:03 ` [PATCH v2 iproute2] misc: make the pattern matching case-insensitive Anton Danilov
2020-07-20 20:30 ` Stephen Hemminger
2020-07-08 15:40 ` [PATCH iproute2] nstat: case-insensitive pattern matching Stephen Hemminger
2020-07-08 21:48 ` Anton Danilov
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=20200708123801.878-1-littlesmilingcloud@gmail.com \
--to=littlesmilingcloud@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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).