D
doni
Hi,
I am having some problems in printing the Hash of Hashes.
MAC, PHY and Network stats gets generated every 30 minutes and are
copied to a file.
I want to extract all the stats information that is copied to a file
into an hash of hashes and print them.
The file has multiple MAC, PHY and Network Statistics in it and I am
extracting the MAC data in a MAC hash of hashes, PHY data in a PHY hash
of hashes and Network data in a Network hash of hashes.
Here is how the data that is represented in a file. There will be
multiple MAC, PHY and Network Statistics in the file but I am showing
only one of them in here as an example.
MAC statistics:
0 frames with invalid header
546 confirmed frames sent succesfully
1693 confirmed frames sent unsuccesfully
542 confirmed frames received
4597 total frames received
851 data packets received
549 packets sent successfully
152 packets sent unsuccessfully
763 packets queued by network layer
61 packet transmissions timed out
0 packets with invalid length
0 out of order fragments received
87 duplicate fragments received
0 partial packets received
4 packet reassemblies timed out
0 no buffers
PHY statistics:
3404 frames transmitted
105 transmits aborted due to rx
0 transmit errors
0 late transmits
11 tx buffer loads interrupted
0 tx buffer load failures
4598 receive interrupts
4598 frames received
0 received frames lost
0 zero length frames received
0 receive cmd errors
Network statistics:
851 total packets received
0 bad packet length
0 bad version number
0 outgoing packets with no route
0 input packets with bad destination address
0 input packets from wrong channel
0 packets dropped for exceeding TTL
0 packets dropped due to full socket buffers
0 packets dropped due to no receiver
0 packets dropped due to running out of memory
762 total packets sent
549 packets succesfully transmitted
213 packets sent unsuccessfully
For example, if there were 10 MAC Statistics in the file, this is how I
want the data from the "frames with invalid header" stats message to be
copied to a hash.
$mac{'frames with invalid header'}{1} = 0
$mac{'frames with invalid header'}{2} = 0
........ $mac{'frames with invalid header'}{10} = 0
Here is the program I wrote to do the above operation but its not
working as expected. Can anyone let me know where I went wrong.
Thanks,
doni
### Open the netstat file copied to this location ###
my $ex_data = 'netstat.log';
open (NETSTAT,$ex_data) || die("Cannot Open File: $!");
my %mac = (); # Will be the HOH for MAC Statistics
my %phy = (); # Will be the HoH for PHY Statistics
my %bbu = (); # Will be the HoH for BBU Statistics
my %dli = (); # Will be the HoH for DLI Statistics
my $stats; # State Variable
my $i = 0; # Count variable for MAC
my $j = 0; # Count Variable for PHY
my $a = 0; # Count Variable for Network
my $x = 0; # Count Varialbe for Hash
while (<NETSTAT>) {
chomp;
if (/^(\S+)\s+statistics:/) {
$stats = $1;
if ($stats =~ /mac/i)
{ $i++; }
elsif ($stats =~ /phy/i)
{ $j++; }
else
{ $a++; }
}
elsif (/^\s+(\d+)\s+(\S.*)/)
{
($value, $key) = ($1, $2);
if ($stats =~ /mac/i) {
next unless defined $stats;
$mac{$key}{$i} = $value;
}
if ($stats =~ /phy/i) {
next unless defined $stats;
$phy{$key}{$j} = $value;
}
if ($stats =~ /network/i) {
next unless defined $stats;
$network{$key}{$a} = $value;
}
}
else { }
}
foreach $key (keys (%mac)) {
foreach $x (keys %{$mac{$key} })
{
while ($x <= $i) {
print "Message Value is: $mac{$key}{$i}\n";
$x++;
}
}
}
close(NETSTAT) || die("Cannot close $ex_data: $!");
I am having some problems in printing the Hash of Hashes.
MAC, PHY and Network stats gets generated every 30 minutes and are
copied to a file.
I want to extract all the stats information that is copied to a file
into an hash of hashes and print them.
The file has multiple MAC, PHY and Network Statistics in it and I am
extracting the MAC data in a MAC hash of hashes, PHY data in a PHY hash
of hashes and Network data in a Network hash of hashes.
Here is how the data that is represented in a file. There will be
multiple MAC, PHY and Network Statistics in the file but I am showing
only one of them in here as an example.
MAC statistics:
0 frames with invalid header
546 confirmed frames sent succesfully
1693 confirmed frames sent unsuccesfully
542 confirmed frames received
4597 total frames received
851 data packets received
549 packets sent successfully
152 packets sent unsuccessfully
763 packets queued by network layer
61 packet transmissions timed out
0 packets with invalid length
0 out of order fragments received
87 duplicate fragments received
0 partial packets received
4 packet reassemblies timed out
0 no buffers
PHY statistics:
3404 frames transmitted
105 transmits aborted due to rx
0 transmit errors
0 late transmits
11 tx buffer loads interrupted
0 tx buffer load failures
4598 receive interrupts
4598 frames received
0 received frames lost
0 zero length frames received
0 receive cmd errors
Network statistics:
851 total packets received
0 bad packet length
0 bad version number
0 outgoing packets with no route
0 input packets with bad destination address
0 input packets from wrong channel
0 packets dropped for exceeding TTL
0 packets dropped due to full socket buffers
0 packets dropped due to no receiver
0 packets dropped due to running out of memory
762 total packets sent
549 packets succesfully transmitted
213 packets sent unsuccessfully
For example, if there were 10 MAC Statistics in the file, this is how I
want the data from the "frames with invalid header" stats message to be
copied to a hash.
$mac{'frames with invalid header'}{1} = 0
$mac{'frames with invalid header'}{2} = 0
........ $mac{'frames with invalid header'}{10} = 0
Here is the program I wrote to do the above operation but its not
working as expected. Can anyone let me know where I went wrong.
Thanks,
doni
### Open the netstat file copied to this location ###
my $ex_data = 'netstat.log';
open (NETSTAT,$ex_data) || die("Cannot Open File: $!");
my %mac = (); # Will be the HOH for MAC Statistics
my %phy = (); # Will be the HoH for PHY Statistics
my %bbu = (); # Will be the HoH for BBU Statistics
my %dli = (); # Will be the HoH for DLI Statistics
my $stats; # State Variable
my $i = 0; # Count variable for MAC
my $j = 0; # Count Variable for PHY
my $a = 0; # Count Variable for Network
my $x = 0; # Count Varialbe for Hash
while (<NETSTAT>) {
chomp;
if (/^(\S+)\s+statistics:/) {
$stats = $1;
if ($stats =~ /mac/i)
{ $i++; }
elsif ($stats =~ /phy/i)
{ $j++; }
else
{ $a++; }
}
elsif (/^\s+(\d+)\s+(\S.*)/)
{
($value, $key) = ($1, $2);
if ($stats =~ /mac/i) {
next unless defined $stats;
$mac{$key}{$i} = $value;
}
if ($stats =~ /phy/i) {
next unless defined $stats;
$phy{$key}{$j} = $value;
}
if ($stats =~ /network/i) {
next unless defined $stats;
$network{$key}{$a} = $value;
}
}
else { }
}
foreach $key (keys (%mac)) {
foreach $x (keys %{$mac{$key} })
{
while ($x <= $i) {
print "Message Value is: $mac{$key}{$i}\n";
$x++;
}
}
}
close(NETSTAT) || die("Cannot close $ex_data: $!");