system

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 16 Imported by: 10

Documentation

Overview

Package system provides system utility functions initially required by `cbbackupmgr`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(command string) (string, error)

Execute will execute the given command in the platforms default shell/command prompt and return the combined stdout/stderr output.

NOTE: In the event of an error, the returned string will always be empty, the error message will contain all the valid information about why the command failed.

func NumCPU

func NumCPU() int

NumCPU returns GOMAXPROCS (defaults to vCPUs) detected by the runtime multiplied by a constant. This function should be used when determining how many Goroutines to create for performing short running tasks which benefit from being performed concurrently. We currently multiply the value by 0.75 to avoid over-saturating the CPU in cases where multiple instances of cbbackupmgr can be run on a single machine e.g. when running info during a merge.

func NumWorkers

func NumWorkers(limit int) int

NumWorkers returns a sane number of workers to create when performing a task concurrently. This function should be used for the same reason as 'NumCPU', however, with the added caveat that we'd like to ensure we don't create more workers than the amount of work that is going to be processed.

func RaiseFileLimit

func RaiseFileLimit(threshold uint64) error

RaiseFileLimit will check if the ulimit on open files is bigger or equal to threshold if it is it will return. Otherwise it will try to raise it and return true. If it fails it will return false.

func TotalMemory

func TotalMemory() (uint64, error)

TotalMemory returns the total physical memory available on the host machine in bytes.

NOTE: This function is a wrapper around os specific functions which ensures that we always return the same value and only calculate it once.

func Version

func Version() (string, error)

Version returns a string representation of the current kernel release.

NOTE: This function is a wrapper around os specific functions which ensures that we always return the same value and only calculate it once.

Types

type Information

type Information struct {
	Hostname string
	OS       string
	Version  string
	Arch     string
	VCPU     int
	Memory   uint64
}

Information represents useful system information which is logged by 'cbbackupmgr' at the beginning of each command.

func GetInformation

func GetInformation(logger *slog.Logger) Information

GetInformation fetches and returns common system information in a platform agnostic fashion.

NOTE: On supported platforms, the returned information may not be that of the host system but of any limits applied.

func (Information) String

func (i Information) String() string

String implements the 'Stringer' interface note changes to this format should be considered carefully as to note break backwards compatibility.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL