util

package
v0.50.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BenignDropReasons = map[string]bool{
	"NOT_SPECIFIED":       true,
	"NO_SOCKET":           true,
	"SOCKET_FILTER":       true,
	"OTHERHOST":           true,
	"TCP_FLAGS":           true,
	"TCP_ZEROWINDOW":      true,
	"TCP_OLD_DATA":        true,
	"TCP_OLD_SEQUENCE":    true,
	"TCP_OVERWINDOW":      true,
	"TCP_OFOMERGE":        true,
	"SKB_CONSUMED":        true,
	"TCP_OFO_QUEUE_PRUNE": true,
}

BenignDropReasons is the canonical set of kernel SKB_DROP_REASON strings that represent normal TCP/IP lifecycle events, not actual packet loss. Maintained in one place to prevent divergence across packages.

Functions

func CPUPct

func CPUPct(prevActive, currActive, prevTotal, currTotal uint64) float64

CPUPct computes CPU usage percentage from two tick values and total ticks.

func Delta

func Delta(prev, curr uint64) uint64

Delta returns curr - prev, or 0 if curr < prev (counter wrap).

func FieldsAt

func FieldsAt(line string, idx int) string

FieldsAt returns the field at the given index from a whitespace-split line. Returns empty string if index is out of bounds.

func FmtBytes

func FmtBytes(b uint64) string

FmtBytes formats bytes to human-readable string (1024-based).

func IsBenignDropReason

func IsBenignDropReason(reason string) bool

IsBenignDropReason returns true if the drop reason string is benign.

func ParseFloat64

func ParseFloat64(s string) float64

ParseFloat64 parses a string to float64, returning 0 on error. NaN and Inf inputs are also treated as 0 to prevent downstream poisoning.

func ParseInt

func ParseInt(s string) int

ParseInt parses a string to int, returning 0 on error.

func ParseKeyValueFile

func ParseKeyValueFile(path string) (map[string]string, error)

ParseKeyValueFile parses a file with "key value" or "key: value" lines.

func ParseKeyValueLines

func ParseKeyValueLines(lines []string) map[string]string

ParseKeyValueLines parses lines with "key value" or "key: value" format.

func ParseUint64

func ParseUint64(s string) uint64

ParseUint64 parses a string to uint64, returning 0 on error.

func Rate

func Rate(prev, curr uint64, dt time.Duration) float64

Rate computes the per-second rate between two counter values.

func RatePct

func RatePct(prev, curr uint64, dt time.Duration, capacity float64) float64

RatePct computes the percentage utilization between two counter values given a time delta and a total capacity in the same unit.

func ReadFileLines

func ReadFileLines(path string) ([]string, error)

ReadFileLines reads a file and returns its lines.

func ReadFileString

func ReadFileString(path string) (string, error)

ReadFileString reads a file and returns its contents as a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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