-
Notifications
You must be signed in to change notification settings - Fork 7
/
retrans_reporter.pl
89 lines (66 loc) · 2.71 KB
/
retrans_reporter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/perl5/bin/perl -w
## Ben Rockwood, March 11th, 2008 (c)
## retrans_reporter.pl
## LICENSE: CDDL
## TODO :
## x Divide by zero bug, on slow systems script freaks.
## x Should be able to report sub 1% deltas, ie: 0.005%
## x Should have a help message
## x Interval should be configurable
### TCP Retransmit Stats in Real Time:
###
### tcp:0:tcp:retransBytes 163797543
### tcp:0:tcp:retransSegs 967731519
### tcp:0:tcp:outDataSegs 2120569978
### tcp:0:tcp:outDataBytes 3018897573
###
### Get those 4, then delta for ratio of retrans.
use strict;
use Sun::Solaris::Kstat;
my $interval = 1;
my $ARGS = @ARGV;
# Parse Args
if($ARGS > 0 && $ARGV[0] =~ m/\d+/) {
$interval = $ARGV[0];
} elsif($ARGS > 0 && $ARGV[0] eq "-h") {
die("Usage: $0 <interval>\n");
}
# Print Header:
print(" PACKETS \t KBYTES \t\n");
print("Total\tRetrans\tTotal\tRetrans\t%\n");
print("-----\t-------\t-----\t-------\t--\n");
my $Kstat = Sun::Solaris::Kstat->new();
my $last_RetransBytes = 0;
my $last_RetransSegs = 0;
my $last_OutBytes = 0;
my $last_OutSegs = 0;
while (1) {
# Get tcp:0:tcp:retransBytes
my $RetransBytes = ${Kstat}->{tcp}->{0}->{tcp}->{retransBytes};
# Get tcp:0:tcp:retransSegs
my $RetransSegs = ${Kstat}->{tcp}->{0}->{tcp}->{retransSegs};
# Get tcp:0:tcp:outDataBytes
my $OutBytes = ${Kstat}->{tcp}->{0}->{tcp}->{outDataBytes};
# Get tcp:0:tcp:outDataSegs
my $OutSegs = ${Kstat}->{tcp}->{0}->{tcp}->{outDataSegs};
# Caluclate the current packet deltas
my $interval_OutSegs = $OutSegs - $last_OutSegs;
my $interval_RetransSegs = $RetransSegs - $last_RetransSegs;
# Calculate Ratio
my $retrans_ratio = $interval_RetransSegs / $interval_OutSegs;
$retrans_ratio =~ s/.*\.(\d{2})(\d*)/$1\.$2/;
# Output:
printf("%d\t%d\t%d\t%d\t%.3f%%\n",
$interval_OutSegs, # Column 1; Total Packet Out
$interval_RetransSegs, # Column 2; Packet Retransmits
int( ($OutBytes - $last_OutBytes) / 1024), # Column 3; Total Bytes Out
int( ($RetransBytes - $last_RetransBytes) / 1024), # Column 4; Retransmit Bytes Out
$retrans_ratio # Out vs Retrans Delta
);
sleep($interval);
$Kstat->update();
$last_RetransBytes = $RetransBytes;
$last_RetransSegs = $RetransSegs;
$last_OutBytes = $OutBytes;
$last_OutSegs = $OutSegs;
}