diff mbox

[iproute2] ss: make socket statistic parseable

Message ID 1382205252-14988-1-git-send-email-hagen@jauu.net
State Changes Requested, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Hagen Paul Pfeifer Oct. 19, 2013, 5:54 p.m. UTC
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(-)

Comments

Eric Dumazet Oct. 19, 2013, 9:56 p.m. UTC | #1
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 ?



--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hagen Paul Pfeifer Oct. 20, 2013, 1:24 p.m. UTC | #2
* 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
Eric Dumazet Oct. 20, 2013, 1:44 p.m. UTC | #3
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


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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