crystal-sys-uptime
system-uptime
Description
A Crystal interface for getting system uptime information.
Supported Platforms
- Linux
- macOS
- BSD systems via
sysctl(KERN_BOOTTIME)where available
At the moment there is no Windows support.
Installation
Add this to your application's shard.yml:
dependencies:
system-uptime:
github: djberg96/crystal-sys-uptime
Then run:
shards install
Synopsis
require "system-uptime"
# Get everything
pp System::Uptime.uptime
# Get individual units
pp System::Uptime.days
pp System::Uptime.hours
pp System::Uptime.minutes
pp System::Uptime.seconds
# Get the boot time
pp System::Uptime.boot_time
API
System::Uptime.secondsreturns total uptime in seconds asInt64System::Uptime.minutesreturns total uptime in minutes asInt64System::Uptime.hoursreturns total uptime in hours asInt64System::Uptime.daysreturns total uptime in days asInt64System::Uptime.uptimereturns adays:hours:minutes:secondsstringSystem::Uptime.boot_timereturns the system boot time as aTime
Notes
This shard is modeled after the Ruby sys-uptime library, but the Crystal API is intentionally smaller right now.
For compatibility, require "sys-uptime" still works for now, but require "system-uptime" is the canonical entrypoint.
The current time, user count, and load average are not included, even though you may be used to seeing them in the command line uptime tool.
On Linux, uptime is read from /proc/uptime.
On macOS and BSD systems, uptime is derived from the kernel boot time. In restricted environments where sysctl(KERN_BOOTTIME) is blocked, the shard attempts a who -b fallback.
Known Bugs
None that I am aware of. Please log any bugs you find on the project website.
License
MIT
Copyright
Copyright 2026, Daniel J. Berger
Warranty
This library is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
Author
Daniel J. Berger
crystal-sys-uptime
- 0
- 0
- 0
- 0
- 0
- 4 days ago
- May 10, 2026
MIT License
Mon, 11 May 2026 00:03:34 GMT