Documentation
¶
Index ¶
- Constants
- Variables
- func CustomLogInit(level logrus.Level) *logrus.Logger
- func DiscardBootReason(log *base.LogObject)
- func DiscardRebootImage(log *base.LogObject)
- func DiscardRebootReason(log *base.LogObject)
- func DumpAllStacks(log *base.LogObject, agentName string)
- func EveCurrentPartition() string
- func EveVersion() string
- func FlushCoverage(_ *base.LogObject)
- func GetBootReason(log *base.LogObject) (types.BootReason, time.Time)
- func GetGlobalConfig(log *base.LogObject, sub pubsub.Subscription) *types.ConfigItemValueMap
- func GetLogLevel(log *base.LogObject, sub pubsub.Subscription, agentName string) (string, bool)
- func GetLogLevelNoDefault(log *base.LogObject, sub pubsub.Subscription, agentName string) (string, bool)
- func GetMyStack() string
- func GetRebootImage(log *base.LogObject) string
- func GetRebootReason(log *base.LogObject) (string, time.Time, string)
- func HandleGlobalConfig(log *base.LogObject, sub pubsub.Subscription, agentName string, ...) *types.ConfigItemValueMap
- func Init(agentName string) (*logrus.Logger, *base.LogObject)
- func ListenDebug(log *base.LogObject, stacksDumpFileName, memDumpFileName string)
- func LogLevel(gc *types.ConfigItemValueMap, agentName string) string
- func ManageStatFileSize(log *base.LogObject, statFile *os.File, thresholdSize uint64, linesToKeep uint) (uint64, error)
- func MaybeInitSigUsr2(sigs chan os.Signal)
- func MemoryPSICollector(collectorCtx context.Context, log *base.LogObject) error
- func PressureMemoryFile() string
- func PrintStacks(log *base.LogObject)
- func RebootReason(reason string, bootReason types.BootReason, agentName string, agentPid int, ...)
- func RebootStack(log *base.LogObject, stacks string, agentName string, agentPid int)
- func UpdatePressureMemoryFile(newpath string)
- type FatalHook
- type MemAllocationSite
- type PressureStallInfo
- type SkipCallerHook
- type SourceHook
Constants ¶
const ( // PSIHeader is the header of the PSI log file PSIHeader = "date time someAvg10 someAvg60 someAvg300 someTotal fullAvg10 fullAvg60 fullAvg300 fullTotal" // PSITimeIntervalSec is the time interval in seconds to collect PSI data PSITimeIntervalSec = 1 // StatLinesPerHour is the maximum number of lines in the log file StatLinesPerHour = 60 * 60 / PSITimeIntervalSec // StatLineMaxSize is the maximum size of a log line in bytes. // The format of a log line is // "date time someAvg10 someAvg60 someAvg300 someTotal fullAvg10 fullAvg60 fullAvg300 fullTotal" // date is of format "2006-01-02" (10 bytes) // time is of format "15:04:05" (8 bytes) // someAvg10, someAvg60, someAvg300, fullAvg10, fullAvg60, fullAvg300 are of format "%.02f" // and the values are in a range of 0.00 to 100.00 (6 bytes maximum each) // totals are int64 and can be represented as a 20 bytes maximum string each // Plus 1 byte for the space between each field (9 spaces) and 1 byte for the newline character // Total size is 10 + 8 + 6*6 + 20*2 + 9 + 1 = 104 bytes // Nevertheless, most of the time the values are not at the maximum size, so we can consider // an average size of 75 bytes. This estimation is good enough for the purpose of the // calculation of the threshold file size. StatLineMaxSize uint64 = 104 // StatLineMinSize is the minimum size of a log line in bytes. It's the case when the values of // the "total" fields are at their minimum size (1 byte) and the values of the "avg" fields are // at their minimum size (0.00-9.99). The format of a log line is // It is 10 + 8 + 4*6 + 1*2 + 9 + 1 = 54 bytes StatLineMinSize uint64 = 54 // StatLineAvgSize is the average size of a log line in bytes. It's just for estimation purposes. StatLineAvgSize uint64 = 75 )
Variables ¶
var PsiMutex sync.Mutex
PsiMutex is the mutex to protect the access to the PSI files. We need it to avoid a race condition with the PSI data emulator in tests.
Functions ¶
func CustomLogInit ¶
CustomLogInit - allow pillar services and containers to use customized logging
func DiscardBootReason ¶
DiscardBootReason removes the BootReason file
func DiscardRebootImage ¶
DiscardRebootImage : Discard the last reboot-image file
func DiscardRebootReason ¶
DiscardRebootReason removes any reason and stack from /persist/
func DumpAllStacks ¶
DumpAllStacks writes to file but does not log
func EveCurrentPartition ¶
func EveCurrentPartition() string
EveCurrentPartition returns the current EVE image partition
func FlushCoverage ¶
FlushCoverage is a no-op in non-coverage builds.
func GetBootReason ¶
GetBootReason returns the BootReason enum, which is stored as a string in /persist, together with its timestamp
func GetGlobalConfig ¶
func GetGlobalConfig(log *base.LogObject, sub pubsub.Subscription) *types.ConfigItemValueMap
func GetLogLevel ¶
Returns (value, ok)
func GetLogLevelNoDefault ¶
func GetMyStack ¶
func GetMyStack() string
GetMyStack is used to log stack traces at certain call sites Excludes ourselves
func GetRebootImage ¶
GetRebootImage : Image from which the reboot happened
func GetRebootReason ¶
GetRebootReason returns the RebootReason string together with its timestamp plus the reboot stack. We limit the size we read to 16k for the RebootReason and to 512k for the stack, because in case of a kernel crash, the stack file contains the whole dmesg, which kernel buffer is limited to some reasonable value below 512k.
func HandleGlobalConfig ¶
func HandleGlobalConfig(log *base.LogObject, sub pubsub.Subscription, agentName string, debugOverride bool, logger *logrus.Logger) *types.ConfigItemValueMap
HandleGlobalConfig updates the LogLevel setting in the passed in logger based on GlobalConfig and debugOverride
func ListenDebug ¶
ListenDebug starts an HTTP server on localhost:6543 that provides various debugging capabilities. It sets up several endpoints for profiling, memory monitoring, and stack dumping. The server can only be started once and will run until a POST request is made to the /stop endpoint. This function ensures that only one instance of the server is running at any given time. For the API documentation, see the info string in the function.
func ManageStatFileSize ¶
func ManageStatFileSize(log *base.LogObject, statFile *os.File, thresholdSize uint64, linesToKeep uint) (uint64, error)
ManageStatFileSize manages the size of the stat file by truncating it when it reaches the threshold size and keeping only the last linesToKeep lines of statistics (excluding the header). log is the logger object. statFile is the file to manage. thresholdSize is the maximum size of the file. linesToKeep is the number of lines of statistics (excluding the header) to keep in the file. It returns an error if the file size is still greater than the threshold size after truncating. We make it public to be able to test it.
func MaybeInitSigUsr2 ¶
MaybeInitSigUsr2 sets up a SIGUSR2 handler if !coverage
func MemoryPSICollector ¶
MemoryPSICollector collects PSI data and writes it to a statistics file. log is the logger object. collectorCtx is the context of the collector. The statistics file is truncated when it reaches a threshold size and keeps only the last linesToKeep lines. The collector runs until the context is canceled.
func PressureMemoryFile ¶
func PressureMemoryFile() string
PressureMemoryFile returns the path to the memory pressure file in /proc
func RebootReason ¶
func RebootReason(reason string, bootReason types.BootReason, agentName string, agentPid int, normal bool)
RebootReason writes a reason string in /persist/reboot-reason, including agentName and date It also appends to /persist/log/reboot-reason.log If the bootReasonFile is not present it will write the bootReason enum there as a string. That ensures that if we have a e.g., a log.Fatal followed by watchdog we retain the fatal. NOTE: can not use log here since we are called from a log hook!
func RebootStack ¶
RebootStack writes stack in /persist/reboot-stack and appends to /persist/log/reboot-stack.log XXX remove latter? Can grow unbounded.
func UpdatePressureMemoryFile ¶
func UpdatePressureMemoryFile(newpath string)
UpdatePressureMemoryFile sets the path to the memory pressure file (mostly used for tests)
Types ¶
type FatalHook ¶
type FatalHook struct {
// contains filtered or unexported fields
}
FatalHook is used make sure we save the fatal and panic strings to a file
type MemAllocationSite ¶
type MemAllocationSite struct {
InUseBytes int64
InUseObjects int64
AllocBytes int64
AllocObjects int64
PrintedStack string
}
MemAllocationSite is the return value of GetMemProfile
func GetMemAllocationSites ¶
func GetMemAllocationSites(reportZeroInUse bool) (int, []MemAllocationSite)
GetMemAllocationSites returns the non-zero allocation sites in the form of an array of strings; each string is for one allocation call site. If reportZeroInUse is set it also reports with zero InUse.
type PressureStallInfo ¶
type PressureStallInfo struct {
SomeAvg10 float64
SomeAvg60 float64
SomeAvg300 float64
SomeTotal int64
FullAvg10 float64
FullAvg60 float64
FullAvg300 float64
FullTotal int64
}
PressureStallInfo is the information about the pressure stall available in the PSI files. See https://www.kernel.org/doc/html/latest/accounting/psi.html for more information.
type SkipCallerHook ¶
type SkipCallerHook struct {
}
SkipCallerHook is used to skip to the "base" package entry in the stack
func (*SkipCallerHook) Fire ¶
func (hook *SkipCallerHook) Fire(entry *logrus.Entry) error
Fire does the skipping
func (*SkipCallerHook) Levels ¶
func (hook *SkipCallerHook) Levels() []logrus.Level
Levels installs the SkipCallerHook for all levels
type SourceHook ¶
type SourceHook struct {
// contains filtered or unexported fields
}
SourceHook is used to add source and pid if not already set
func (*SourceHook) Fire ¶
func (hook *SourceHook) Fire(entry *logrus.Entry) error
Fire adds source and pid if not already set
func (*SourceHook) Levels ¶
func (hook *SourceHook) Levels() []logrus.Level
Levels installs the SourceHook for all levels