system

package
v0.0.0-...-883cb22 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemMainTotalKey = "MemTotal"
	MemSwapTotalKey = "SwapTotal"
)

string definitions for parsing /proc/meminfo output

View Source
const (
	SysctlPagecacheLimitMB          = "vm.pagecache_limit_mb"
	SysctlPagecacheLimitIgnoreDirty = "vm.pagecache_limit_ignore_dirty"
	SysctlNumaBalancing             = "kernel.numa_balancing"
	SysctlShmall                    = "kernel.shmall"
	SysctlShmax                     = "kernel.shmmax"
	SysctlShmni                     = "kernel.shmmni"
	SysctlMaxMapCount               = "vm.max_map_count"
	SysctlSem                       = "kernel.sem"
	SysctlNumberHugepages           = "vm.nr_hugepages"
	SysctlSwappines                 = "vm.swappiness"
	SysctlVFSCachePressure          = "vm.vfs_cache_pressure"
	SysctlOvercommitMemory          = "vm.overcommit_memory"
	SysctlOvercommitRatio           = "vm.overcommit_ratio"
	SysctlDirtyRatio                = "vm.dirty_ratio"
	SysctlDirtyBackgroundRatio      = "vm.dirty_background_ratio"
	SysctlNetReadMemMax             = "net.core.rmem_max"
	SysctlNetWriteMemMax            = "net.core.wmem_max"
	SysctlNetMaxBacklog             = "net.core.netdev_max_backlog"
	SysctlNetMaxconn                = "net.core.somaxconn"
	SysctlTCPReadMem                = "net.ipv4.tcp_rmem"
	SysctlTCPWriteMem               = "net.ipv4.tcp_wmem"
	SysctlTCPTimestamps             = "net.ipv4.tcp_timestamps"
	SysctlTCPSack                   = "net.ipv4.tcp_sack"
	SysctlTCPDsack                  = "net.ipv4.tcp_dsack"
	SysctlTCPFack                   = "net.ipv4.tcp_fack"
	SysctlTCPFragLowThreshold       = "net.ipv4.ipfrag_low_thresh"
	SysctlTCPFragHighThreshold      = "net.ipv4.ipfrag_high_thresh"
	SysctlTCPMaxSynBacklog          = "net.ipv4.tcp_max_syn_backlog"
	SysctlTCPSynackRetries          = "net.ipv4.tcp_synack_retries"
	SysctpTCPRetries2               = "net.ipv4.tcp_retries2"
	SysctlTCPKeepaliveTime          = "net.ipv4.tcp_keepalive_time"
	SysctlTCPKeepaliveProbes        = "net.ipv4.tcp_keepalive_probes"
	SysctlTCPKeepaliveInterval      = "net.ipv4.tcp_keepalive_intvl"
	SysctlTCPTWRecycle              = "net.ipv4.tcp_tw_recycle"
	SysctlTCPTWReuse                = "net.ipv4.tcp_tw_reuse"
	SysctlTCPFinTimeout             = "net.ipv4.tcp_fin_timeout"
	SysctlTCPMTUProbing             = "net.ipv4.tcp_mtu_probing"
	SysctlTCPSynCookies             = "net.ipv4.tcp_syncookies"
	SysctlIPAcceptSourceRoute       = "net.ipv4.conf.all.accept_source_route"
	SysctlIPAcceptRedirects         = "net.ipv4.conf.all.accept_redirects"
	SysctlIPRPFilter                = "net.ipv4.conf.all.rp_filter"
	SysctlIPIgnoreICMPBroadcasts    = "net.ipv4.icmp_echo_ignore_broadcasts"
	SysctlIPIgnoreICMPBogusError    = "net.ipv4.icmp_ignore_bogus_error_responses"
	SysctlIPLogMartians             = "net.ipv4.conf.all.log_martians"
	SysctlRandomizeVASpace          = "kernel.randomize_va_space"
	SysctlKptrRestrict              = "kernel.kptr_restrict"
	SysctlProtectHardlinks          = "fs.protected_hardlinks"
	SysctlProtectSymlinks           = "fs.protected_symlinks"
	SysctlRunChildFirst             = "kernel.sched_child_runs_first"
)

mapping of system parameter names to configuration names

View Source
const SaptuneSectionDir = "/var/lib/saptune/sections"

SaptuneSectionDir defines saptunes saved state directory

View Source
const SecurityLimitUnlimitedValue = SecurityLimitInt(-1)

SecurityLimitUnlimitedValue is the constant integer value that represents unrestricted limit.

Variables

View Source
var ErrorExitOut = ErrorLog

ErrorExitOut defines, which exit output function should be used

View Source
var OSExit = os.Exit

OSExit defines, which exit function should be used

View Source
var SecurityLimitUnlimitedString = []string{"unlimited", "infinity"}

SecurityLimitUnlimitedString are the string constants that represent unrestricted limit.

Functions

func BlockDeviceIsDisk

func BlockDeviceIsDisk(dev string) bool

BlockDeviceIsDisk checks, if a block device is a disk /sys/block/*/device/type (TYPE_DISK / 0x00) does not work for virtio block devices, needs workaround

func CalledFrom

func CalledFrom() string

CalledFrom returns the name and the line number of the calling source file

func CheckCPUState

func CheckCPUState(csMap map[string]string) bool

CheckCPUState checks, if all cpus have the same state settings returns true, if the cpu states differ

func CheckForPattern

func CheckForPattern(file, pattern string) bool

CheckForPattern returns true, if the file is available and contains the expected string

func CheckRpmVers

func CheckRpmVers(vers1, vers2 string) int

CheckRpmVers compare versions of 2 RPMs (installed version, expected version) Return 0 (Equal), 1 (GreaterThan) or -1 (LessThan)

func CliArg

func CliArg(i int) string

CliArg returns the i-th command line parameter, or empty string if it is not specified.

func CmdIsAvailable

func CmdIsAvailable(cmdName string) bool

CmdIsAvailable returns true, if the cmd is available.

func CmpRpmVers

func CmpRpmVers(vers1, vers2 string) bool

CmpRpmVers compare versions of 2 RPMs (installed version, expected version) Return true, if installed package version is equal or higher than expected Return false, if installed package version is less than expected

func CmpServiceStates

func CmpServiceStates(actStates, expStates string) bool

CmpServiceStates compares the expected service states with the current active service states

func CollectBlockDeviceInfo

func CollectBlockDeviceInfo() []string

CollectBlockDeviceInfo collects all needed information about block devices from /sys/block write info to /var/lib/saptune/sections/block.run

func CopyFile

func CopyFile(srcFile, destFile string) error

CopyFile from source to destination

func DebugLog

func DebugLog(txt string, stuff ...interface{})

DebugLog sents text to the debugLogger and stderr

func ErrorExit

func ErrorExit(template string, stuff ...interface{})

ErrorExit prints the message to stderr and exit 1.

func ErrorLog

func ErrorLog(txt string, stuff ...interface{}) error

ErrorLog sents text to the errorLogger and stderr

func GetAvailServices

func GetAvailServices() map[string]string

GetAvailServices returns a map of the available services of the system

func GetCurrentLogins

func GetCurrentLogins() []string

GetCurrentLogins returns the user ids of the currently logged in users

func GetFLInfo

func GetFLInfo() (string, string, bool)

GetFLInfo retrieve CPU latency configuration from the system and returns the current latency, the latency states of all CPUs to save latency states for 'revert', if cpu states differ return lat, savedStates, cpuStateDiffer

func GetGovernor

func GetGovernor() map[string]string

GetGovernor retrieve performance configuration regarding to cpu frequency from the system

func GetMainMemSizeMB

func GetMainMemSizeMB() uint64

GetMainMemSizeMB return size of system main memory, excluding swap. Panic on error.

func GetOsName

func GetOsName() string

GetOsName returns the OS name

func GetOsVers

func GetOsVers() string

GetOsVers returns the OS version

func GetPerfBias

func GetPerfBias() string

GetPerfBias retrieve CPU performance configuration from the system

func GetRpmVers

func GetRpmVers(rpm string) string

GetRpmVers return the version of an installed RPM

func GetSemaphoreLimits

func GetSemaphoreLimits() (msl, mns, opm, mni uint64)

GetSemaphoreLimits return kernel semaphore limits. Panic on error.

func GetServiceName

func GetServiceName(service string) string

GetServiceName returns the systemd service name for supported services

func GetSolutionSelector

func GetSolutionSelector() string

GetSolutionSelector returns the architecture string needed to select the supported set os solutions

func GetSysChoice

func GetSysChoice(parameter string) (string, error)

GetSysChoice read a /sys/ key that comes with current value and alternative choices, return the current choice or empty string.

func GetSysInt

func GetSysInt(parameter string) (int, error)

GetSysInt read an integer /sys/ key.

func GetSysString

func GetSysString(parameter string) (string, error)

GetSysString read a /sys/ key and return the string value.

func GetSysctlInt

func GetSysctlInt(parameter string) (int, error)

GetSysctlInt read an integer sysctl key.

func GetSysctlString

func GetSysctlString(parameter string) (string, error)

GetSysctlString read a sysctl key and return the string value.

func GetSysctlUint64

func GetSysctlUint64(parameter string) (uint64, error)

GetSysctlUint64 read an uint64 sysctl key.

func GetSysctlUint64Field

func GetSysctlUint64Field(param string, field int) (uint64, error)

GetSysctlUint64Field extracts an uint64 value from a sysctl key of many fields.

func GetTasksMax

func GetTasksMax(userID string) string

GetTasksMax returns the current limit of TasksMax for a given user id which is the value for UserTasksMax

func GetTotalMemSizeMB

func GetTotalMemSizeMB() uint64

GetTotalMemSizeMB return size of system main memory plus swap. Panic on error.

func GetTotalMemSizePages

func GetTotalMemSizePages() uint64

GetTotalMemSizePages return size of system main memory plus swap, in pages. Panic on error.

func GetTunedAdmProfile

func GetTunedAdmProfile() string

GetTunedAdmProfile return the currently active tuned profile. Return empty string if it cannot be determined.

func GetTunedProfile

func GetTunedProfile() string

GetTunedProfile returns the currently active tuned profile by reading the file /etc/tuned/active_profile may be unreliable in newer tuned versions, so better use 'tuned-adm active' Return empty string if it cannot be determined.

func GetdmaLatency

func GetdmaLatency() string

GetdmaLatency retrieve DMA latency configuration from the system

func InfoLog

func InfoLog(txt string, stuff ...interface{})

InfoLog sents text to the infoLogger and stdout

func IsPagecacheAvailable

func IsPagecacheAvailable() bool

IsPagecacheAvailable check, if system supports pagecache limit

func IsSLE12

func IsSLE12() bool

IsSLE12 returns true, if System is running a SLE12 release

func IsSLE15

func IsSLE15() bool

IsSLE15 returns true, if System is running a SLE15 release

func IsServiceAvailable

func IsServiceAvailable(service string) bool

IsServiceAvailable checks, if a systemd service is available on the system

func IsSystemRunning

func IsSystemRunning() bool

IsSystemRunning returns true, if 'is-system-running' reports 'running' or 'starting'. In all other cases it returns false, which means: do not call 'start' or 'restart' to prevent 'Transaction is destructive' messages

func IsUserRoot

func IsUserRoot() bool

IsUserRoot return true only if the current user is root.

func IsValidGovernor

func IsValidGovernor(cpu, gov string) bool

IsValidGovernor check, if the system will support CPU frequency settings

func ListDir

func ListDir(dirPath, logMsg string) (dirNames, fileNames []string)

ListDir list directory content.

func LogInit

func LogInit(logFile, debug, verbose string)

LogInit initialise the different log writer saptune will use

func OutIsTerm

func OutIsTerm(writer *os.File) bool

OutIsTerm returns true, if Stdout is a terminal

func ParseCmdline

func ParseCmdline(fileName, option string) string

ParseCmdline parse /proc/cmdline into key(string) - value(string) pairs. return value for given boot option or 'NA', if not available

func ParseMeminfo

func ParseMeminfo() (infoMap map[string]uint64)

ParseMeminfo parse /proc/meminfo into key(string) - value(int) pairs. Panic on error.

func ReadConfigFile

func ReadConfigFile(fileName string, autoCreate bool) ([]byte, error)

ReadConfigFile read content of config file

func ReleaseSaptuneLock

func ReleaseSaptuneLock()

ReleaseSaptuneLock removes the saptune lock file

func RemountSHM

func RemountSHM(newSizeMB uint64) error

RemountSHM invoke mount command to resize /dev/shm to the specified value.

func SaptuneLock

func SaptuneLock()

SaptuneLock creates the saptune lock file

func SecureBootEnabled

func SecureBootEnabled() bool

SecureBootEnabled check, if the system is in lock-down mode

func SetForceLatency

func SetForceLatency(value, savedStates, info string, revert bool) error

SetForceLatency set CPU latency configuration to the system

func SetGovernor

func SetGovernor(value, info string) error

SetGovernor set performance configuration regarding to cpu frequency to the system using 'cpupower' command

func SetPerfBias

func SetPerfBias(value string) error

SetPerfBias set CPU performance configuration to the system using 'cpupower' command

func SetSysInt

func SetSysInt(parameter string, value int) error

SetSysInt write an integer /sys/ value.

func SetSysString

func SetSysString(parameter, value string) error

SetSysString write a string /sys/ value.

func SetSysctlInt

func SetSysctlInt(parameter string, value int) error

SetSysctlInt write an integer sysctl value.

func SetSysctlString

func SetSysctlString(parameter, value string) error

SetSysctlString write a string sysctl value.

func SetSysctlUint64

func SetSysctlUint64(parameter string, value uint64) error

SetSysctlUint64 write an integer sysctl value.

func SetSysctlUint64Field

func SetSysctlUint64Field(param string, field int, value uint64) error

SetSysctlUint64Field write an integer sysctl value into the specified field pf the key.

func SetTasksMax

func SetTasksMax(userID, limit string) error

SetTasksMax sets the limit of TasksMax for a given user id to 'limit'

func SupportsPerfBias

func SupportsPerfBias() bool

SupportsPerfBias check, if the system will support CPU performance settings

func SwitchOffLogging

func SwitchOffLogging()

SwitchOffLogging disables logging

func SystemctlDisable

func SystemctlDisable(thing string) error

SystemctlDisable call systemctl disable on thing.

func SystemctlDisableStop

func SystemctlDisableStop(thing string) error

SystemctlDisableStop call systemctl disable and then systemctl stop on thing. Panic on error.

func SystemctlEnable

func SystemctlEnable(thing string) error

SystemctlEnable call systemctl enable on thing.

func SystemctlEnableStart

func SystemctlEnableStart(thing string) error

SystemctlEnableStart call systemctl enable and then systemctl start on thing.

func SystemctlIsEnabled

func SystemctlIsEnabled(thing string) bool

SystemctlIsEnabled return true only if systemctl suggests that the thing is enabled.

func SystemctlIsRunning

func SystemctlIsRunning(thing string) bool

SystemctlIsRunning return true only if systemctl suggests that the thing is running.

func SystemctlReloadTryRestart

func SystemctlReloadTryRestart(thing string) error

SystemctlReloadTryRestart call systemctl reload on thing.

func SystemctlRestart

func SystemctlRestart(thing string) error

SystemctlRestart call systemctl restart on thing.

func SystemctlStart

func SystemctlStart(thing string) error

SystemctlStart call systemctl start on thing.

func SystemctlStop

func SystemctlStop(thing string) error

SystemctlStop call systemctl stop on thing.

func TestSysString

func TestSysString(parameter, value string) error

TestSysString Test writing a string /sys/ value.

func TunedAdmOff

func TunedAdmOff() error

TunedAdmOff calls tuned-adm to switch off the active profile.

func TunedAdmProfile

func TunedAdmProfile(profileName string) error

TunedAdmProfile calls tuned-adm to switch to the specified profile. newer versions of tuned seems to be reliable with this command and they changed the behaviour/handling of the file /etc/tuned/active_profile

func WarningLog

func WarningLog(txt string, stuff ...interface{})

WarningLog sents text to the warningLogger and stderr

func WriteTunedAdmProfile

func WriteTunedAdmProfile(profileName string) error

WriteTunedAdmProfile write new profile to tuned, used instead of sometimes unreliable 'tuned-adm' command

Types

type BlockDev

type BlockDev struct {
	AllBlockDevs    []string
	BlockAttributes map[string]map[string]string
}

BlockDev contains all key-value pairs of current avaliable block devices in /sys/block

func GetBlockDeviceInfo

func GetBlockDeviceInfo() (*BlockDev, error)

GetBlockDeviceInfo reads content of stored block device information. content stored in SaptuneSectionDir (/var/lib/saptune/sections) as blockdev.run Return the content as BlockDev

type MountPoint

type MountPoint struct {
	Device     string
	MountPoint string
	Type       string
	Options    []string
	Dump       int
	Fsck       int
}

MountPoint Represent a mount point entry in /proc/mounts or /etc/fstab

func (MountPoint) Equals

func (mount1 MountPoint) Equals(mount2 MountPoint) bool

Equals return true only if two mount points are identical in all attributes.

func (MountPoint) GetFileSystemSizeMB

func (mount MountPoint) GetFileSystemSizeMB() uint64

GetFileSystemSizeMB return the total size of the file system in MegaBytes. Panic on error.

type MountPoints

type MountPoints []MountPoint

MountPoints contains a list of mount points.

func ParseFstab

func ParseFstab() MountPoints

ParseFstab return all mount points defined in /etc/fstab. Panic on error.

func ParseMounts

func ParseMounts(txt string) (mounts MountPoints)

ParseMounts return all mount points defined in the input text. Panic on malformed entry.

func ParseMtabMounts

func ParseMtabMounts() MountPoints

ParseMtabMounts return all mount points appearing in /proc/mounts. Panic on error.

func ParseProcMounts

func ParseProcMounts() MountPoints

ParseProcMounts return all mount points appearing in /proc/mounts. Panic on error.

func (MountPoints) GetByMountPoint

func (mounts MountPoints) GetByMountPoint(mountPoint string) (MountPoint, bool)

GetByMountPoint find a mount point by its path.

type SecLimits

type SecLimits struct {
	Entries []*SecLimitsEntry
}

SecLimits Entries of security/limits.conf file. It is able to convert back to original text in the original entry order.

func ParseSecLimits

func ParseSecLimits(input string) *SecLimits

ParseSecLimits read limits.conf text and parse the text into memory structures.

func ParseSecLimitsFile

func ParseSecLimitsFile(fileName string) (*SecLimits, error)

ParseSecLimitsFile read limits.conf and parse the file content into memory structures.

func (*SecLimits) Apply

func (limits *SecLimits) Apply() error

Apply overwrite /etc/security/limits.conf with the content of this structure.

func (*SecLimits) ApplyDropIn

func (limits *SecLimits) ApplyDropIn(lim []string, noteID string) error

ApplyDropIn overwrite file 'dropInFile' with the content of this structure.

func (*SecLimits) Get

func (limits *SecLimits) Get(domain, typeName, item string) (string, bool)

Get return string value that belongs to the entry.

func (*SecLimits) GetOr0

func (limits *SecLimits) GetOr0(domain, typeName, item string) SecurityLimitInt

GetOr0 retrieves an integer limit value and return. If the value is not specified or cannot be parsed correctly, 0 will be returned.

func (*SecLimits) Set

func (limits *SecLimits) Set(domain, typeName, item, value string)

Set value for an entry. If the entry does not yet exist, it is created.

func (*SecLimits) ToDropIn

func (limits *SecLimits) ToDropIn(lim []string, noteID, fileName string) string

ToDropIn convert the entries back into text.

func (*SecLimits) ToText

func (limits *SecLimits) ToText() string

ToText convert the entries back into text.

type SecLimitsEntry

type SecLimitsEntry struct {
	LeadingComments    []string // The comment lines leading to the key-value pair, including prefix '#', excluding end-of-line.
	Domain, Type, Item string
	Value              string
}

SecLimitsEntry is a single entry in security/limits.conf file.

type SecurityLimitInt

type SecurityLimitInt int

SecurityLimitInt is an integer number where -1 represents unlimited value.

func ToSecurityLimitInt

func ToSecurityLimitInt(in string) SecurityLimitInt

ToSecurityLimitInt interprets integer limit number from input string. If the input cannot be parsed successfully, it will return a default 0 value.

func (SecurityLimitInt) String

func (limit SecurityLimitInt) String() string

Jump to

Keyboard shortcuts

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