Forum Discussion

Bret_McGinnis_1's avatar
Bret_McGinnis_1
Icon for Nimbostratus rankNimbostratus
Sep 09, 2005

Clock time

I want to track the length of time that a pool is down and send a syslog message with the downtime in hours:minutes:seconds format. I'm still not that familiar with TCL and having some difficulty using the clock command. Can you provide some insight.

 

 

Regards,
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Well, first, I would not recommend to heavily using the clock command until 9.2 as it does have a potential performance impact (however, it may not effect you enough to be concerned about it).

    The main command to use is [clock seconds] which will return you the number of seconds since epoch. You can use this to easily compute the number of seconds that a pool member has been down. To then format this into something more human readable you would use the [clock format] command. Eg:

    
    when RULE_INIT {
       array set ::down_nodes { }
    }
    when LB_FAILED {
       set cur_time [clock seconds]
       set server [LB::server addr]
        Has this member been down for more than one request
       if { [info exists ::down_nodes($server)] } {
          set delta [expr $cur_time - $::down_nodes($server)]
           Start logging after the member has been down for more than 60 secs
          if { $delta > 60 } {
             log local0. "Pool member [LB::server] down [clock format $delta -format {%H:%M:%S}]"
          }
       }
       set ::down_nodes($server) $cur_time
    }
    when LB_SELECTED {
        Clear out a down node that is now up
       if { [info exists ::down_nodes([LB::server addr])] } {
          unset ::down_nodes([LB::server addr])
       }
    }
  • Thank you. I just figured it out on my own. I think this is the second time that got an irule to work on my own and then checked my email only to find the answer waiting for me.

     

     

    One addition note: I found that the time displayed was 16 hours off. I did some reading and found that i needed to add "-gmt 1" to the "clock format" command to get it to display the proper time.

     

     

    One additional question: Your irule used an "unset" command. I have not seen that used before. It would simplify some of my checking for not exist or an undisired value. Is there anything I should be careful about when using it.

     

     

     

    Thanks again.

     

     

     

    Regards,

     

     

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Is there anything I should be careful about when using it (unset)?

     

     

    "unset" deletes a variable. So, the only thing you need to be careful about when using it is that you properly detect when a variable does not exist - otherwise you will get a rule error. So, just be sure to use "info exists" in a conditional around accessing the variable.