ns::stats::SQLiteHistory method history configure (public)

 <instance of ns::stats::SQLiteHistory[i]> history configure \
    -pool pool  [ -retention retention ] [ -maxBytes maxBytes ]

Defined in

Validate the database pool and retention limits, initialize the schema and start a separate persistence callback. Repeated configuration with identical settings is harmless; changing active settings requires disabling persistence first. Return the resulting history status. Does not start sampling. Normalize retention to fractional seconds and maxBytes to bytes with ns_baseunit before validating the bounds.

Switches:
-pool (required)
-retention (optional, defaults to "86400")
-maxBytes (optional, defaults to "67108864")

Testcases:
No testcase defined.
Source code:
set retention [ns_baseunit -time $retention]
set maxBytes [ns_baseunit -size $maxBytes]
if {$retention < 60 || $retention > 604800 || $maxBytes < 4194304} {
    error "retention must be 60..604800 seconds and maxBytes at least 4 MiB"
}
if {[info commands ns_db] eq ""} {
    error "history requires nsdb/nsdbsqlite"
}
set config [dict create  enabled true pool $pool retention $retention maxBytes $maxBytes  owner [ns_info server]  busy false scheduler {}  generation [clock microseconds] lastSaved {}  failures 0 lastFailure {} lastLoggedAt 0 gaps {}  mixins [:info object mixins] topology {} topologyAt 0]
set old [nsv_get ns_stats history]
if {$old ne "" && [dict get $old enabled]} {
    foreach k {pool retention maxBytes owner} {
        if {[dict get $old $k] ne [dict get $config $k]} {
            error "history already configured differently; disable before reconfiguring"
        }
    }
    return [:history status]
}
set db [:historyConnect $config]
try {
    :historySchema $db
} finally {
    ns_db releasehandle $db
}
:locked {
    set old [nsv_get ns_stats history]
    if {$old ne "" && [dict get $old enabled]} {
        error "history was concurrently configured; retry"
    }
    dict set config scheduler [ns_schedule_proc -thread 1 [self] history persist]
    nsv_set ns_stats history $config
}
return [:history status]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: