Skip to content

Instantly share code, notes, and snippets.

@garno
Created August 24, 2010 02:35
Show Gist options
  • Save garno/546804 to your computer and use it in GitHub Desktop.
Save garno/546804 to your computer and use it in GitHub Desktop.
Get the current system load with Perl.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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