Sys-CpuLoad-0.03/0040755000247300001450000000000007445475463012564 5ustar clintdwengSys-CpuLoad-0.03/Changes0100644000247300001450000000063307445473446014055 0ustar clintdwengRevision history for Perl extension Sys::CpuLoad 0.03 Mon Mar 18 15:02:33 PST 2002 - LC_NUMERIC patch from Victor Wagner - Added cache support to remember how we got the system load - Restricted getloadavg() to FreeBSD/OpenBSD for now 0.02 Sun Feb 17 23:43:26 PST 2002 - bsd getloadavg() support with help from Dmitry Dorofeev 0.01 Wed Aug 11 15:44:55 PDT 1999 - original version; created by h2xs 1.16 Sys-CpuLoad-0.03/MANIFEST0100644000247300001450000000047207434130127013674 0ustar clintdwengChanges - revision history MANIFEST - this file Makefile.PL - "perl Makefile.PL" to get things started README - read this first CpuLoad.pm - the main module CpuLoad.xs - C stub to call bsd getloadavg() test.pl - test script (empty for now) Sys-CpuLoad-0.03/Makefile.PL0100644000247300001450000000061207434127776014531 0ustar clintdwenguse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Sys::CpuLoad', 'VERSION_FROM' => 'CpuLoad.pm', # finds $VERSION 'LIBS' => [''], # e.g., '-lm' 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' 'INC' => '', # e.g., '-I/usr/include/other' ); Sys-CpuLoad-0.03/README0100644000247300001450000000205707445473422013436 0ustar clintdwengDESCRIPTION This module retrieves the 1 minute, 5 minute, and 15 minute load average of a machine. SYNOPSIS use Sys::CpuLoad; print '1 min, 5 min, 15 min load average: ', join(',', Sys::CpuLoad::load()), "\n"; TO-DO - Better getloadavg() support. Currently FreeBSD and OpenBSD are supported. To improve upon this, see the next item below. - Instead of hard coding preprocessor macros around getloadavg(), try to compile C code snippets to see if getloadavg() is supported. - Wanted: HPUX 11.11 pstat_getprocessor() and HPUX 11.00 pstat(PSTAT_PROCESSOR, ...) man pages, sample code, and preprocessor macros. - Win32 support AUTHOR Clinton Wong Contact info: http://search.cpan.org/search?mode=author&query=CLINTDW COPYRIGHT Copyright (c) 1999-2002 Clinton Wong. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Sys-CpuLoad-0.03/test.pl0100644000247300001450000000122106754377027014070 0ustar clintdweng# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use Sys::CpuLoad; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): Sys-CpuLoad-0.03/CpuLoad.pm0100644000247300001450000000443507445475463014454 0ustar clintdwengpackage Sys::CpuLoad; # Copyright (c) 1999-2002 Clinton Wong. All rights reserved. # This program is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); require Exporter; require DynaLoader; require AutoLoader; @ISA = qw(Exporter AutoLoader DynaLoader); @EXPORT = qw(); @EXPORT_OK = qw(load); $VERSION = '0.02'; bootstrap Sys::CpuLoad $VERSION; =head1 NAME Sys::CpuLoad - a module to retrieve system load averages. =head1 DESCRIPTION This module retrieves the 1 minute, 5 minute, and 15 minute load average of a machine. =head1 SYNOPSIS use Sys::CpuLoad; print '1 min, 5 min, 15 min load average: ', join(',', Sys::CpuLoad::load()), "\n"; =head1 AUTHOR Clinton Wong Contact info: http://search.cpan.org/search?mode=author&query=CLINTDW =head1 COPYRIGHT Copyright (c) 1999-2002 Clinton Wong. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut use IO::File; my $cache = 'unknown'; sub load { # handle bsd getloadavg(). Read the README about why it is freebsd/openbsd. if ($cache eq 'getloadavg()' or lc $^O eq 'freebsd' or lc $^O eq 'openbsd' ) { $cache = 'getloadavg()'; return getbsdload() } # handle linux proc filesystem if ($cache eq 'unknown' or $cache eq 'linux') { my $fh = new IO::File('/proc/loadavg', 'r'); if (defined $fh) { my $line = <$fh>; $fh->close(); if ($line =~ /^(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)/) { $cache = 'linux'; return ($1, $2, $3); } # if we can parse /proc/loadavg contents } # if we could load /proc/loadavg } # if linux or not cached # last resort... $cache = 'uptimepipe'; local %ENV = %ENV; $ENV{'LC_NUMERIC'}='POSIX'; # ensure that decimal separator is a dot my $fh=new IO::File('/usr/bin/uptime|'); if (defined $fh) { my $line = <$fh>; $fh->close(); if ($line =~ /(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*,\s+(\d+\.\d+)\s*$/) { return ($1, $2, $3); } # if we can parse the output of /usr/bin/uptime } # if we could run /usr/bin/uptime return (undef, undef, undef); } 1; __END__ Sys-CpuLoad-0.03/CpuLoad.xs0100644000247300001450000000100707445472476014463 0ustar clintdweng#ifdef __cplusplus extern "C" { #endif #include #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #ifdef __cplusplus } #endif MODULE = Sys::CpuLoad PACKAGE = Sys::CpuLoad void getbsdload() PREINIT: double loadavg[3]; PPCODE: #if defined(__FreeBSD__) || defined(__OpenBSD__) getloadavg(loadavg, 3); #endif EXTEND(SP, 3); PUSHs(sv_2mortal(newSVnv(loadavg[0]))); PUSHs(sv_2mortal(newSVnv(loadavg[1]))); PUSHs(sv_2mortal(newSVnv(loadavg[2])));