How to remotely check connection uptime?

Discussion in 'Tomato Firmware' started by jyavenard, Aug 19, 2008.

  1. jyavenard

    jyavenard Network Guru Member


    When you browse the main tomato firmware page, it shows the connection uptime...

    Any ideas how it calculates that value ? I can't find it anywhere ...

  2. jyavenard

    jyavenard Network Guru Member

    Ok, here it is

    little exe running directly on your wrt54...

    source code attached

    only tested on Tomato ; not sure it will work on any other firmware

    Attached Files:

  3. TexasFlood

    TexasFlood Network Guru Member

    It's part of the output of the "uptime" command (right after "up") which you can run from telnet or SSH.
  4. rhester72

    rhester72 Network Guru Member

    You can also get this from snmpd if you are running it (external binary).

  5. jyavenard

    jyavenard Network Guru Member

    It's not that easy unfortunately.
    uptime shows how long the system has been up. Not how long the connection has been on, like how the the pppoe session laster.

    What I'm interested in is what Tomato displays on the main page under the line "Connection uptime"

    This information isn't available over SNMP either.

    The program I posted before is extracted from Tomato httpd (javascript) that retrieve that value.
    The way it works is:
    whenever the WAN goes up, a timestamp is stored in /var/lib/misc/wantime (a long int is stored).
    To find out how long the WAN has been up you subtract that value to the current uptime.

  6. PeterT

    PeterT Network Guru Member

    Wouldn't a brute force approach be to have a WAN up script that eched the time to a logfile...
  7. TexasFlood

    TexasFlood Network Guru Member

    Apologies, I obviously didn't read the original post carefully enough.

    You could just echo a timestamp in whatever format you wanted at the start of the "WAN Up" script tab. So I did that just now, trying to figure out how to translate the value in /tmp/var/lib/misc/wantime.

    The output of the date command on the WAN Up tab was:
    Wed Aug 20 12:53:43 MDT 2008

    and wantime is:

    # hexdump /tmp/var/lib/misc/wantime
    0000000 000b 0000

    Haven't figured out the format yet, but if I can then it might just be easier to use wantime.
  8. jyavenard

    jyavenard Network Guru Member

    Looks like you didn't read my 2nd post either ... I explained there the wantime var already and what it contained
  9. TexasFlood

    TexasFlood Network Guru Member

    So maybe I'm a slow learner, :grin: I'm not a programmer so this stuff doesn't come naturally to me. I did see your post and understand what it contains, in theory. But I didn't see how to translate it directly into a timestamp. Of course, maybe isn't worth it since you already provided the answer. So probably would just be satisfying my curiosity at this point.

    *Update: OK, I get it now.

    I was thinking that it was more complicated than it really was.

    When you said timestamp, I was thinking absolute time rather than relative. That's where I got confused. But it's simply relative time in seconds. After I rebooted a coiuple of times and it kept coming up "000b 0000", I finally woke up and realized that it was just the relative 11 seconds that it takes my WAN to come up after the system does. OK, I may be a slow learner, but I can learn, :biggrin:
  10. jyavenard

    jyavenard Network Guru Member

    No it really is rather simple. When the connection is established using either PPP, PPPoE, PPTP etc... the timestamp in seconds is stored as a long (32 bits) in this /var/lib/misc/wantime.

    That value is retrieved from the linux system structure provided by sysinfo (on a linux prompt, type man sysinfo.

    To find out how long it's been running, you look at the current time value in sysinfo and substract the value stored in wantime

    The only tricky bit (which isn't included in the source code provided earlier) is that the variable wantime isn't removed when the WAN connection drops. So you also have to check if the WAN connection is up.
    The author of Tomato wrote some very nice code to check if the WAN is up ; which is no trivial task when you see all the various connection used for WAN

    The WRT54 is a great toy to learn about embedded linux , and that the full source code is supplied is a huge help...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice