{"id":42,"date":"2009-01-19T17:47:04","date_gmt":"2009-01-19T15:47:04","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=42"},"modified":"2009-01-19T17:47:04","modified_gmt":"2009-01-19T15:47:04","slug":"awk-snippet-to-count-tcp-sockets-grouped-by-state","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/awk-snippet-to-count-tcp-sockets-grouped-by-state\/","title":{"rendered":"Awk snippet to count TCP sockets grouped by state"},"content":{"rendered":"<p>Depending on the release of awk it could be:<\/p>\n<pre lang=\"c\">\r\n#!\/usr\/bin\/gawk -f\r\n{\r\n        if ( ($NF) in stats )  {\r\n                stats[$NF] = stats[$NF]+1;\r\n        } else {\r\n                stats[$NF]=1;\r\n        }\r\n}\r\nEND {\r\n        for ( var in stats) {\r\n                print var \" = \" stats[var];\r\n        }\r\n}\r\n<\/pre>\n<p>I saved the script as <b>netstat_c<\/b>.<br \/>\nI have to filter my netstat output to match only my tcp sockets prior to pipe the output to the script.<\/p>\n<p>On linux:<\/p>\n<pre lang=\"none\">\r\n$ netstat -a | grep ^tcp | netstat_c\r\nLISTEN = 13\r\nESTABLISHED = 74\r\nTIME_WAIT = 7\r\n<\/pre>\n<p>This is great to check my webserver connections when I do stress tests.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Depending on the release of awk it could be: #!\/usr\/bin\/gawk -f { if ( ($NF) in stats ) { stats[$NF] = stats[$NF]+1; } else { stats[$NF]=1; } } END { for ( var in stats) { print var &#8221; = &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/awk-snippet-to-count-tcp-sockets-grouped-by-state\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-42","post","type-post","status-publish","format-standard","hentry","category-linux"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":2,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"predecessor-version":[{"id":44,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/42\/revisions\/44"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}