Created
August 24, 2010 02:35
-
-
Save garno/546804 to your computer and use it in GitHub Desktop.
Get the current system load with Perl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Get current system load average | |
# | |
# based on: http://www.skolnick.org/cgi-bin/list.pl?file=serverload.pl | |
# file: server_load.pl | |
# | |
# Get system load average with ruby => %x[perl server_load.pl].to_f | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
print get_load_average(); | |
sub get_load_average { | |
open(LOAD, "/proc/loadavg") or die "Unable to get server load \n"; | |
my $load_avg = <LOAD>; | |
close LOAD; | |
my ( $one_min_avg ) = split /\s/, $load_avg; | |
return $one_min_avg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment