Section D.2. A Perl Version of Uptime


D.2. A Perl Version of Uptime

#!/usr/bin/perl -w # # uptime - Perl Kstat version of uptime. Solaris 8+. # # This program fetches similar statistics to the /usr/bin/uptime command, # as a demonstation of the Perl Kstat module. # # USAGE:    uptime # use strict; use Sun::Solaris::Kstat; ### Create Kstat object my $Kstat = Sun::Solaris::Kstat->new(); ### Fetch load averages my $load1  = $Kstat->{unix}->{0}->{system_misc}->{avenrun_1min}; my $load5  = $Kstat->{unix}->{0}->{system_misc}->{avenrun_5min}; my $load15 = $Kstat->{unix}->{0}->{system_misc}->{avenrun_15min}; ### Fetch boot time my $boot = $Kstat->{unix}->{0}->{system_misc}->{boot_time}; ### Processing $load1  /= 256; $load5  /= 256; $load15 /= 256; my $days = (time() - $boot) / (60 * 60 * 24); ### Print output print scalar localtime(); printf ",  up %.2f days", $days ; printf ",  load averages: %.2f, %.2f, %.2f\n", $load1, $load5, $load15; 





Solaris Performance and Tools(c) Dtrace and Mdb Techniques for Solaris 10 and Opensolaris
Solaris Performance and Tools: DTrace and MDB Techniques for Solaris 10 and OpenSolaris
ISBN: 0131568191
EAN: 2147483647
Year: 2007
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net