Rev 48 | Rev 51 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use warnings;
use strict;
# Description: Gets information on Unix based systems
our $VERSION = '1.0';
# Basic Unix module for sysinfo client
# Author: R. W. Rodolico
# Date: 2016-04-08
# gets additional systems information on Linux machine using some standard
# utilities
BEGIN {
push @INC, shift;
}
use library;
exit 1 unless &getOperatingSystem() =~ m/bsd/i;
# the commands this script will use
my %commands = (
'grep' => '',
'dmesg' => '',
'uname' => ''
);
# check the commands for validity
foreach my $command ( keys %commands ) {
$commands{$command} = &validCommandOnSystem( $command );
}
# category we will use for all values found
# see sysinfo for a list of valid categories
my $CATEGORY = 'system';
my $temp;
my @cpu = qx(dmesg | grep CPU);
chomp @cpu;
my $numProcessor = 0;
for ( my $i = 0; $i < @cpu; $i++ ) {
if ( $cpu[$i] =~ m/^CPU:(.*)/ ) {
print "$CATEGORY\tcpu\t$1\n";
if ( $cpu[$i] =~ m/([0-9.]+)\s*([gm]hz])/ ) {
$temp = $1;
$temp *= 1000 if ( lc($2) eq 'ghz' );
print "$CATEGORY\tcpu_speed\t$temp\n";
}
} elsif ( $cpu[$i] =~ m/^cpu\d/ ) {
$numProcessor++;
}
}
print "$CATEGORY\tnum_cpu\t$numProcessor\n";
my $mem = qx( dmesg | grep 'real memory' );
# real memory = 4286578688 (4088 MB)
$mem =~ m/=\s+(\d+)/;
$mem = $1 / 1024;
print "$CATEGORY\tmemory\t$mem\n";
# all this needs is uname
print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};
my $uptime = qx( uptime );
chomp $uptime;
$uptime =~ m/.*up +(?:(\d+) days?,? +)?(\d+):(\d+),.*/;
my $day = $1 ? $1 : 0;
my $hour = $2 ? $2 : 0;
my $minute = $3 ? $3 : 0;
$uptime = $day*86400+ $hour * 3600 + $minute * 60;
print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
print "$CATEGORY\tuptime\t$uptime\n";
exit 0;