|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "sysinfo" for SysInfo
|
|
|
|
var formatBytes = Fn.new { |bytes|
|
|
if (bytes < 1024) return "%(bytes) B"
|
|
if (bytes < 1024 * 1024) return "%(((bytes / 1024) * 10).floor / 10) KB"
|
|
if (bytes < 1024 * 1024 * 1024) return "%(((bytes / 1024 / 1024) * 10).floor / 10) MB"
|
|
return "%(((bytes / 1024 / 1024 / 1024) * 10).floor / 10) GB"
|
|
}
|
|
|
|
System.print("=== SysInfo Module Demo ===\n")
|
|
|
|
System.print("--- System Information ---")
|
|
System.print("Hostname: %(SysInfo.hostname)")
|
|
System.print("Uptime: %(SysInfo.uptime) seconds")
|
|
|
|
System.print("\n--- Memory Information ---")
|
|
var total = SysInfo.totalMemory
|
|
var free = SysInfo.freeMemory
|
|
var used = total - free
|
|
var resident = SysInfo.residentMemory
|
|
var constrained = SysInfo.constrainedMemory
|
|
|
|
System.print("Total: %(formatBytes.call(total))")
|
|
System.print("Free: %(formatBytes.call(free))")
|
|
System.print("Used: %(formatBytes.call(used))")
|
|
System.print("Process RSS: %(formatBytes.call(resident))")
|
|
if (constrained > 0) {
|
|
System.print("Constrained: %(formatBytes.call(constrained))")
|
|
}
|
|
|
|
System.print("\n--- CPU Information ---")
|
|
var cpus = SysInfo.cpuInfo
|
|
System.print("CPU Count: %(cpus.count)")
|
|
|
|
for (i in 0...cpus.count) {
|
|
var cpu = cpus[i]
|
|
System.print(" CPU %(i): %(cpu["model"]) @ %(cpu["speed"]) MHz")
|
|
}
|
|
|
|
System.print("\n--- 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("\n--- Network Interfaces ---")
|
|
var interfaces = SysInfo.networkInterfaces
|
|
for (name in interfaces.keys) {
|
|
System.print("%(name):")
|
|
for (addr in interfaces[name]) {
|
|
System.print(" %(addr["family"]): %(addr["address"])")
|
|
System.print(" Internal: %(addr["internal"])")
|
|
System.print(" Netmask: %(addr["netmask"])")
|
|
System.print(" MAC: %(addr["mac"])")
|
|
}
|
|
}
|
|
|
|
System.print("\n--- High Resolution Timer ---")
|
|
var t1 = SysInfo.hrtime
|
|
var t2 = SysInfo.hrtime
|
|
System.print("Time 1: %(t1) ns")
|
|
System.print("Time 2: %(t2) ns")
|
|
System.print("Delta: %(t2 - t1) ns")
|