Sponsored Content
Top Forums UNIX for Advanced & Expert Users Amount of Network Traffic info from netstat output Post 302595840 by agama on Sunday 5th of February 2012 12:25:43 PM
Old 02-05-2012
I'm not sure what you mean by 'traffic,' so I'll assume total bytes. If not, the technique can be applied to other measurements.

The output from netstat is a total count since 'the beginning of time' which is probably the last boot. The man page I just checked didn't give any indication so that's my assumption.

Regardless, in order to know what your traffic is, you have to capture a baseline value, and then at sometime in the future, capture a second value with the difference being the traffic over that period of time.

A small script like this can present output counts by the minute:

Code:
#!/usr/bin/env ksh

# print two values to stdout: outoctet count and inoctet count
function get_stats
{
    netstat  -s wlan0 | awk '        #<<<< change for your interface or remove for all
    /OutOctets/ { out=$2; next;}
    /InOctets:/ { inp = $2; next} 
    END {print out, inp }
    '
}

get_stats | read baseo basei   # seed the baseline values
while true
do
    sleep 60
    get_stats | read newo newi
    echo "inbound $(( newi - basei ))/min  outbound $(( newo - baseo ))/min"
    basei=$newi               # current becomes the baseline
    baseo=$newo
done

One note: Bash is not able to handle the syntax 'command | read x y' so this isn't a portable script. If you want to use this under bash you'll need to change each get_stats statement to these three:

Code:
values=$(get_stats)                    # bash compatable
baseo=${values% *}
basei=${values#* }

This User Gave Thanks to agama For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

monitoring network traffic

there are commands to monitor the memory, paging, io... how about network traffic. i mean commands to see whether the network traffic (LAN) is congested? the closest i got is netstat thanks (6 Replies)
Discussion started by: yls177
6 Replies

2. Cybersecurity

How to capture network traffic

Hi, Can someone give me the clue on how to capture network traffic at gateway. Thanx (2 Replies)
Discussion started by: kayode
2 Replies

3. Infrastructure Monitoring

Network Traffic

Hi all, Got a strange one here, well not so much strange, different :-) I need to work out if a server is particulary chatty, whether its talking / communicating heavily to a particular server, as Im planning to physically move the server to a different server, over a link. Hence the... (6 Replies)
Discussion started by: sbk1972
6 Replies

4. Solaris

'netstat' info on Solaris

Hello All I just wanted to know if on solaris ,below two commands need to be run separately unlike AIX where "/usr/bin/netstat -an -f inet " gives tcp as well as udp info. /usr/bin/netstat -an -f inet -P tcp /usr/bin/netstat -an -f inet -P udp Also is there any way i can make these two... (10 Replies)
Discussion started by: ak835
10 Replies

5. HP-UX

Monitoring traffic in the network

I Colleagues, Somebody can say me how to monitoring traffic in the network. also I am interested in monitoring memory. if somebody to know a guide with command advanced in unix welcome for me. Thank you for adcanced. (0 Replies)
Discussion started by: systemoper
0 Replies

6. Infrastructure Monitoring

How do I know what traffic is in network port?

If I would like to know what connection , data , traffic in a network port ( eth0 ) , what can I do ? ps. because I always found the network is very slow , so I would like what the network port is doing . Thanks Login ID ust3 is currently in read-only mode for multiple infractions. Creating... (0 Replies)
Discussion started by: ust03
0 Replies

7. UNIX for Advanced & Expert Users

How to throttle network traffic?

Hi All I am resilience testing an application that is spread across multiple servers. One thing I will need to do soon is throttle the network traffic for specific interfaces within the test cluster. Specifically, maybe make a connection take twice or three times as long to respond.... I... (3 Replies)
Discussion started by: bbq
3 Replies

8. Shell Programming and Scripting

Help with netstat traffic server command

Help required for creating a unix shell script using netstat command for retrieving total traffic in Kbytes with the source and destination address. (4 Replies)
Discussion started by: Samee
4 Replies

9. IP Networking

I would like to monitor network traffic for a computer on my network

My son does homework on a school laptop. I was thinking about setting up a gateway on my home network, so that I can monitor web traffic and know if he is doing his homework without standing over his shoulder. Ideally I would like to use the Raspberry Pi Model b that I already have. However, I... (15 Replies)
Discussion started by: gandolf989
15 Replies
UNCONFINED(8)							     AppArmor							     UNCONFINED(8)

NAME
aa-unconfined - output a list of processes with tcp or udp ports that do not have AppArmor profiles loaded SYNOPSIS
aa-unconfined DESCRIPTION
aa-unconfined will use netstat(8) to determine which processes have open network sockets and do not have AppArmor profiles loaded into the kernel. BUGS
aa-unconfined must be run as root to retrieve the process executable link from the /proc filesystem. This program is susceptible to race conditions of several flavours: an unlinked executable will be mishandled; an executable started before a AppArmor profile is loaded will not appear in the output, despite running without confinement; a process that dies between the netstat(8) and further checks will be mishandled. This program only lists processes using TCP and UDP. In short, this program is unsuitable for forensics use and is provided only as an aid to profiling all network-accessible processes in the lab. If you find any bugs, please report them to bugzilla at <http://bugzilla.novell.com>. SEE ALSO
netstat(8), apparmor(7), apparmor.d(5), change_hat(2), and <http://forge.novell.com/modules/xfmod/project/?apparmor>. NOVELL
/SUSE 2008-06-11 UNCONFINED(8)
All times are GMT -4. The time now is 08:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy