Class ::nsmcp::ServerRuntime (public)

 ::nx::Class ::nsmcp::ServerRuntime[i]

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

Testcases:
No testcase defined.
Source code:
    :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::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} {
        if {[catch {:mode $arguments} message]} {
            return -code error -errorcode {NSMCP RPC -32602} $message
        }
    }

    :public method execute {context arguments} {
        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
[ hide source ] | [ make this the default ]
Show another procedure: