netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ss: make socket statistic parseable
@ 2013-10-19 17:54 Hagen Paul Pfeifer
  2013-10-19 21:56 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2013-10-19 17:54 UTC (permalink / raw)
  To: netdev; +Cc: shemminger, Hagen Paul Pfeifer, Eric Dumazet

Currently "ss -emoi" output is nearly perfect: key value(s) tuples are
delimited by colon. Except three groups: socket options, congestion
control algorithm and send data. Especially the first two groups prevent
automated parsing: what if a future congestion control algorithm is
named "faster" - is this a TCP flag or a congestion control algorithm?
The current syntax allow no parsing.

This patch harmonize the syntax for the last three remaining groups.

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
---
 misc/ss.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index c0369f1..beca2eb 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1386,20 +1386,22 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 			info = RTA_DATA(tb[INET_DIAG_INFO]);
 
 		if (show_options) {
+			int is_not_first_element = 0;
+			printf(" options:");
 			if (info->tcpi_options & TCPI_OPT_TIMESTAMPS)
-				printf(" ts");
+				printf("%cts", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_SACK)
-				printf(" sack");
+				printf("%csack", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_ECN)
-				printf(" ecn");
+				printf("%cecn", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_ECN_SEEN)
-				printf(" ecnseen");
+				printf("%cecnseen", is_not_first_element++ ? ',' : '\0');
 			if (info->tcpi_options & TCPI_OPT_SYN_DATA)
-				printf(" fastopen");
+				printf("%cfastopen", is_not_first_element++ ? ',' : '\0');
 		}
 
 		if (tb[INET_DIAG_CONG])
-			printf(" %s", rta_getattr_str(tb[INET_DIAG_CONG]));
+			printf(" cc:%s", rta_getattr_str(tb[INET_DIAG_CONG]));
 
 		if (info->tcpi_options & TCPI_OPT_WSCALE)
 			printf(" wscale:%d,%d", info->tcpi_snd_wscale,
@@ -1429,7 +1431,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
 		}
 
 		if (rtt > 0 && info->tcpi_snd_mss && info->tcpi_snd_cwnd) {
-			printf(" send %sbps",
+			printf(" send:%sbps",
 			       sprint_bw(b1, (double) info->tcpi_snd_cwnd *
 					 (double) info->tcpi_snd_mss * 8000000.
 					 / rtt));
-- 
1.8.4.rc3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ss: make socket statistic parseable
  2013-10-19 17:54 [PATCH iproute2] ss: make socket statistic parseable Hagen Paul Pfeifer
@ 2013-10-19 21:56 ` Eric Dumazet
  2013-10-20 13:24   ` Hagen Paul Pfeifer
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2013-10-19 21:56 UTC (permalink / raw)
  To: Hagen Paul Pfeifer; +Cc: netdev, shemminger, Eric Dumazet

On Sat, 2013-10-19 at 19:54 +0200, Hagen Paul Pfeifer wrote:
> Currently "ss -emoi" output is nearly perfect: key value(s) tuples are
> delimited by colon. Except three groups: socket options, congestion
> control algorithm and send data. Especially the first two groups prevent
> automated parsing: what if a future congestion control algorithm is
> named "faster" - is this a TCP flag or a congestion control algorithm?
> The current syntax allow no parsing.
> 
> This patch harmonize the syntax for the last three remaining groups.
> 
> Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
> ---

Seems fine to me, maybe we want to support json for better parsing
capabilities ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ss: make socket statistic parseable
  2013-10-19 21:56 ` Eric Dumazet
@ 2013-10-20 13:24   ` Hagen Paul Pfeifer
  2013-10-20 13:44     ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Hagen Paul Pfeifer @ 2013-10-20 13:24 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netdev, shemminger, Eric Dumazet

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

* Eric Dumazet | 2013-10-19 14:56:16 [-0700]:

>Seems fine to me, maybe we want to support json for better parsing
>capabilities ?

Currently the parsing is straight forward with Python: split for
whitespaces and subsequent split for colon to get a key/value list. Supporting
an additional format may be overhead - not sure?! But yeah, JSON formated
output is nice too. The current format has the advantage that it is human
readable and "good" machine parseable. Except the first line:

tcp    ESTAB      0      0 192.168.1.29:58951 208.68.163.218:xmpp-cli

The line has a strict order, so it is not that hard to write a correct parser.


Btw: for people not following google plus circus: I wrote an parser for ss(8)
for plotting TCP stack variables:

http://research.protocollabs.com/captcp/doc-socket-statistic-module.html


Cheers, Hagen

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ss: make socket statistic parseable
  2013-10-20 13:24   ` Hagen Paul Pfeifer
@ 2013-10-20 13:44     ` Eric Dumazet
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2013-10-20 13:44 UTC (permalink / raw)
  To: Hagen Paul Pfeifer; +Cc: netdev, shemminger, Eric Dumazet

On Sun, 2013-10-20 at 15:24 +0200, Hagen Paul Pfeifer wrote:
> * Eric Dumazet | 2013-10-19 14:56:16 [-0700]:
> 
> >Seems fine to me, maybe we want to support json for better parsing
> >capabilities ?
> 
> Currently the parsing is straight forward with Python: split for
> whitespaces and subsequent split for colon to get a key/value list. Supporting
> an additional format may be overhead - not sure?! But yeah, JSON formated
> output is nice too. The current format has the advantage that it is human
> readable and "good" machine parseable. Except the first line:
> 

Yes, I was only suggesting adding the -j flag, as done lately on other
iproute2 commands. Default would stay as is ;)

> tcp    ESTAB      0      0 192.168.1.29:58951 208.68.163.218:xmpp-cli
> 
> The line has a strict order, so it is not that hard to write a correct parser.
> 
> 
> Btw: for people not following google plus circus: I wrote an parser for ss(8)
> for plotting TCP stack variables:
> 
> http://research.protocollabs.com/captcp/doc-socket-statistic-module.html

Yeah, I saw that on your Google+ page, very nice tool !

Thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-20 13:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-19 17:54 [PATCH iproute2] ss: make socket statistic parseable Hagen Paul Pfeifer
2013-10-19 21:56 ` Eric Dumazet
2013-10-20 13:24   ` Hagen Paul Pfeifer
2013-10-20 13:44     ` Eric Dumazet

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).