Class ::nsmcp::ServerRuntime (public)
::nx::Class ::nsmcp::ServerRuntime
Defined in /usr/local/ns/tcl/nsmcp/stats-tools.tcl
- Testcases:
- No testcase defined.
Source code: :public object method schedulerComparison {previous current} { # # Compare scheduler counters from two observations of the same process. # # @param previous Previous observation, or empty if no baseline exists. # @param current Current observation and its process identity. # @return Interval deltas and explicit reasons for unavailable metrics. # set result [dict create available false scope process baselineSource previous-server-runtime-call to [dict get $current observedAt]] if {$previous eq ""} { dict set result reason no-baseline return $result } dict set result from [dict get $previous observedAt] if {[dict get $previous identity] ne [dict get $current identity]} { dict set result reason process-changed return $result } set elapsed [expr {[dict get $current observedAt]-[dict get $previous observedAt]}] if {$elapsed <= 0} { dict set result reason nonpositive-interval return $result } dict set result elapsedSeconds $elapsed dict set result available true set metrics {} foreach phase {waitReturnLateness mutexAcquisition nonThreadedCallbacks dispatchLateness dispatchDelay workerQueueDelay threadedCallbacks callbackOverrun} { set entry [dict create available false] if {![dict exists $previous counters $phase] || ![dict exists $current counters $phase]} { dict set entry reason phase-unavailable } else { set a [dict get $previous counters $phase] set b [dict get $current counters $phase] set valid true foreach field {count over100ms totalSeconds maxSeconds} { if {![dict exists $a $field] || ![dict exists $b $field] || ![string is double -strict [dict get $a $field]] || ![string is double -strict [dict get $b $field]]} { set valid false break } } if {!$valid} { dict set entry reason counters-unavailable } elseif {[dict get $b count] < [dict get $a count] || [dict get $b over100ms] < [dict get $a over100ms] || [dict get $b totalSeconds] < [dict get $a totalSeconds] || [dict get $b maxSeconds] < [dict get $a maxSeconds]} { dict set entry reason counters-reset } else { set count [expr {[dict get $b count]-[dict get $a count]}] set total [expr {[dict get $b totalSeconds]-[dict get $a totalSeconds]}] dict set entry available true dict set entry observationsDelta $count dict set entry over100msDelta [expr {[dict get $b over100ms]-[dict get $a over100ms]}] dict set entry totalSecondsDelta $total dict set entry averageSeconds [expr {$count > 0 ? $total/double($count) : ""}] dict set entry newMaximum [expr {[dict get $b maxSeconds] > [dict get $a maxSeconds]}] } } dict set metrics $phase $entry } dict set result metrics $metrics dict set result limitations {Deltas cover all scheduler jobs in this observation interval, not the warning query window or a specific callback. A positive over100msDelta shows threshold crossings during the interval; the lifetime maximum callback does not attribute smaller observations. newMaximum identifies only a newly increased lifetime maximum; use current counters for its callback and observation time. Zero over100msDelta excludes only observations above that threshold, not all delay. Baselines are shared by server_runtime callers on this virtual server and updated on each successful scheduler read; concurrent or nonpositive observation intervals are unavailable. Worker/queue values remain current gauges; peaks remain lifetime maxima.} return $result } :property {name server_runtime} :property {schedulerCommand ::ns_info} :property {schedulerStore nsmcp:scheduler-observations} :method schedulerDiagnostics {} { # Always collected now, even when runtime data comes from a shared sample. set result [dict create scope process observedAt [clock seconds]] if {[catch { ${:schedulerCommand} scheduler } counters]} { dict set result available false dict set result reason {ns_info scheduler is unavailable or failed; scheduler timings are unknown.} } else { dict set result available true dict set result counters $counters # One bounded NSV slot survives interpreter changes and module reload. # Atomic exchange avoids separate get/set races; out-of-order reads # are rejected by the comparison's interval check. if {[catch { set identity [list [ns_info pid] [ns_info boottime]] }]} { dict set result comparison {available false reason process-identity-unavailable} } else { set current [dict create identity $identity observedAt [expr {[clock microseconds]/1000000.0}] counters $counters] set previous [nsv_set -reset ${:schedulerStore} latest $current] dict set result observedAt [dict get $current observedAt] dict set result comparison [::nsmcp::ServerRuntime schedulerComparison $previous $current] } } return $result } :property {description {Read ns_stats runtime diagnostics for the authenticated server. mode snapshot (default) collects current gauges and cumulative counters; mode sample returns the latest published interval rates and CPU percentages. sampling reports readiness, age and running state. Process CPU, drivers, allocator and database-pool metrics remain process-wide. Timestamp is epoch microseconds; phase times are seconds; CPU percentages use one core as 100%. Also returns scheduler diagnostics from ns_info scheduler when supported: current process-lifetime cumulative timing counters, maxima and job IDs, collected at scheduler.observedAt independently of snapshot/sample time. Newer cores distinguish dispatchDelay (actual queue deadline to dequeue), workerQueueDelay (dequeue to worker pickup), threadedCallbacks runtime and callbackOverrun (completion beyond next nominal time), with current/peak workers and queue counts. Maximum context includes maxObservedAt (Unix seconds), bounded maxCallback text and maxCallbackTruncated when supported, including completed one-shot jobs. dispatchLateness retains nominal-time lateness and is not necessarily actual dispatch delay. Missing phase fields on older cores are unknown, not zero. Scheduler availability is explicit on older versions. scheduler.comparison compares cumulative counters with the previous successful server_runtime scheduler read on this virtual server, shared across callers/interpreters. The first read establishes a baseline; later reads report explicit from/to/elapsedSeconds and per-phase observationsDelta, over100msDelta, totalSecondsDelta, averageSeconds and newMaximum. Missing phases, process changes, resets and nonpositive intervals remain unavailable. Deltas cover all jobs, not specific callbacks or the warning window. Zero threshold crossings distinguish isolated maxima from recent delays above 100 ms but do not exclude smaller delays. Current workers/queues and lifetime maxima remain separate. Does not start or change sampling.}} :property {inputSchema { { "type": "object", "properties": { "mode": { "type": "string", "enum": [ "snapshot", "sample" ], "default": "snapshot" } }, "additionalProperties": false } }} :method mode {arguments} { if {[lindex $arguments 1] ne "object"} { error "Expected arguments object" } set mode snapshot foreach {key type value} [lindex $arguments 2] { if {$key ne "mode" || $type ne "string" || $value ni {snapshot sample}} { error "Supply only mode snapshot or sample" } set mode $value } return $mode } :public method validate {arguments} { # # Validate the runtime inspection mode. # # Decode the rooted JSON argument object and enforce this tool's option, # range and combination constraints. # # @param arguments Rooted ns_json typed triples for the tool's JSON argument # object. # # @return An empty result on success; invalid input raises RPC error -32602. # if {[catch { :mode $arguments } message]} { return -code error -errorcode {NSMCP RPC -32602} $message } } :public method execute {context arguments} { # # Read bounded runtime diagnostics for the selected server. # # Apply the validated inspection mode and retain unavailable capability and # scheduler diagnostics. # # @param context Authenticated request context carrying the principal, # grants and selected server. # @param arguments Rooted ns_json typed triples for the tool's JSON argument # object. # # @return A rooted JSON tool-result object, including availability or job # metadata as appropriate. # if {![:available]} { return [:unavailable $context] } set mode [:mode $arguments] set data [${:command} $mode -server [$context server]] set status [${:command} sampling status] return [list {} object [list server string [$context server] available boolean true mode string $mode sampling object [:encode metrics $status] scheduler object [:encode schedulerDiagnostics [:schedulerDiagnostics]] runtime object [:encode runtime $data]]] }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)