Right now I'm working on a program with PHP and Perl to read the computer's system data and we have been using SNMP to collect data (or rather, forced to). After retrieving the data, we were supposed to store the data in a database and then use the data to plot out a line graph.
At the moment, I'm using this perl script to retrieve the CPU/Processor usage of a computer.
$MIB1 = ".1.3.6.1.2.1.25.3.3.1.2"; #Cpu Processors
$HOST = shift; #or localhost for testing
$count = 0;
#print out all the processors of the computer and their values
#SNMP is used with perl because of the libraries
#snmpwalk retrieves information from the computers by the computer name and MIB
#as there are many values, they are stored in an array to be used
(@values) = &snmpwalk("$HOST","$MIB1");
foreach $value (@values)
{
$count++;
if ($value) {
#fixes the value for presentation
$goodvalue = &strip_comment($value);
#prints out the result. $count will count out the processor number
print "CPU Usage of Processor $count: $goodvalue%\n"; }
if ($value > 90){
#warns user if the processor usage is over 90%
print "Warning: CPU Usage over 90%! \n"
}
else { warn "No response from host :$HOST:\n"; } #provides error
}
The code, or rather, SNMP retrieves several individual processors and many should know that there can be many processors on one computer, therefore making storing this data into a database not very practical, (for example if one computer has only 2 processors, the next has 4 and the one across the room has 100.)
So I was wondering if anyone could help better this code or change it so that I could add them all together, and find an average value of the CPU/processor usages and store it into a database. Because, I'm not too sure how to go about it, as the loop scans for only 1 processor at a time, and it might be unknown how many there are.
Thanks in advance.