Forum Discussion

eschurma_27945's avatar
eschurma_27945
Icon for Nimbostratus rankNimbostratus
Oct 24, 2007

Retrieving time in milliseconds? (using v. 9.1.2)

I am trying to retrieve the current time, down to the number of milliseconds. I can't find any way to do this (I am using v9.1.2). If I use "clock milliseconds" I get the error

 

 

01070151:3: Rule [timestamp_remove_add2] error:

 

line 3: [invalid option "milliseconds" must be: clicks format scan seconds] [milliseconds]

 

line 5: [command is not valid in the current scope] [}]

 

 

"clock seconds" works fine. I can use "clock clicks -milliseconds", but that doesn't give me the actual time - just the click count expressed in milliseconds, which doesn't seem to be tied to any meaningful zero point. Is there any way to get the current actual time down to the millisecond level?

 

 

Thanks!

 

Eric

3 Replies

  • Try this:

     

     

    
    when CLIENT_ACCEPTED {
    set secs [clock seconds]
    set msec [clock clicks -milliseconds]
    set base [expr { $secs * 1000 } ]
    set fract [expr { $msec - $base }]
    if { $fract >= 1000 } {
    set diff [expr { $fract / 1000 }]
    incr secs $diff
    incr fract [expr { -1000 * $diff }]
    }
    log local0. "Timestamp with milliseconds is [clock format $secs -format {%H:%M:%S}].$fract"
    }

     

     

    My log entries with this code look like this:

     

     

    Oct 25 08:16:47 tmm tmm[1541]: Rule logtime_rule : Timestamp with milliseconds is 08:16:47.399

     

    Oct 25 08:16:49 tmm tmm[1541]: Rule logtime_rule : Timestamp with milliseconds is 08:16:49.575

     

    Oct 25 08:16:49 tmm tmm[1541]: Rule logtime_rule : Timestamp with milliseconds is 08:16:49.582

     

     

     

    Note that you really shouldn't use the clock command on production traffic unless your LTM is at least at version 9.2.

     

     

    Modified from an example found here: http://wiki.tcl.tk/1035 Click here

     

     

  • would that work? Doesn't it assume that the clicks started on a second boundary? The TCL docs say that clicks aren't aligned with any particular epoch.

     

     

    More importantly, can you elaborate on the problems with using the clock command on versions prior to 9.2 in production traffic?
  • Yes, but it's the closest way I could think of to get you to your desired goal.

     

     

    The issues prior to 9.2. are related the efficiency of the implementation of the command. The developers warned against using it pre-9.2. Search the forum if you want the details. I believe the post detailing the problems was authored by unRuleY.