Unix::Uptime::Linux - Linux implementation of Unix::Uptime


Unix-Uptime documentation Contained in the Unix-Uptime distribution.

Index


Code Index:

NAME

Top

Unix::Uptime::Linux - Linux implementation of Unix::Uptime

SEE ALSO

Top

Unix::Uptime


Unix-Uptime documentation Contained in the Unix-Uptime distribution.

package Unix::Uptime::Linux;

use warnings;
use strict;

our $VERSION='0.3701';
$VERSION = eval $VERSION;

sub uptime {
    my $class = shift;
    open my $proc_uptime, '<', '/proc/uptime'
        or die "Failed to open /proc/uptime: $!";

    my $line = <$proc_uptime>;
    my ($uptime) = $line =~ /^(\d+)/;
    return $uptime;
}

sub uptime_hires {
    my $class = shift;

    unless ($class->_want_hires()) {
        die "uptime_hires: you need to import Unix::Uptime with ':hires'";
    }

    open my $proc_uptime, '<', '/proc/uptime'
        or die "Failed to open /proc/uptime: $!";

    my $line = <$proc_uptime>;
    my ($uptime) = $line =~ /^(\d+(\.\d+)?)/;
    return $uptime;
}

sub load {
    my $class = shift;

    open my $proc_loadavg, '<', '/proc/loadavg'
        or die "Failed to open /proc/loadavg: $!";

    my $line = <$proc_loadavg>;
    my ($load1, $load5, $load15) = $line =~ /^(\d+\.?\d*)\s+(\d+\.?\d*)\s+(\d+\.?\d*)/;
    return ($load1, $load5, $load15);
}

1;

__END__

# vim: set ft=perl sw=4 sts=4 et :