From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 8 16:29:23 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C5A4EE49 for ; Fri, 8 Aug 2014 16:29:23 +0000 (UTC) Received: from mho-01-ewr.mailhop.org (mho-03-ewr.mailhop.org [204.13.248.66]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 99D5E28FC for ; Fri, 8 Aug 2014 16:29:22 +0000 (UTC) Received: from [73.34.117.227] (helo=ilsoft.org) by mho-01-ewr.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1XFn2f-000Ct5-13; Fri, 08 Aug 2014 16:29:21 +0000 Received: from [172.22.42.240] (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id s78GTJwG021730; Fri, 8 Aug 2014 10:29:19 -0600 (MDT) (envelope-from ian@FreeBSD.org) X-Mail-Handler: Dyn Standard SMTP by Dyn X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/sendlabs/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX19gyFo3HSqvOX7pIeXLrPLT X-Authentication-Warning: paranoia.hippie.lan: Host revolution.hippie.lan [172.22.42.240] claimed to be [172.22.42.240] Subject: Re: disk and NIC io statistics via sysctl From: Ian Lepore To: Stefan Parvu In-Reply-To: <20140808184021.537feca9b15e3a261ea27fa7@systemdatarecorder.org> References: <20140808184021.537feca9b15e3a261ea27fa7@systemdatarecorder.org> Content-Type: text/plain; charset="us-ascii" Date: Fri, 08 Aug 2014 10:29:18 -0600 Message-ID: <1407515358.56408.374.camel@revolution.hippie.lan> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Aug 2014 16:29:23 -0000 On Fri, 2014-08-08 at 18:40 +0300, Stefan Parvu wrote: > Hi, > > Fetching CPU and Memory statistics, using sysctl interface and perl seems nice and easy. > I made great progress with sysrec a generic recorder reporting: cpu mem disk and nic > stats on FreeBSD. Now Im getting into disk and nic sections: > > 1. Disk > Im able to get a list of all disks on a system using kern.disks sysctl variable. > I want to be able to report per disk something like: > > readreq rate read requests per second, rate > writereq rate write requests per second, rate > totreq rate total read + write requests per second, rate > readbyt rate read bytes per second, in KB, rate > writebyt rate write bytes per second, in KB, rate > totbyt rate total read + write bytes per second, in KB, rate > > iostat seems the simplest way to fetch these, but how about sysctl interface ? > I could not figure out any sysctl parameters for disk throughput. How one will > fetch throughput per disk via sysctl ? > > > 2. NIC > Same will go for network card interfaces. I want to fetch per NIC throughput and > errors via sysctl, something like these: > > 1 timestamp time seconds since Epoch > 2 interface number NIC name, string > 3 rxKB rate the number of KBytes received per sec > 4 rxpcks rate the no. of packets received per sec > 5 rxerrs rate the number of errors while received packets per sec > 6 rxdrop rate the number of packets that were dropped per sec > 7 rxfifo rate the number of FIFO overruns on received packets per sec > 8 rxframe rate the number of carrier errors on received packet per sec > 9 rxcompr rate the number of compressed packets received per sec > 10 rxmulti rate the number of multicast packets received per sec > 11 txKB rate the number of KBytes transmitted per sec > 12 txpcks rate the number of packets transmitted per sec > 13 txerrs rate the number of errors transmitting packets per sec > 14 txdrop rate the number of packets that were dropped per sec > 15 txfifo rate the number of FIFO overruns on transmitted packets per sec > 16 txcolls rate the number of collisions that were detecte per sec > 17 txcarr rate the number of carrier errors on transmitted packets per sec > 18 txcompr rate the number of compressed packets transmitted per sec > 19 ttpcks rate the total number of packets (received + transmitted) per sec > 20 ttKB rate the total number of KBytes (received + transmitted) per sec > > > Any ideas ? > > Many thanks, > All of this series of questions you've been asking really have the same answer: look at the source code for the very apps you cite as examples of outputting the info you want, and do what they do. There are no magic secret kernel backdoor interfaces, all these userland tools are using documented interfaces such as sysctl to get their info. (There may be a few miscreants that open /dev/kmem and rudely poke around in kernel memory, but I'm not sure we have any of them in base. The lsof tool in ports is one that comes to mind for that.) In addition to the tools you've already mentioned that have the info you want, have a look at gstat for IO stats, netstat for net throughput, and systat for lots of stuff. -- Ian