-   Linux - Networking (
-   -   Finding out interface uptime (

GSMD 12-11-2007 09:30 AM

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?


David1357 12-11-2007 12:06 PM


Originally Posted by GSMD (Post 2987179)
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.

GSMD 12-13-2007 07:27 AM

Thanks for your reply. Unfortunately, not the case for ppp.

nx5000 12-13-2007 07:55 AM

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.

GSMD 12-13-2007 04:06 PM

Nope, got another idea :)

date +%s
gives the universal timestamp while

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.

All times are GMT -5. The time now is 04:52 AM.