Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 May 2008 13:09:01 -0700
From:      David Wolfskill <david@catwhisker.org>
To:        hackers@freebsd.org
Subject:   [Patch] Using sysctl(8) to acquire info from different systems
Message-ID:  <20080512200901.GL66703@bunrab.catwhisker.org>

next in thread | raw e-mail | index | archive | help

--R0UoHh4jwSc8qXKC
Content-Type: multipart/mixed; boundary="ZMT28BdW279F9lxY"
Content-Disposition: inline


--ZMT28BdW279F9lxY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I recently started using output from sysctl(8) to get information from
some FreeBSD systems in what I hope is a low-impact way.

I wanted to avoid installing or configuring any additional software on
the machines; as they didn't have an SNMP daemon running (and I'm not
the one who actually controls or runs them anyway), I was reluctant to
recommend making such changes to production systems.

But I did have a requirement to gather information as to resource
consumption on the production machines, so I thought that sysctl(8)
output might be of some use -- and it has (or so I believe).

But I ran into one mild annoyance:  Once I got a script working to
collect data from one machine, and I then tried running the script
(configured to collect information on the same OIDs), things were OK ...
as long as the new system was running the same revision of FreeBSD.

I realize that there will be changes in supported OIDs over time.  But
the current behavior of sysctl(8) is to (squawk unless -q is specified)
and bail as soon as it sees a request to report on the value of an OID
it doesn't know.

In my case, I believe it would be useful to provide an ability to tell
sysctl(8) to report on everything asked for that it does know, and
ignore the OIDs it doesn't know.

Is this percpetion so radical that I'm way off base?  If so, please
educate me as to why.

Otherwise, I'll plan on filing a PR with the attached patch, which adds
"-i" to sysctl(8)'s flags -- and which appears to work as described above:

localhost(8.0-C)[1] uname -a
FreeBSD localhost 8.0-CURRENT FreeBSD 8.0-CURRENT #769: Mon May 12 07:17:44=
 PDT 2008     root@g1-37.catwhisker.org:/common/S4/obj/usr/src/sys/CANARY  =
i386
localhost(8.0-C)[2] sysctl hw.ncpu kern.sched.quantum net.inet.ip.fw.enable
hw.ncpu: 1
sysctl: unknown oid 'kern.sched.quantum'
localhost(8.0-C)[3] sysctl -i hw.ncpu kern.sched.quantum net.inet.ip.fw.ena=
ble
hw.ncpu: 1
net.inet.ip.fw.enable: 1
localhost(8.0-C)[4] ^-i^-q
sysctl -q hw.ncpu kern.sched.quantum net.inet.ip.fw.enable
hw.ncpu: 1
localhost(8.0-C)[5]=20

Peace,
david
--=20
David H. Wolfskill				david@catwhisker.org
I submit that "conspiracy" would be an appropriate collective noun for cats.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.

--ZMT28BdW279F9lxY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sysctl.patch"
Content-Transfer-Encoding: quoted-printable

Index: sysctl.8
=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: /cvs/freebsd/src/sbin/sysctl/sysctl.8,v
retrieving revision 1.64
diff -u -r1.64 sysctl.8
--- sysctl.8	28 Nov 2007 14:48:30 -0000	1.64
+++ sysctl.8	12 May 2008 19:14:08 -0000
@@ -82,6 +82,12 @@
 is specified, or a variable is being set.
 .It Fl h
 Format output for human, rather than machine, readability.
+.It Fl i
+Ignore unknown OIDs.
+The purpose is to make use of
+.Nm
+for collecting data from a variety of machines (not all of which
+are necessarily running exactly the same software) easier.
 .It Fl N
 Show only variable names, not their values.
 This is particularly useful with shells that offer programmable
Index: sysctl.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: /cvs/freebsd/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.88
diff -u -r1.88 sysctl.c
--- sysctl.c	15 Oct 2007 20:00:19 -0000	1.88
+++ sysctl.c	12 May 2008 19:07:34 -0000
@@ -58,8 +58,8 @@
 #include <string.h>
 #include <unistd.h>
=20
-static int	aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag;
-static int	qflag, xflag;
+static int	aflag, bflag, dflag, eflag, hflag, iflag, Nflag, nflag;
+static int	oflag, qflag, xflag;
=20
 static int	oidfmt(int *, int, char *, u_int *);
 static void	parse(char *);
@@ -89,7 +89,7 @@
 	setbuf(stdout,0);
 	setbuf(stderr,0);
=20
-	while ((ch =3D getopt(argc, argv, "AabdehNnoqwxX")) !=3D -1) {
+	while ((ch =3D getopt(argc, argv, "AabdehiNnoqwxX")) !=3D -1) {
 		switch (ch) {
 		case 'A':
 			/* compatibility */
@@ -110,6 +110,9 @@
 		case 'h':
 			hflag =3D 1;
 			break;
+		case 'i':
+			iflag =3D 1;
+			break;
 		case 'N':
 			Nflag =3D 1;
 			break;
@@ -185,6 +188,8 @@
 	len =3D name2oid(bufp, mib);
=20
 	if (len < 0) {
+		if (iflag)
+			return;
 		if (qflag)
 			exit(1);
 		else

--ZMT28BdW279F9lxY--

--R0UoHh4jwSc8qXKC
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)

iEYEARECAAYFAkgoo9wACgkQmprOCmdXAD2IygCfRJlKA3DUICvywPUGRU6jr8KP
apwAnjtARZrbE24WP+q6w+7Y0xiKKHbQ
=Vb7I
-----END PGP SIGNATURE-----

--R0UoHh4jwSc8qXKC--



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