Documentation ¶
Index ¶
- Constants
- Variables
- func BlockDeviceIsDisk(dev string) bool
- func CalledFrom() string
- func CheckCPUState(csMap map[string]string) bool
- func CheckForPattern(file, pattern string) bool
- func CheckRpmVers(vers1, vers2 string) int
- func CliArg(i int) string
- func CmdIsAvailable(cmdName string) bool
- func CmpRpmVers(vers1, vers2 string) bool
- func CmpServiceStates(actStates, expStates string) bool
- func CollectBlockDeviceInfo() []string
- func CopyFile(srcFile, destFile string) error
- func DebugLog(txt string, stuff ...interface{})
- func ErrorExit(template string, stuff ...interface{})
- func ErrorLog(txt string, stuff ...interface{}) error
- func GetAvailServices() map[string]string
- func GetCurrentLogins() []string
- func GetFLInfo() (string, string, bool)
- func GetGovernor() map[string]string
- func GetMainMemSizeMB() uint64
- func GetOsName() string
- func GetOsVers() string
- func GetPerfBias() string
- func GetRpmVers(rpm string) string
- func GetSemaphoreLimits() (msl, mns, opm, mni uint64)
- func GetServiceName(service string) string
- func GetSolutionSelector() string
- func GetSysChoice(parameter string) (string, error)
- func GetSysInt(parameter string) (int, error)
- func GetSysString(parameter string) (string, error)
- func GetSysctlInt(parameter string) (int, error)
- func GetSysctlString(parameter string) (string, error)
- func GetSysctlUint64(parameter string) (uint64, error)
- func GetSysctlUint64Field(param string, field int) (uint64, error)
- func GetTasksMax(userID string) string
- func GetTotalMemSizeMB() uint64
- func GetTotalMemSizePages() uint64
- func GetTunedAdmProfile() string
- func GetTunedProfile() string
- func GetdmaLatency() string
- func InfoLog(txt string, stuff ...interface{})
- func IsPagecacheAvailable() bool
- func IsSLE12() bool
- func IsSLE15() bool
- func IsServiceAvailable(service string) bool
- func IsSystemRunning() bool
- func IsUserRoot() bool
- func IsValidGovernor(cpu, gov string) bool
- func ListDir(dirPath, logMsg string) (dirNames, fileNames []string)
- func LogInit(logFile, debug, verbose string)
- func OutIsTerm(writer *os.File) bool
- func ParseCmdline(fileName, option string) string
- func ParseMeminfo() (infoMap map[string]uint64)
- func ReadConfigFile(fileName string, autoCreate bool) ([]byte, error)
- func ReleaseSaptuneLock()
- func RemountSHM(newSizeMB uint64) error
- func SaptuneLock()
- func SecureBootEnabled() bool
- func SetForceLatency(value, savedStates, info string, revert bool) error
- func SetGovernor(value, info string) error
- func SetPerfBias(value string) error
- func SetSysInt(parameter string, value int) error
- func SetSysString(parameter, value string) error
- func SetSysctlInt(parameter string, value int) error
- func SetSysctlString(parameter, value string) error
- func SetSysctlUint64(parameter string, value uint64) error
- func SetSysctlUint64Field(param string, field int, value uint64) error
- func SetTasksMax(userID, limit string) error
- func SupportsPerfBias() bool
- func SwitchOffLogging()
- func SystemctlDisable(thing string) error
- func SystemctlDisableStop(thing string) error
- func SystemctlEnable(thing string) error
- func SystemctlEnableStart(thing string) error
- func SystemctlIsEnabled(thing string) bool
- func SystemctlIsRunning(thing string) bool
- func SystemctlReloadTryRestart(thing string) error
- func SystemctlRestart(thing string) error
- func SystemctlStart(thing string) error
- func SystemctlStop(thing string) error
- func TestSysString(parameter, value string) error
- func TunedAdmOff() error
- func TunedAdmProfile(profileName string) error
- func WarningLog(txt string, stuff ...interface{})
- func WriteTunedAdmProfile(profileName string) error
- type BlockDev
- type MountPoint
- type MountPoints
- type SecLimits
- func (limits *SecLimits) Apply() error
- func (limits *SecLimits) ApplyDropIn(lim []string, noteID string) error
- func (limits *SecLimits) Get(domain, typeName, item string) (string, bool)
- func (limits *SecLimits) GetOr0(domain, typeName, item string) SecurityLimitInt
- func (limits *SecLimits) Set(domain, typeName, item, value string)
- func (limits *SecLimits) ToDropIn(lim []string, noteID, fileName string) string
- func (limits *SecLimits) ToText() string
- type SecLimitsEntry
- type SecurityLimitInt
Constants ¶
const ( MemMainTotalKey = "MemTotal" MemSwapTotalKey = "SwapTotal" )
string definitions for parsing /proc/meminfo output
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
const SaptuneSectionDir = "/var/lib/saptune/sections"
SaptuneSectionDir defines saptunes saved state directory
const SecurityLimitUnlimitedValue = SecurityLimitInt(-1)
SecurityLimitUnlimitedValue is the constant integer value that represents unrestricted limit.
Variables ¶
var ErrorExitOut = ErrorLog
ErrorExitOut defines, which exit output function should be used
var OSExit = os.Exit
OSExit defines, which exit function should be used
var SecurityLimitUnlimitedString = []string{"unlimited", "infinity"}
SecurityLimitUnlimitedString are the string constants that represent unrestricted limit.
Functions ¶
func BlockDeviceIsDisk ¶
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 ¶
CheckCPUState checks, if all cpus have the same state settings returns true, if the cpu states differ
func CheckForPattern ¶
CheckForPattern returns true, if the file is available and contains the expected string
func CheckRpmVers ¶
CheckRpmVers compare versions of 2 RPMs (installed version, expected version) Return 0 (Equal), 1 (GreaterThan) or -1 (LessThan)
func CliArg ¶
CliArg returns the i-th command line parameter, or empty string if it is not specified.
func CmdIsAvailable ¶
CmdIsAvailable returns true, if the cmd is available.
func CmpRpmVers ¶
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 ¶
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 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 GetAvailServices ¶
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 ¶
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 ¶
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 GetPerfBias ¶
func GetPerfBias() string
GetPerfBias retrieve CPU performance configuration from the system
func GetRpmVers ¶
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 ¶
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 ¶
GetSysChoice read a /sys/ key that comes with current value and alternative choices, return the current choice or empty string.
func GetSysString ¶
GetSysString read a /sys/ key and return the string value.
func GetSysctlInt ¶
GetSysctlInt read an integer sysctl key.
func GetSysctlString ¶
GetSysctlString read a sysctl key and return the string value.
func GetSysctlUint64 ¶
GetSysctlUint64 read an uint64 sysctl key.
func GetSysctlUint64Field ¶
GetSysctlUint64Field extracts an uint64 value from a sysctl key of many fields.
func GetTasksMax ¶
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 IsServiceAvailable ¶
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 IsValidGovernor ¶
IsValidGovernor check, if the system will support CPU frequency settings
func LogInit ¶
func LogInit(logFile, debug, verbose string)
LogInit initialise the different log writer saptune will use
func ParseCmdline ¶
ParseCmdline parse /proc/cmdline into key(string) - value(string) pairs. return value for given boot option or 'NA', if not available
func ParseMeminfo ¶
ParseMeminfo parse /proc/meminfo into key(string) - value(int) pairs. Panic on error.
func ReadConfigFile ¶
ReadConfigFile read content of config file
func ReleaseSaptuneLock ¶
func ReleaseSaptuneLock()
ReleaseSaptuneLock removes the saptune lock file
func RemountSHM ¶
RemountSHM invoke mount command to resize /dev/shm to the specified value.
func SecureBootEnabled ¶
func SecureBootEnabled() bool
SecureBootEnabled check, if the system is in lock-down mode
func SetForceLatency ¶
SetForceLatency set CPU latency configuration to the system
func SetGovernor ¶
SetGovernor set performance configuration regarding to cpu frequency to the system using 'cpupower' command
func SetPerfBias ¶
SetPerfBias set CPU performance configuration to the system using 'cpupower' command
func SetSysString ¶
SetSysString write a string /sys/ value.
func SetSysctlInt ¶
SetSysctlInt write an integer sysctl value.
func SetSysctlString ¶
SetSysctlString write a string sysctl value.
func SetSysctlUint64 ¶
SetSysctlUint64 write an integer sysctl value.
func SetSysctlUint64Field ¶
SetSysctlUint64Field write an integer sysctl value into the specified field pf the key.
func SetTasksMax ¶
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 SystemctlDisable ¶
SystemctlDisable call systemctl disable on thing.
func SystemctlDisableStop ¶
SystemctlDisableStop call systemctl disable and then systemctl stop on thing. Panic on error.
func SystemctlEnable ¶
SystemctlEnable call systemctl enable on thing.
func SystemctlEnableStart ¶
SystemctlEnableStart call systemctl enable and then systemctl start on thing.
func SystemctlIsEnabled ¶
SystemctlIsEnabled return true only if systemctl suggests that the thing is enabled.
func SystemctlIsRunning ¶
SystemctlIsRunning return true only if systemctl suggests that the thing is running.
func SystemctlReloadTryRestart ¶
SystemctlReloadTryRestart call systemctl reload on thing.
func SystemctlRestart ¶
SystemctlRestart call systemctl restart on thing.
func SystemctlStart ¶
SystemctlStart call systemctl start on thing.
func SystemctlStop ¶
SystemctlStop call systemctl stop on thing.
func TestSysString ¶
TestSysString Test writing a string /sys/ value.
func TunedAdmOff ¶
func TunedAdmOff() error
TunedAdmOff calls tuned-adm to switch off the active profile.
func TunedAdmProfile ¶
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 ¶
WriteTunedAdmProfile write new profile to tuned, used instead of sometimes unreliable 'tuned-adm' command
Types ¶
type BlockDev ¶
BlockDev contains all key-value pairs of current avaliable block devices in /sys/block
func GetBlockDeviceInfo ¶
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 ¶
ParseSecLimits read limits.conf text and parse the text into memory structures.
func ParseSecLimitsFile ¶
ParseSecLimitsFile read limits.conf and parse the file content into memory structures.
func (*SecLimits) Apply ¶
Apply overwrite /etc/security/limits.conf with the content of this structure.
func (*SecLimits) ApplyDropIn ¶
ApplyDropIn overwrite file 'dropInFile' with the content of this structure.
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.
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