LDAP_ Measure_ Reporting

Problem this snippet solves:

This is an iRule that goes with the LDAP_Stats_measure iRule and provides a web accessible polling interface for the stats gathered by the LDAP_Stats_Measure iRule.

the stats are returned in a ':' delimited list by user (Plus total). Only active users are returned.

requires 10.1.0 or later

Code :

timing on

when RULE_INIT {

    # Variables to hold connection status, table names etc...
set tableName    "ldap_measure"
set static::lmr_logseq 0


set content ""

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 }]
set timestamp "[expr {(($secs % 86400) * 1000) + $fract}]"

set total_conn_count  [table keys -count -subtable "$tableName.connections"]
#set timeNow [clock seconds]

switch [HTTP::uri] {
"/status" {
set content ":${static::lmr_logseq}:${timestamp}
incr static::lmr_logseq

foreach uid [table keys -subtable "$tableName.activeUsers"] {
#set user_conn_count [table keys -count -subtable "$tableName.user.${uid}.connections"]
#set content "${content}${timeNow}

set user_search_active [table keys -count -subtable "${static::tableName}.user.$uid.searchactive"]
set all_search_active [table keys -count -subtable "${static::tableName}.total.searchactive"]
set user_conn_active [table keys -count -subtable "${static::tableName}.user.${uid}.connections"]
set all_conn_active [table keys -count -subtable "${static::tableName}.connections"]
set user_search_total [table lookup -subtable "${static::tableName}.user.${uid}" "searchcount"]
set all_search_total [table lookup -subtable "${static::tableName}.total" "searchcount"]
set user_conn_total [table lookup -subtable "${static::tableName}.user.${uid}" "conncount"]
set all_conn_total [table lookup -subtable "${static::tableName}.total" "conncount"]
set user_msg_count [table lookup -subtable "${static::tableName}.user.${uid}" "msgcount"]
set conn_msg_count 0
set all_msg_count[table lookup -subtable "${static::tableName}.total" "msgcount"]
set user_search_elapsed [table lookup -subtable "${static::tableName}.user.${uid}" "elapsed"]
set conn_search_elapsed 0
set all_search_elapsed [table lookup -subtable "${static::tableName}.total" "elapsed"]
                set conn_search_total 0

#log local0. "all_conn_active ${all_conn_active}"
                                set content "${content}:${static::lmr_logseq}:$timestamp:status:${uid}:UNKNOWN:${user_search_active}: \
                                                   ${all_search_active}:${user_conn_active}:${all_conn_active}:${user_conn_total}:${all_conn_total}: \
                                                   ${user_search_total}:${conn_search_total}:${all_search_total}:${user_conn_total}:${all_conn_total}: \
                                                   ${user_msg_count}:${conn_msg_count}:${all_msg_count}:${user_search_elapsed}: \
incr static::lmr_logseq 1
set last_message [clock seconds]


HTTP::respond 200 content $content

Tested this on version:

Published Mar 18, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment