::nsmcp::ServerRuntime ::nsmcp::ServerRuntime → schedulerComparison execute mode schedulerDiagnostics validate ::nsmcp::StatsTool ::nsmcp::StatsTool available encode unavailable ::nsmcp::ServerRuntime->::nsmcp::StatsTool ::nsmcp::ServerTopology ::nsmcp::ServerTopology execute ::nsmcp::ServerTopology->::nsmcp::StatsTool ::nsmcp::ServerHistory ::nsmcp::ServerHistory compactHistory execute options validate ::nsmcp::ServerHistory->::nsmcp::StatsTool ::nsmcp::Tool ::nsmcp::Tool dependenciesPresent describe execute init jsonArguments name permission validate ::nsmcp::StatsTool->::nsmcp::Tool ::nsmcp::Object ::nsmcp::Object ::nsmcp::Tool->::nsmcp::Object

Class ::nsmcp::ServerRuntime

::nsmcp::ServerRuntime[i] create ... \
           [ -adminExample (default "") ] \
           [ -adminSummary (default "") ] \
           [ -command (default "::ns_stats") ] \
           [ -description (default "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.") ] \
           [ -inputSchema (default " { "type": "object", "properties": { "mode": { "type": "string", "enum": [ "snapshot", "sample" ], "default": "snapshot" } }, "additionalProperties": false } ") ] \
           [ -name (default "server_runtime") ] \
           [ -outputSchema (default "") ] \
           [ -permission (default "diagnostics.runtime.read") ] \
           [ -schedulerCommand (default "::ns_info") ] \
           [ -schedulerStore (default "nsmcp:scheduler-observations") ]

Defined in /usr/local/ns/tcl/nsmcp/stats-tools.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nsmcp::StatsTool[i]
::nx::Class create ::nsmcp::ServerRuntime \
     -superclass ::nsmcp::StatsTool

Methods (to be applied on the object)

  • schedulerComparison (scripted, public)

     nsmcp::ServerRuntime[i] schedulerComparison previous current

    Compare scheduler counters from two observations of the same process.

    Parameters:
    previous (required)
    Previous observation, or empty if no baseline exists.
    current (required)
    Current observation and its process identity.
    Returns:
    Interval deltas and explicit reasons for unavailable metrics.

    Testcases:
    No testcase defined.
    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

Methods (to be applied on instances)

  • execute (scripted, public)

     <instance of nsmcp::ServerRuntime[i]> execute context arguments

    Read bounded runtime diagnostics for the selected server. Apply the validated inspection mode and retain unavailable capability and scheduler diagnostics.

    Parameters:
    context (required)
    Authenticated request context carrying the principal, grants and selected server.
    arguments (required)
    Rooted ns_json typed triples for the tool's JSON argument object.
    Returns:
    A rooted JSON tool-result object, including availability or job metadata as appropriate.

    Testcases:
    No testcase defined.
    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]]]
  • validate (scripted, public)

     <instance of nsmcp::ServerRuntime[i]> validate arguments

    Validate the runtime inspection mode. Decode the rooted JSON argument object and enforce this tool's option, range and combination constraints.

    Parameters:
    arguments (required)
    Rooted ns_json typed triples for the tool's JSON argument object.
    Returns:
    An empty result on success; invalid input raises RPC error -32602.

    Testcases:
    No testcase defined.
    if {[catch {
        :mode $arguments
    } message]} {
        return -code error -errorcode {NSMCP RPC -32602} $message
    }