Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Aug 2007 14:48:57 +0800
From:      LI Xin <delphij@delphij.net>
To:        freebsd-net <freebsd-net@freebsd.org>
Cc:        Robert Watson <rwatson@FreeBSD.org>, hshh <hunreal@gmail.com>
Subject:   Add socket related statistics to netstat(1)?
Message-ID:  <46D516D9.4050007@delphij.net>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigC7AC46FEA34DE35C9DBEE14E
Content-Type: multipart/mixed; boundary="------------080100020102070403070508"

This is a multi-part message in MIME format.
--------------080100020102070403070508
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi,

Here is a proof-of-concept patch that adds sockets related statistics to
netstat(1)'s -m option, which could make SA's life easier.  Inspired by
a local user's suggestion.

Comments?

Cheers,
--=20
Xin LI <delphij@delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!

--------------080100020102070403070508
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="socket.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
 filename="socket.diff"

Index: mbuf.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.bin/netstat/mbuf.c,v
retrieving revision 1.53
diff -u -p -r1.53 mbuf.c
--- mbuf.c	16 Jul 2007 17:15:55 -0000	1.53
+++ mbuf.c	29 Aug 2007 06:45:26 -0000
@@ -1,4 +1,4 @@
-/*
+/*-
  * Copyright (c) 1983, 1988, 1993
  *	The Regents of the University of California.
  * Copyright (c) 2005 Robert N. M. Watson
@@ -58,6 +58,8 @@ __FBSDID("$FreeBSD: src/usr.bin/netstat/
 #include <string.h>
 #include "netstat.h"
=20
+#define SOCKET_MEM_NAME "socket"
+
 /*
  * Print mbuf statistics.
  */
@@ -70,6 +72,7 @@ mbpr(void *kvmd, u_long mbaddr)
 	uintmax_t cluster_count, cluster_bytes, cluster_limit, cluster_free;
 	uintmax_t cluster_failures, cluster_size;
 	uintmax_t packet_count, packet_bytes, packet_free, packet_failures;
+	uintmax_t socket_count, socket_bytes, socket_limit, socket_free, socket=
_failures;
 	uintmax_t tag_count, tag_bytes;
 	uintmax_t jumbop_count, jumbop_bytes, jumbop_limit, jumbop_free;
 	uintmax_t jumbop_failures, jumbop_size;
@@ -134,6 +137,18 @@ mbpr(void *kvmd, u_long mbaddr)
 	packet_free =3D memstat_get_free(mtp);
 	packet_failures =3D memstat_get_failures(mtp);
=20
+	mtp =3D memstat_mtl_find(mtlp, ALLOCATOR_UMA, SOCKET_MEM_NAME);
+	if (mtp =3D=3D NULL) {
+		warnx("memstat_mtl_find: zone %s not found",
+		    SOCKET_MEM_NAME);
+		goto out;
+	}
+	socket_count =3D memstat_get_count(mtp);
+	socket_bytes =3D memstat_get_bytes(mtp);
+	socket_free =3D memstat_get_free(mtp);
+	socket_limit =3D memstat_get_countlimit(mtp);
+	socket_failures =3D memstat_get_failures(mtp);
+
 	mtp =3D memstat_mtl_find(mtlp, ALLOCATOR_UMA, MBUF_CLUSTER_MEM_NAME);
 	if (mtp =3D=3D NULL) {
 		warnx("memstat_mtl_find: zone %s not found",
@@ -208,6 +223,9 @@ mbpr(void *kvmd, u_long mbaddr)
 	    "(current/cache)\n",
 	    packet_count, packet_free);
=20
+	printf("%ju/%ju/%ju/%ju socket UMA in use (current/cache/total/max)\n",=

+	    socket_count, socket_free, socket_count + socket_free, socket_limit=
);
+
 	printf("%ju/%ju/%ju/%ju %juk (page size) jumbo clusters in use "
 	    "(current/cache/total/max)\n",
 	    jumbop_count, jumbop_free, jumbop_count + jumbop_free,
@@ -280,6 +298,11 @@ mbpr(void *kvmd, u_long mbaddr)
 	    "mbuf+clusters)\n", mbuf_failures, cluster_failures,
 	    packet_failures);
=20
+	printf("%juK bytes allocated to socket\n",
+	    socket_bytes / 1024);
+
+	printf("%ju request for socket UMA denied\n", socket_failures);
+
 	printf("%ju/%ju/%ju requests for jumbo clusters denied "
 	    "(%juk/9k/16k)\n", jumbop_failures, jumbo9_failures,
 	    jumbo16_failures, jumbop_size / 1024);

--------------080100020102070403070508--

--------------enigC7AC46FEA34DE35C9DBEE14E
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG1RbaOfuToMruuMARCjzaAJ9uSsxyQbXxvh5kEwK0fr2vd08MUACaAtWE
GGkKi6DwIQA7a0p7FfzSW0w=
=h9G5
-----END PGP SIGNATURE-----

--------------enigC7AC46FEA34DE35C9DBEE14E--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?46D516D9.4050007>