LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-11-2007, 09:30 AM   #1
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Rep: Reputation: 16
Finding out interface uptime


Is there any way to find out how long is an interface (e.g. ppp0) up?
I've looked through /proc/net and found nothing.
The only way I see so far, is getting bytes/packets received from /proc/net/dev along with a time stamp and then comparing against these values. Which seems like a dirty hack.
Anything better, please?

TIA.
 
Old 12-11-2007, 12:06 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by GSMD View Post
Is there any way to find out how long is an interface (e.g. ppp0) up?
For wired interface (e.g. eth0) you will see a line like this in the output of "dmesg":

[ 80.836871] e1000: eth0: e1000_watchdog: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX/TX
You will also see a similar line if the interface goes down. The number in brackets is the time in seconds since the system booted. Just write a script or program that can parse dmesg and diff the times. I would use a C program, but I am a programmer.
 
Old 12-13-2007, 07:27 AM   #3
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Original Poster
Rep: Reputation: 16
Thanks for your reply. Unfortunately, not the case for ppp.
 
Old 12-13-2007, 07:55 AM   #4
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Well then look at the creation time of the log of ppp?
In some cases, maybe checking /etc/resolv.conf modification time can do the trick.
 
Old 12-13-2007, 04:06 PM   #5
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Original Poster
Rep: Reputation: 16
Nope, got another idea
Code:
date +%s
gives the universal timestamp while
Code:
cat /proc/net/dev | grep ppp0 | cut -d":" -f2 | cut -d" " -f1
gives the number of bytes received.
For each round (BTW, this will be a Munin plugin) the current number of bytes received gets compared with the number of bytes received during the previous round (stored somewhere in file in /tmp/). If it's <, then the connection has been dropped and reestablished. Total uptime gets calculated during each round.

Last edited by GSMD; 12-13-2007 at 04:07 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Finding out Bonding mode of Interface ajeet528 Linux - Networking 4 07-09-2015 02:19 AM
Uptime: 2.4 vs 2.6 Synesthesia Linux - General 4 10-17-2005 03:23 PM
Finding the Best Interface on Linux wjacky Linux - Newbie 7 03-28-2005 08:38 PM
24/7 uptime? jollyjoice General 20 01-25-2005 11:12 AM
uptime skate Linux - Software 16 08-14-2003 03:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:05 PM.

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