Sys::uptime - tied OO interface to uptime
Published at: 2000.08.18 23:38:38
Sys::uptime - tied OO interface to uptime
use Sys::uptime;
tie $uptime, 'Sys::uptime';
printf "Load average over the last minute: %s\n",
$uptime->load('one');
print "Uptime was: '$uptime'\n";
OR
# Update internal uptime cache after 2 seconds
tie $uptime, 'Sys::uptime', 2;
print "Load average now: %s\n",
$uptime->load('one');
sleep 3;
print "Load average 3 seconds later: %s\n",
$uptime->load('one');
Sys::uptime is an interface to your system's uptime command. It parses the output of that command and lets you use simple object methods to access the data fields.
In addition, though, Sys::uptime also implements a tied interface that automatically updates its internal uptime cache after a certain number of seconds. For example, say that you wished to get the system load average now, then again in five seconds. Sys::uptime makes that very simple, because it automatically refreshes the information without you needing to do anything.
You can set the number of seconds after which the internal cache will be updated when you tie the variable:
tie $foo, 'Sys::uptime', 20;
will tell Sys::uptime that it should update $foo's cache every 20 seconds.
The following methods can be called on the variable that you tie to Sys::uptime. All values come directly from the uptime output.
The length of time that your system has been ``up''. This can be in any number of formats, as it's returned directly from the uptime output.
The number of users currently logged in to the system.
The load average from the last one, five, or fifteen minutes, respectively.
Output of the uptime command. You can get the same result by using the
$uptime object in string context, because string context has
been overloaded. So $uptime->str() will give you the same thing that
``$uptime'' gives you.
Benjamin Trott, ben@rhumba.pair.com
© 2000 Benjamin Trott, ben@rhumba.pair.com