Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
udpstat
#udpstat
======

UDP buffer size (RX, TX) and dropped packages statistics program, written by PZolee (pzoleex @ freemail.hu), 2012
https://github.com/pzolee/udpstat

This little tool lists the usage of the incoming and outgoing buffers of the UDP socket belongs to the specified port, and the number of dropped packages.

Example:

```bash
:~# ./udpstat.py 5001 -u 10
Start collecting RX and TX queue statistics information and dropped packages result for port (5001)
2012-09-03T14:28:38.550504;tx queue: 0 bytes, 0 KB, 0 MB; rx queue: 0 bytes, 0 KB, 0 MB; dropped packages: 0;
Expand Down Expand Up @@ -47,3 +50,4 @@ Options:
-u RUNTIME, --run-time=RUNTIME
The running time if given. Default: untill CTRL+C
-c, --csv Generate CSV output format
```
15 changes: 10 additions & 5 deletions udpstat.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def signal_handler(signal, frame):
exit(1)

hexport = "%x" % int(args[0])
HEXPORT = "%X" % int(args[0])

print "Start collecting RX and TX queue statistics information and dropped packages result for port (%s)" % args[0]

if opts.filename:
Expand All @@ -89,24 +91,27 @@ def signal_handler(signal, frame):
max_rx = 0
max_tx = 0

drops = 0
stime = atime = time.time()
while stime >= atime - opts.runtime:
f = open(udp_input, 'rb')
lines = f.readlines()
f.close()
for item in lines:
if search(hexport, item) != None:
if search(hexport, item) != None or search(HEXPORT, item) != None :
if search(HEXPORT, item) != None:
hexport=HEXPORT
buffers = item.strip().split() # 0:sl, 1:local_address, 2:rem_address, 3:st, 4:tx_queue rx_queue, 5:tr tm->when retrnsmt
# 6:retrnsmt, 7:uid, 8:timeout, 9:inode, 10:ref, 11:pointer, 12:drops
sl, la, ra, st, tx_rx, tr, retrnsmt, uid, timeout, inode, ref, pointer, drops = buffers
if opts.listened == 'local' and search(la.split(':')[1], hexport) == None:
if opts.listened == 'local' and ( search(la.split(':')[1], hexport) == None and search(la.split(':')[1], "0"+hexport) == None) :
# The local port does not match to the given local port
print "There is no matching port yet"
print "local :There is no matching port yet"
time.sleep(opts.freq)
continue
if opts.listened == 'remote' and search(ra.split(':')[1], hexport) == None:
if opts.listened == 'remote' and ( search(ra.split(':')[1], hexport) == None and search(la.split(':')[1], "0"+hexport) == None) :
# The remote port does not match to the given remote port
print "There is no matching port yet"
print "remote: There is no matching port yet"
time.sleep(opts.freq)
continue

Expand Down