LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-08-2012, 01:10 AM   #1
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Rep: Reputation: 15
Port Counters


Hi,

I want to read the Rx/TX Pkts/Bytes on an ethernet port. I know ifconfig will give this. Is there any command which will
give these values or should I parse the ifconfig output to get the value? How do I clear these counters?

Thanks,
Dhanesh.
 
Old 08-08-2012, 01:44 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

you should be able to get this information directly from /proc/net/dev
The values will continue to increase, instead or "reseting" them you should subtract from the previous reading.

Evo2.
 
Old 08-09-2012, 12:22 AM   #3
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Original Poster
Rep: Reputation: 15
Thanks Evo, I meant, is there a system call or ioctl call to read these values or should I write a C code to
parse them?
 
Old 08-09-2012, 12:34 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

sorry don't know about any system calls.

But it's not hard to parse, and the there is no need to write in c. Write it in whatever language you like. I use a widget written in lua (for awesome wm) that reads /proc/net/dev to provide upload/download stats.

What are you actually trying to do?

Evo2.
 
Old 08-09-2012, 11:06 PM   #5
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Original Poster
Rep: Reputation: 15
Iam trying to read Tx /RX bytes/packets for a given ethernet interface
 
Old 08-13-2012, 06:02 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

so I don't see what your problem is. How about the following that outputs the number of rx and tx in ~= 1 sec intervals.
Code:
#!/bin/bash
device="eth0"
first=0
while true ; do
    while read line ; do
	a=($line)
	if [ "${a[0]}" != "${device}:" ] ; then
	    continue
	fi
	if [ $first -ne 0 ] ; then
	    rx=$(( ${a[2]} - $rxsum ))
	    tx=$(( ${a[9]} - $txsum ))
	    echo "${a[0]} $rx $tx"
	fi
	rxsum=${a[2]}
	txsum=${a[9]}
	first=1
    done < /proc/net/dev
    sleep 1
done
Evo2.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't zero-out counters in iptables didooofidooo Linux - Security 5 02-25-2010 02:51 PM
hit counters icecubeflower General 6 11-24-2009 10:08 AM
traffic counters blazkovskib Linux - Networking 1 11-03-2006 09:21 AM
iptables counters? matthewa Linux - Security 1 09-27-2005 11:07 PM
Mozilla counters in the cache Chiel Linux - Newbie 1 08-29-2004 05:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration