Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
48 rodolico 1
#!/usr/bin/env perl
2
use warnings;
3
use strict;  
4
 
5
# Description: Gets information on Unix based systems
6
 
7
our $VERSION = '1.0';
8
 
9
# Basic Unix module for sysinfo client
10
# Author: R. W. Rodolico
11
# Date:   2016-04-08
12
 
13
# gets additional systems information on Linux machine using some standard
14
# utilities
15
 
16
 
17
BEGIN {
18
   push @INC, shift;
19
}
20
 
21
use library;
22
 
23
exit 1 unless &getOperatingSystem() =~ m/bsd/i;
24
 
25
# the commands this script will use
26
my %commands = ( 
27
                  'grep' => '',
28
                  'dmesg' => '',
29
                  'uname' => ''
30
               );
31
 
32
 
33
# check the commands for validity
34
foreach my $command ( keys %commands ) {
35
   $commands{$command} = &validCommandOnSystem( $command );
36
}
37
 
38
 
39
 
40
 
41
# category we will use for all values found
42
# see sysinfo for a list of valid categories
43
my $CATEGORY = 'system';
44
 
45
my $temp;
46
 
47
my @cpu = qx(dmesg | grep CPU);
48
chomp @cpu;
49
my $numProcessor = 0;
50
for ( my $i = 0; $i < @cpu; $i++ ) {
51
   if ( $cpu[$i] =~ m/^CPU:(.*)/ ) {
52
      print "$CATEGORY\tcpu\t$1\n";
53
      if ( $cpu[$i] =~ m/([0-9.]+)\s*([gm]hz])/ ) {
54
         $temp = $1;
55
         $temp *= 1000 if ( lc($2) eq 'ghz' );
56
         print "$CATEGORY\tcpu_speed\t$temp\n";
57
      }
58
   } elsif ( $cpu[$i] =~ m/^cpu\d/ ) {
59
      $numProcessor++;
60
   }
61
}
62
print "$CATEGORY\tnum_cpu\t$numProcessor\n";
63
 
64
 
65
my $mem = qx( dmesg | grep 'real memory' );
66
# real memory  = 4286578688 (4088 MB)
67
$mem =~ m/=\s+(\d+)/;
68
$mem = $1 / 1024;
69
print "$CATEGORY\tmemory\t$mem\n";
70
 
71
 
72
# all this needs is uname
73
print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};
74
 
75
my $uptime = qx( uptime );
76
chomp $uptime;
77
$uptime =~ m/.*up +(?:(\d+) days?,? +)?(\d+):(\d+),.*/;
78
$uptime =  $1*86400+ $2 * 3600 + $3 * 60;
79
print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
80
print "$CATEGORY\tuptime\t$uptime\n";
81
 
82
exit 0;