ns::stats::Sampler method sampling tick (public)

 <instance of ns::stats::Sampler[i]> sampling tick

Defined in

Perform one scheduled collection and publish its interval sample. Skip collection when the sampler is stopped or another collection is in progress. Collect observations outside the coordination lock, then calculate and publish only if the sampler generation is still current. Retain the raw snapshot as the next interval baseline. Collection failures retain the previous publication, update error status and emit a warning. Does not write SQLite history; persistence runs through a separate callback.

Testcases:
No testcase defined.
Source code:
set generation {}
:locked {
    set state [nsv_get ns_stats control]
    if {![dict get $state running] || [dict get $state busy]} {
        return
    }
    set generation [dict get $state generation]
    dict set state busy true
    nsv_set ns_stats control $state
}
if {$generation eq ""} {
    return
}
try {
    set current [:snapshot]
    :locked {
        set state [nsv_get ns_stats control]
        if {$generation!=[dict get $state generation]} {
            return
        }
        set pair [nsv_get ns_stats pair]
        set previous [expr {$pair eq "" ? "" : [dict get $pair raw]}]
        set sample [:calculate $current $previous [dict get $state interval] [dict get $state instance]]
        dict set sample raw $current
        nsv_set ns_stats pair $sample
        dict set state busy false
        dict set state lastError {}
        nsv_set ns_stats control $state
    }
} on error {message options} {
    :locked {
        set state [nsv_get ns_stats control]
        if {$generation == [dict get $state generation]} {
            dict set state busy false
            dict incr state errors
            dict set state lastError $message
            nsv_set ns_stats control $state
        }
    }
    ns_log warning "ns_stats: sampling failed: $message"
}
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: