sysctl

package
v13.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sysctl provides methods for reading kernel parameters

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(param string) (string, error)

Get returns kernel parameter value as a string

Example
paramValue, err := Get("kernel.random.boot_id")

if err != nil {
	panic(err.Error())
}

fmt.Printf("Boot ID: %s\n", paramValue)
Output:

func GetI

func GetI(param string) (int, error)

GetI returns kernel parameter value as an int

Example
paramValue, err := GetI("kernel.pty.max")

if err != nil {
	panic(err.Error())
}

fmt.Printf("PTY Max: %d\n", paramValue)
Output:

func GetI64

func GetI64(param string) (int64, error)

GetI64 returns kernel parameter value as an int64

Example
paramValue, err := GetI64("fs.file-max")

if err != nil {
	panic(err.Error())
}

fmt.Printf("File max: %d\n", paramValue)
Output:

Types

type Params added in v13.5.0

type Params map[string]string

Params contains all kernel parameters

func All added in v13.5.0

func All() (Params, error)

All returns all kernel parameters

Example
params, err := All()

if err != nil {
	panic(err.Error())
}

for n, v := range params {
	fmt.Printf("%s → %s\n", n, v)
}
Output:

func (Params) Get added in v13.5.0

func (p Params) Get(name string) string

Get returns kernel parameter value as a string

Example
params, err := All()

if err != nil {
	panic(err.Error())
}

fmt.Printf("Boot ID: %s\n", params.Get("kernel.random.boot_id"))
Output:

func (Params) GetI added in v13.5.0

func (p Params) GetI(param string) (int, error)

GetI returns kernel parameter value as an int

Example
params, err := All()

if err != nil {
	panic(err.Error())
}

paramValue, err := params.GetI("kernel.pty.max")

if err != nil {
	panic(err.Error())
}

fmt.Printf("PTY Max: %d\n", paramValue)
Output:

func (Params) GetI64 added in v13.5.0

func (p Params) GetI64(param string) (int64, error)

GetI64 returns kernel parameter value as an int64

Example
params, err := All()

if err != nil {
	panic(err.Error())
}

paramValue, err := params.GetI64("fs.file-max")

if err != nil {
	panic(err.Error())
}

fmt.Printf("File max: %d\n", paramValue)
Output:

Jump to

Keyboard shortcuts

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