ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/perl/i-scream_disk.pl
Revision: 1.4
Committed: Tue Dec 18 04:07:17 2001 UTC (22 years, 10 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.3: +6 -12 lines
Log Message:
Solaris process accounting made me notice the number of times `uname` was
being called. It was way over the top, especially as it's unlikely to
change during an invocation of ihost :) Before it was run by each plugin
every time they were run - in total 50 times a minute :/ Now, it's run once
by ihost at startup, and that's it. The value read at startup is passed as
a command line argument to each plugin. The plugins can fallback on working
out the ostype using `uname` if they don't get given one on the command
line.

File Contents

# User Rev Content
1 tdb 1.1 #!/usr/bin/perl -w
2    
3     #-----------------------------------------------------------------
4     # i-scream host plugin - disk information
5 tdb 1.4 # $Author: tdb $
6     # $Id: i-scream_disk.pl,v 1.3 2001/12/03 15:14:11 tdb Exp $
7 tdb 1.1 #
8     # A short perl script to grab the current disk states and info
9     #-----------------------------------------------------------------
10    
11    
12     $| = 1;
13    
14    
15     # You'd be silly not to use this ;)
16     use strict;
17    
18 tdb 1.3 # Exclude list
19     my($exclude_list) = "^/nfs/;^/cdrom/";
20     my(@exclude_array) = split(';', $exclude_list);
21    
22 tdb 1.4 # Get the OS type from the args, or try towork it out
23     my($ostype) = $ARGV[0];
24     $ostype = `uname -s` if not defined $ostype;
25     chomp($ostype);
26 tdb 1.1
27     # Decide which paths we should use.
28     my($dfbin);
29     if ($ostype eq "SunOS") {
30     # covers: Solaris 7/8
31     $dfbin = "/usr/bin/df -akl";
32     }
33     elsif ($ostype eq "Linux") {
34     # covers: Debian r2.2
35     $dfbin = "/bin/df -akl";
36     }
37     elsif ($ostype eq "FreeBSD") {
38     # covers: FreeBSD 4.X
39     $dfbin = "/bin/df -ak";
40     }
41     else {
42     print "i-scream_disk.pl Error: Unable to identify system type - \"$ostype\".\n";
43     print "\"uname -s\" does not report one of the following known types;\n";
44     print " SunOS, Linux, FreeBSD\n";
45     exit(1);
46     }
47    
48     # Run the following components: -
49     &include_disk();
50    
51     # End the program normally.
52     exit(0);
53    
54    
55    
56    
57     # sub to print pairs of data, separated by a single space character.
58     # If the second argument is undefined, then the pair is still printed,
59     # however, the value shall be displayed as the the 'default' value
60     # if the passed value was undefined.
61     sub print_pair($$$) {
62     my($default, $name, $value) = @_;
63    
64     if (!defined $value) {
65     $value = $default;
66     }
67    
68     # Remove the trailing linefeed if we've not already done so.
69     chomp($value);
70    
71     # print the pair of data with a space inbetween.
72     print "$name $value\n";
73     }
74    
75    
76     # sub to find out disk partition information, if it exists.
77     sub include_disk() {
78    
79     # Run the df program.
80     my(@df) = `$dfbin`;
81    
82     # Go through each line of the program, looking for each thing we want.
83     my($partition_no) = 0;
84 tdb 1.2 for (my($i) = 0; $i <= $#df; ++$i) {
85 tdb 1.1 my($line) = $df[$i];
86 tdb 1.2 if ($line =~ /^[^\s]+\s*$/) {
87     ++$i;
88     $line .= $df[$i] if defined $df[$i];
89     }
90     if ($line =~ /^([^\s]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+[^\s]+\s+(\/[^\s]*)\s*/) {
91 tdb 1.1 my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5);
92 tdb 1.3 my($do_disk) = 1;
93     foreach my $exclusion (@exclude_array) {
94     if ($mount =~ /$exclusion/) {
95     $do_disk = 0;
96     last;
97     }
98     }
99     if($do_disk) {
100     &print_pair("unknown", "packet.disk.p$partition_no.attributes.name", $filesystem);
101     &print_pair(0, "packet.disk.p$partition_no.attributes.kbytes", $kbytes);
102     &print_pair(0, "packet.disk.p$partition_no.attributes.used", $used);
103     &print_pair(0, "packet.disk.p$partition_no.attributes.avail", $avail);
104     &print_pair("unknown", "packet.disk.p$partition_no.attributes.mount", $mount);
105     ++$partition_no;
106     }
107 tdb 1.1 }
108     }
109    
110     }