Forum Discussion
Bret_McGinnis_1
Nimbostratus
Sep 09, 2005Clock 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,
3 Replies
- unRuleY_95363Historic F5 AccountWell, 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]) } } - Bret_McGinnis_1
Nimbostratus
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_95363Historic F5 AccountIs 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.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects