2026-01-25 12:09:28 +00:00
<!DOCTYPE html>
<!-- retoor <retoor@molodetz.nl> -->
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title > sysinfo - Wren-CLI Manual</ title >
< link rel = "stylesheet" href = "../css/style.css" >
</ head >
< body >
< button class = "mobile-menu-toggle" > Menu</ button >
< div class = "container" >
< aside class = "sidebar" >
< div class = "sidebar-header" >
< h1 >< a href = "../index.html" > Wren-CLI</ a ></ h1 >
< div class = "version" > v0.4.0</ div >
</ div >
< nav class = "sidebar-nav" >
< div class = "section" >
< span class = "section-title" > Getting Started</ span >
< ul >
< li >< a href = "../getting-started/index.html" > Overview</ a ></ li >
< li >< a href = "../getting-started/installation.html" > Installation</ a ></ li >
< li >< a href = "../getting-started/first-script.html" > First Script</ a ></ li >
< li >< a href = "../getting-started/repl.html" > Using the REPL</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > Language</ span >
< ul >
< li >< a href = "../language/index.html" > Syntax Overview</ a ></ li >
< li >< a href = "../language/classes.html" > Classes</ a ></ li >
< li >< a href = "../language/methods.html" > Methods</ a ></ li >
< li >< a href = "../language/control-flow.html" > Control Flow</ a ></ li >
< li >< a href = "../language/fibers.html" > Fibers</ a ></ li >
< li >< a href = "../language/modules.html" > Modules</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > API Reference</ span >
< ul >
< li >< a href = "index.html" > Overview</ a ></ li >
< li >< a href = "string.html" > String</ a ></ li >
< li >< a href = "number.html" > Num</ a ></ li >
< li >< a href = "argparse.html" > argparse</ a ></ li >
< li >< a href = "base64.html" > base64</ a ></ li >
< li >< a href = "crypto.html" > crypto</ a ></ li >
< li >< a href = "dataset.html" > dataset</ a ></ li >
< li >< a href = "datetime.html" > datetime</ a ></ li >
< li >< a href = "dns.html" > dns</ a ></ li >
< li >< a href = "env.html" > env</ a ></ li >
< li >< a href = "fswatch.html" > fswatch</ a ></ li >
< li >< a href = "html.html" > html</ a ></ li >
< li >< a href = "http.html" > http</ a ></ li >
< li >< a href = "io.html" > io</ a ></ li >
< li >< a href = "jinja.html" > jinja</ a ></ li >
< li >< a href = "json.html" > json</ a ></ li >
< li >< a href = "markdown.html" > markdown</ a ></ li >
< li >< a href = "math.html" > math</ a ></ li >
< li >< a href = "net.html" > net</ a ></ li >
< li >< a href = "os.html" > os</ a ></ li >
< li >< a href = "pathlib.html" > pathlib</ a ></ li >
< li >< a href = "regex.html" > regex</ a ></ li >
< li >< a href = "scheduler.html" > scheduler</ a ></ li >
< li >< a href = "signal.html" > signal</ a ></ li >
< li >< a href = "sqlite.html" > sqlite</ a ></ li >
< li >< a href = "subprocess.html" > subprocess</ a ></ li >
< li >< a href = "sysinfo.html" class = "active" > sysinfo</ a ></ li >
< li >< a href = "tempfile.html" > tempfile</ a ></ li >
< li >< a href = "timer.html" > timer</ a ></ li >
< li >< a href = "tls.html" > tls</ a ></ li >
< li >< a href = "udp.html" > udp</ a ></ li >
< li >< a href = "uuid.html" > uuid</ a ></ li >
< li >< a href = "wdantic.html" > wdantic</ a ></ li >
< li >< a href = "web.html" > web</ a ></ li >
< li >< a href = "websocket.html" > websocket</ a ></ li >
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > Tutorials</ span >
< ul >
< li >< a href = "../tutorials/index.html" > Tutorial List</ a ></ li >
< li >< a href = "../tutorials/http-client.html" > HTTP Client</ a ></ li >
< li >< a href = "../tutorials/websocket-chat.html" > WebSocket Chat</ a ></ li >
< li >< a href = "../tutorials/database-app.html" > Database App</ a ></ li >
< li >< a href = "../tutorials/template-rendering.html" > Templates</ a ></ li >
< li >< a href = "../tutorials/cli-tool.html" > CLI Tool</ a ></ li >
2026-01-25 18:02:02 +00:00
< li >< a href = "../tutorials/web-server.html" > Web Server</ a ></ li >
2026-01-25 12:09:28 +00:00
</ ul >
</ div >
< div class = "section" >
< span class = "section-title" > How-To Guides</ span >
< ul >
< li >< a href = "../howto/index.html" > How-To List</ a ></ li >
< li >< a href = "../howto/http-requests.html" > HTTP Requests</ a ></ li >
< li >< a href = "../howto/json-parsing.html" > JSON Parsing</ a ></ li >
< li >< a href = "../howto/regex-patterns.html" > Regex Patterns</ a ></ li >
< li >< a href = "../howto/file-operations.html" > File Operations</ a ></ li >
< li >< a href = "../howto/async-operations.html" > Async Operations</ a ></ li >
< li >< a href = "../howto/error-handling.html" > Error Handling</ a ></ li >
</ ul >
</ div >
2026-01-25 18:02:02 +00:00
< div class = "section" >
< span class = "section-title" > Contributing</ span >
< ul >
< li >< a href = "../contributing/index.html" > Overview</ a ></ li >
< li >< a href = "../contributing/module-overview.html" > Module Architecture</ a ></ li >
< li >< a href = "../contributing/pure-wren-module.html" > Pure-Wren Modules</ a ></ li >
< li >< a href = "../contributing/c-backed-module.html" > C-Backed Modules</ a ></ li >
< li >< a href = "../contributing/foreign-classes.html" > Foreign Classes</ a ></ li >
< li >< a href = "../contributing/async-patterns.html" > Async Patterns</ a ></ li >
< li >< a href = "../contributing/testing.html" > Writing Tests</ a ></ li >
< li >< a href = "../contributing/documentation.html" > Documentation</ a ></ li >
</ ul >
</ div >
2026-01-25 12:09:28 +00:00
</ nav >
</ aside >
< main class = "content" >
< nav class = "breadcrumb" >
< a href = "../index.html" > Home</ a >
< span class = "separator" > /</ span >
< a href = "index.html" > API Reference</ a >
< span class = "separator" > /</ span >
< span > sysinfo</ span >
</ nav >
< article >
< h1 > sysinfo</ h1 >
< p > The < code > sysinfo</ code > module provides system information including CPU details, memory usage, uptime, and network interfaces. All values are retrieved from libuv.</ p >
< pre >< code > import "sysinfo" for SysInfo</ code ></ pre >
< div class = "toc" >
< h4 > On This Page</ h4 >
< ul >
< li >< a href = "#sysinfo-class" > SysInfo Class</ a ></ li >
< li >< a href = "#examples" > Examples</ a ></ li >
</ ul >
</ div >
< h2 id = "sysinfo-class" > SysInfo Class</ h2 >
< div class = "class-header" >
< h3 > SysInfo</ h3 >
< p > System information properties</ p >
</ div >
< h3 > Static Properties</ h3 >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.cpuInfo</ span > → < span class = "type" > List</ span >
</ div >
< p > Returns a list of maps containing CPU information. Each map includes < code > model</ code > , < code > speed</ code > , and < code > times</ code > (with < code > user</ code > , < code > nice</ code > , < code > sys</ code > , < code > idle</ code > , < code > irq</ code > ).</ p >
< pre >< code > var cpus = SysInfo.cpuInfo
for (cpu in cpus) {
System.print("Model: %(cpu["model"])")
System.print("Speed: %(cpu["speed"]) MHz")
}</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.cpuCount</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns the number of CPUs/cores available on the system.</ p >
< pre >< code > System.print("CPU count: %(SysInfo.cpuCount)")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.loadAverage</ span > → < span class = "type" > List</ span >
</ div >
< p > Returns the system load averages as a list of three numbers: 1-minute, 5-minute, and 15-minute averages. On Windows, returns < code > [0, 0, 0]</ code > .</ p >
< pre >< code > var load = SysInfo.loadAverage
System.print("Load: %(load[0]) %(load[1]) %(load[2])")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.totalMemory</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns the total system memory in bytes.</ p >
< pre >< code > var totalMB = SysInfo.totalMemory / 1024 / 1024
System.print("Total memory: %(totalMB) MB")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.freeMemory</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns the free system memory in bytes.</ p >
< pre >< code > var freeMB = SysInfo.freeMemory / 1024 / 1024
System.print("Free memory: %(freeMB) MB")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.uptime</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns the system uptime in seconds.</ p >
< pre >< code > var hours = (SysInfo.uptime / 3600).floor
System.print("Uptime: %(hours) hours")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.hostname</ span > → < span class = "type" > String</ span >
</ div >
< p > Returns the system hostname.</ p >
< pre >< code > System.print("Hostname: %(SysInfo.hostname)")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.networkInterfaces</ span > → < span class = "type" > Map</ span >
</ div >
< p > Returns a map of network interfaces. Each key is an interface name, and each value is a list of address maps containing < code > address</ code > , < code > netmask</ code > , < code > family</ code > (IPv4 or IPv6), < code > internal</ code > , and < code > mac</ code > .</ p >
< pre >< code > var interfaces = SysInfo.networkInterfaces
for (name in interfaces.keys) {
System.print("Interface: %(name)")
for (addr in interfaces[name]) {
System.print(" %(addr["family"]): %(addr["address"])")
}
}</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.hrtime</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns a high-resolution time value in nanoseconds. Useful for precise timing measurements.</ p >
< pre >< code > var start = SysInfo.hrtime
// ... do some work ...
var elapsed = SysInfo.hrtime - start
System.print("Elapsed: %(elapsed / 1000000) ms")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.residentMemory</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns the resident set size (RSS) of the current process in bytes.</ p >
< pre >< code > var rssMB = SysInfo.residentMemory / 1024 / 1024
System.print("Process RSS: %(rssMB) MB")</ code ></ pre >
< div class = "method-signature" >
< span class = "method-name" > SysInfo.constrainedMemory</ span > → < span class = "type" > Num</ span >
</ div >
< p > Returns the memory limit for the process in bytes (e.g., cgroup limit). Returns 0 if no limit is set.</ p >
< pre >< code > var limit = SysInfo.constrainedMemory
if (limit > 0) {
System.print("Memory limit: %(limit / 1024 / 1024) MB")
} else {
System.print("No memory limit set")
}</ code ></ pre >
< h2 id = "examples" > Examples</ h2 >
< h3 > System Overview</ h3 >
< pre >< code > import "sysinfo" for SysInfo
System.print("=== System Information ===")
System.print("Hostname: %(SysInfo.hostname)")
System.print("CPUs: %(SysInfo.cpuCount)")
System.print("")
System.print("=== Memory ===")
var totalGB = (SysInfo.totalMemory / 1024 / 1024 / 1024 * 100).floor / 100
var freeGB = (SysInfo.freeMemory / 1024 / 1024 / 1024 * 100).floor / 100
var usedPercent = ((1 - SysInfo.freeMemory / SysInfo.totalMemory) * 100).floor
System.print("Total: %(totalGB) GB")
System.print("Free: %(freeGB) GB")
System.print("Used: %(usedPercent)\%")
System.print("")
System.print("=== Load Average ===")
var load = SysInfo.loadAverage
System.print("1 min: %(load[0])")
System.print("5 min: %(load[1])")
System.print("15 min: %(load[2])")
System.print("")
System.print("=== Uptime ===")
var uptime = SysInfo.uptime
var days = (uptime / 86400).floor
var hours = ((uptime % 86400) / 3600).floor
var minutes = ((uptime % 3600) / 60).floor
System.print("%(days) days, %(hours) hours, %(minutes) minutes")</ code ></ pre >
< h3 > CPU Information</ h3 >
< pre >< code > import "sysinfo" for SysInfo
var cpus = SysInfo.cpuInfo
System.print("CPU Information:")
System.print("================")
var i = 0
for (cpu in cpus) {
System.print("CPU %(i): %(cpu["model"])")
System.print(" Speed: %(cpu["speed"]) MHz")
var times = cpu["times"]
var total = times["user"] + times["nice"] + times["sys"] + times["idle"] + times["irq"]
var idle = (times["idle"] / total * 100).floor
System.print(" Idle: %(idle)\%")
i = i + 1
}</ code ></ pre >
< h3 > Network Interfaces</ h3 >
< pre >< code > import "sysinfo" for SysInfo
var interfaces = SysInfo.networkInterfaces
System.print("Network Interfaces:")
System.print("===================")
for (name in interfaces.keys) {
var addrs = interfaces[name]
System.print("%(name):")
for (addr in addrs) {
if (!addr["internal"]) {
System.print(" %(addr["family"]): %(addr["address"])")
if (addr["mac"] != "00:00:00:00:00:00") {
System.print(" MAC: %(addr["mac"])")
}
}
}
}</ code ></ pre >
< h3 > Performance Timing</ h3 >
< pre >< code > import "sysinfo" for SysInfo
var measure = Fn.new { |name, fn|
var start = SysInfo.hrtime
fn.call()
var elapsed = SysInfo.hrtime - start
System.print("%(name): %(elapsed / 1000000) ms")
}
measure.call("String concatenation") {
var s = ""
for (i in 0...1000) {
s = s + "x"
}
}
measure.call("List operations") {
var list = []
for (i in 0...10000) {
list.add(i)
}
}</ code ></ pre >
< h3 > Memory Monitoring</ h3 >
< pre >< code > import "sysinfo" for SysInfo
import "timer" for Timer
System.print("Memory Monitor (press Ctrl+C to stop)")
System.print("=====================================")
while (true) {
var totalMB = (SysInfo.totalMemory / 1024 / 1024).floor
var freeMB = (SysInfo.freeMemory / 1024 / 1024).floor
var rssMB = (SysInfo.residentMemory / 1024 / 1024).floor
var usedPercent = ((1 - SysInfo.freeMemory / SysInfo.totalMemory) * 100).floor
System.print("System: %(freeMB)/%(totalMB) MB free (%(usedPercent)\% used) | Process RSS: %(rssMB) MB")
Timer.sleep(1000)
}</ code ></ pre >
< div class = "admonition note" >
< div class = "admonition-title" > Note</ div >
< p > Load average values are not available on Windows and will return < code > [0, 0, 0]</ code > .</ p >
</ div >
< div class = "admonition tip" >
< div class = "admonition-title" > Tip</ div >
< p > Use < code > SysInfo.hrtime</ code > for precise performance measurements. It provides nanosecond resolution and is not affected by system clock adjustments.</ p >
</ div >
</ article >
< footer class = "page-footer" >
< a href = "subprocess.html" class = "prev" > subprocess</ a >
< a href = "tempfile.html" class = "next" > tempfile</ a >
</ footer >
</ main >
</ div >
< script src = "../js/main.js" ></ script >
</ body >
</ html >