tinman
Tinman allows you to query information about the operating system, runtime and environment.
It’s useful for working around platform quirks or setting up global resource limits at startup. It’s not suitable as a monitoring library.
Types
Container runtime
pub type ContainerRuntime {
Docker
Podman
Wsl
}
Constructors
-
Docker -
Podman -
Wsl
The CPU architecture.
pub type CpuArchitecture {
X64
Arm64
Arm
Riscv64
}
Constructors
-
X64 -
Arm64 -
Arm -
Riscv64
Byte order / endianness.
pub type Endianness {
BigEndian
LittleEndian
}
Constructors
-
BigEndian -
LittleEndian
The C standard library implementation (Linux only).
pub type Libc {
Glibc
Musl
}
Constructors
-
Glibc -
Musl
The operating system platform.
pub type OperatingSystem {
Linux
Macos
Windows
FreeBsd
OpenBsd
}
Constructors
-
Linux -
Macos -
Windows -
FreeBsd -
OpenBsd
The JavaScript or Erlang runtime.
pub type Runtime {
Beam
AtomVm
Node
Deno
Bun
}
Constructors
-
Beam -
AtomVm -
Node -
Deno -
Bun
Values
pub fn available_parallelism() -> Int
Returns the recommended level of parallelism.
This is the number of available schedulers on Erlang, or the number of runtime threads on Javascript. Note that Javascript itself is always single-threaded by default.
pub fn container_runtime() -> Result(ContainerRuntime, Nil)
Returns the detected container runtime.
Detects Docker, Podman, and WSL environments.
Returns Error(Nil) if no container could be detected.
pub fn cpu_architecture() -> Result(CpuArchitecture, Nil)
Returns the CPU architecture.
Returns Error(Nil) if the architecture cannot be determined or is unknown.
pub fn cpu_count() -> Result(Int, Nil)
Returns the number of logical CPU cores.
Returns Error(Nil) if the CPU count cannot be determined.
Note: Usually you want to use
available_parallelisminstead!
pub fn end_of_line() -> String
Returns the end-of-line marker for the current platform.
"\n" on Unix-like systems, "\r\n" on Windows.
pub fn executable_extension() -> String
Returns the executable file extension for the current platform.
".exe" on Windows, "" (empty string) on Unix-like systems.
pub fn free_disk_space() -> Result(Int, Nil)
Returns the free disk space in bytes for the root/system drive.
Uses df on Unix-like systems and PowerShell on Windows.
Returns Error(Nil) if the information cannot be determined.
pub fn free_memory() -> Result(Int, Nil)
Returns the available system memory in bytes. When running inside a container, memory limits applied to the container are respected.
Note: This information is not exposed by the Erlang runtime system, and has to be queried from the operating system in various ways. Doing so might be unexpectedly slow, especially on Windows!
pub fn group_id() -> Result(Int, Nil)
Returns the current group ID.
Returns Error(Nil) if the group ID cannot be determined.
pub fn is_admin() -> Bool
Returns whether the current user has administrator/root privileges.
On Unix-like systems, checks if the user ID is 0 (root).
On Windows, checks if we can successfully run a utility with elevated privileges.
pub fn is_ci() -> Bool
Returns whether your program is running in a CI environment.
Checks for CI and CONTINUOUS_INTEGRATION environment variables.
pub fn is_in_ssh() -> Bool
Returns whether your program is running in an SSH session.
Checks for SSH_CONNECTION, SSH_CLIENT, and SSH_TTY environment variables.
pub fn is_online() -> Bool
Returns whether the system appears to be online.
Checks if there is an active non-loopback network interface available.
pub fn is_test() -> Bool
Returns whether the program is running in test mode.
Checks if the entrypoint module is _test, which is the case when running
with gleam test.
pub fn is_tty() -> Bool
Checks whether the program is running in an interactive terminal (TTY).
pub fn libc() -> Result(Libc, Nil)
Returns the C standard library type (Linux only).
Returns Error(Nil) on non-Linux systems or if detection fails.
pub fn os() -> Result(OperatingSystem, Nil)
Returns the operating system platform.
Returns Error(Nil) if the platform cannot be determined or is unknown.
pub fn os_version() -> Result(Version, Nil)
Returns the operating system version.
Returns Error(Nil) if the version cannot be determined or parsed.
pub fn path_delimiter() -> String
Returns the path delimiter - the character used inside the PATH environment
variable to separate multiple paths - for the current platform.
":" on Unix-like systems, ";" on Windows.
pub fn path_separator() -> String
Returns the path separator - the character used inside paths to separate
files and directories - for the current platform.
"/" on Unix-like systems, "\\" on Windows.
pub fn runtime() -> Result(Runtime, Nil)
Returns the current runtime (Erlang, Node, Deno, or Bun).
Returns Error(Nil) if the runtime cannot be determined.
pub fn runtime_version() -> Result(Version, Nil)
Returns the runtime version.
Returns Error(Nil) if the version cannot be determined or parsed.
Note: On Erlang, this is the version of the Erlang runtime system (ERTS), not the version of the OTP release!
pub fn total_disk_space() -> Result(Int, Nil)
Returns the total disk space in bytes for the root/system drive.
Uses df on Unix-like systems and PowerShell on Windows.
Returns Error(Nil) if the information cannot be determined.
pub fn total_memory() -> Result(Int, Nil)
Returns the total available system memory in bytes. When running inside a container, memory limits applied to the container are respected.
Note: This information is not exposed by the Erlang runtime system, and has to be queried from the operating system in various ways. Doing so might be unexpectedly slow, especially on Windows!
pub fn used_memory() -> Int
Returns the memory used by the runtime and your program.
pub fn user_id() -> Result(Int, Nil)
Returns the current user ID.
Returns Error(Nil) if the user ID cannot be determined.