Forum Discussion

mhuss3y_61750's avatar
mhuss3y_61750
Icon for Nimbostratus rankNimbostratus
Jun 05, 2009

Profile fallback statistics

I have a profile with fallback configured. Is there a way I can view/record the number of times fallback occurs or the profile is invoked?

 

3 Replies

  • Well you could do it if you assume the fall back is working when there is a LB failure.

    The following will trigger everytime the LB_FAILED event is triggered which assumes the fall back host is properly working)

     
     when RULE_INIT { 
          log local0. "Initialize the count of requests: [STATS::set fallback "current_count" 0]" 
          set ::count 0 
      
       } 
      
     when HTTP_REQUEST { 
       if { [HTTP::uri] starts_with "/give-me-stats-baby" } { 
             set html_content "Fallback StatisticsIncremented the current count to: [STATS::incr fallback 'current_count']" 
         HTTP::respond 200 content $html_content 
       } 
     } 
      
     when LB_FAILED {    
       log local0. "Incremented the current count to: [STATS::incr fallback "current_count"]" 
     }    
      
      
     

    The output will be:

    Rule stats_rule : Incremented the current count to: 100

    You can also go further by adding /give-me-stats-baby it will output the count via HTML. However please be aware that if you reboot or re-initialize the irule it will go straight back to 0. Also keep in mind that I have tested this so there might be some syntax issue but the general logic is there.

    Hope this helps,

    CB

  • Thanks CB.. i receive error message:

     

     

    01070151:3: Rule [test] error:

     

    line 2: [command is not valid in current event context (RULE_INIT)] [STATS::set fallback "current_count" 0]

     

     

    when I try to create the irule....