Skip to content

Instantly share code, notes, and snippets.

@giganteous
Created August 28, 2018 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giganteous/daa416a4498d7940dac31acb27b78b4d to your computer and use it in GitHub Desktop.
Save giganteous/daa416a4498d7940dac31acb27b78b4d to your computer and use it in GitHub Desktop.
To debug drops, use "watch -n 1 drops.pl"
#! /usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
#
sub read_udp {
my $fn = shift;
my $drops = shift;
my $fh;
open($fh, '<', $fn) or die "$fn: $!\n";
<$fh>;
while(<$fh>) {
chomp;
s/^\s*//;
my @f = split(/\s+/);
next if $f[12] eq '0';
$drops->{$f[9]} = $f[12];
}
close $fh;
}
my %drops;
read_udp('/proc/net/udp', \%drops);
read_udp('/proc/net/udp6', \%drops);
my $arg = shift;
$arg ||= 'sport = 5300 or sport = 53';
my @port = qq/$arg/;
my $fh;
open($fh, '-|', 'ss', '-nleu') or die "ss: $!\n";
# udp UNCONN 0 0 194.109.20.106:5300 *:* ino:31851 sk:2bf <->
# udp UNCONN 0 0 127.0.0.1:5300 *:* ino:30795 sk:2c0 <->
# udp UNCONN 0 0 2001:888:0:104::6a:5300 :::* ino:31852 sk:2df v6only:1 <->
# udp UNCONN 0 0 ::1:5300 :::* ino:31850 sk:2e0 v6only:1 <->
my $hdr = 0;
while (<$fh>) {
if ($hdr == 0) {
chomp;
print "$_ Drops\n";
$hdr = 1;
next;
}
next unless /UNCONN/;
next unless /:53(00)?\s/;
my @f;
push @f, $1 while (s/^(\S+\s*)//);
#print Dumper(\@f);
my $field = 5;
my $inode = $f[$field];
my $l = length($inode);
$inode =~ s/\s*ino:(\d+)\s*/$1/;
my $d = $drops{$inode} || 0;
$f[$field] = sprintf("%-*d", $l, $d);
print join('', @f); # if $d > 0;
}
close $fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment