Class ::nsmcp::ServerHistory (public)
::nx::Class ::nsmcp::ServerHistory
Defined in /usr/local/ns/tcl/nsmcp/lib/stats-tools.tcl
- Testcases:
- No testcase defined.
Source code: :property {name server_history} :property {description {Query persisted ns_stats intervals for the authenticated server. Defaults to the last 10 completed minutes. Use lastMinutes, period previous-hour, or explicit from/to (Unix seconds; half-open interval, at most 24 hours). Return records, referenced topologies, persistence status and coverage including gaps, restarts, evictions and write failures. Never assume complete coverage from record count. Follow nextArguments unchanged for stable paging; a page is not a complete window. Does not enable sampling or persistence. Requires separately configured ns_stats SQLite history. Process metrics remain process-wide.}} :property {inputSchema {{} object {type string object properties object { lastMinutes object {type string integer minimum number 1 maximum number 1440 default number 10} period object {type string string enum array {0 string previous-hour}} from object {type string integer minimum number 0 description string {Inclusive Unix epoch seconds}} to object {type string integer minimum number 1 description string {Exclusive Unix epoch seconds}} limit object {type string integer minimum number 1 maximum number 100 default number 12} cursor object {type string integer minimum number 0 description string {Paging timestamp in microseconds; requires explicit from/to}} } additionalProperties boolean false}}} :method options {arguments} { if {[lindex $arguments 1] ne "object"} { error "Expected arguments object" } set options {limit 12 cursor 0} foreach {key type value} [lindex $arguments 2] { if {$key eq "period"} { if {$type ne "string" || $value ne "previous-hour"} { error "period must be previous-hour" } } elseif {$key ni {lastMinutes from to limit cursor} || $type ne "number" || ![string is entier -strict $value]} { error "Supply integer time and paging options, or period previous-hour" } dict set options $key $value } set explicit [expr {[dict exists $options from] || [dict exists $options to]}] set relative [expr {[dict exists $options lastMinutes] + [dict exists $options period]}] if {$relative > 1 || ($explicit && $relative)} { error "Use lastMinutes, period, or paired from/to" } if {$explicit && (![dict exists $options from] || ![dict exists $options to])} { error "Supply both from and to" } if {!$explicit && [dict get $options cursor] != 0} { error "Paging requires the returned explicit from/to bounds" } set now [clock seconds] if {[dict exists $options period]} { set end [expr {($now / 3600) * 3600}] dict set options from [expr {$end - 3600}] dict set options to $end dict unset options period } elseif {!$explicit} { set minutes 10 if {[dict exists $options lastMinutes]} { set minutes [dict get $options lastMinutes] dict unset options lastMinutes } if {$minutes < 1 || $minutes > 1440} { error "lastMinutes must be 1..1440" } set end [expr {($now / 60) * 60}] dict set options from [expr {$end - $minutes * 60}] dict set options to $end } dict with options {} if {$from < 0 || $to <= $from || $to > $now || $to - $from > 86400 || $limit < 1 || $limit > 100 || $cursor < 0 || ($cursor != 0 && ($cursor < $from * 1000000 || $cursor >= $to * 1000000))} { error "Expected a past window up to 24 hours, limit 1..100 and a cursor within the window" } return $options } :public method validate {arguments} { if {[catch {:options $arguments} message]} { return -code error -errorcode {NSMCP RPC -32602} $message } } :public method execute {context arguments} { if {![:available]} { return [:unavailable $context] } set options [:options $arguments] set status [${:command} history status] set configured [dict exists $status pool] set fields [list server string [$context server] available boolean true configured boolean $configured persistence object [:encode metrics $status]] if {!$configured} { lappend fields reason string {Configure ns_stats history with a dedicated nsdbsqlite pool to retain interval samples.} return [list {} object $fields] } set query [list ${:command} history query -server [$context server]] dict for {key value} $options { lappend query -$key $value } set history [{*}$query] lappend fields history object [:encode history $history] if {[dict get $history more]} { set next [list from number [dict get $history from] to number [dict get $history to] limit number [dict get $options limit] cursor number [dict get $history nextCursor]] lappend fields nextArguments object $next } else { lappend fields nextArguments null {} } return [list {} object $fields] }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)