utils

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package utils provides utility functions for the agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToGigabytes

func BytesToGigabytes(b uint64) float64

BytesToGigabytes converts bytes to gigabytes and rounds to two decimal places.

func BytesToMegabytes

func BytesToMegabytes(b float64) float64

BytesToMegabytes converts bytes to megabytes and rounds to two decimal places.

func CgroupMountPoint added in v0.21.1

func CgroupMountPoint(path, fstype, controller string) string

CgroupMountPoint finds a hierarchy's mount point in the given mountinfo file. Use fstype "cgroup2" and an empty controller for v2, or "cgroup" and the desired controller for v1. It returns the mount root, not a process's leaf.

func FileExists

func FileExists(path string) bool

FileExists reports whether the given path exists.

func GetEnv

func GetEnv(key string) (value string, exists bool)

GetEnv retrieves an environment variable with a "BESZEL_AGENT_" prefix, or falls back to the unprefixed key.

func InCgroupV2 added in v0.21.1

func InCgroupV2(path string) bool

InCgroupV2 reports whether the given /proc/self/cgroup file lists the unified hierarchy (a "0::<path>" entry).

func LookPathHomebrew

func LookPathHomebrew(file string) (string, error)

LookPathHomebrew is like exec.LookPath but also checks Homebrew paths.

func ReadCgroupStat added in v0.21.1

func ReadCgroupStat(path string) (map[string]uint64, error)

ReadCgroupStat reads all unsigned counters from a cgroup key/value stat file in one read. Malformed entries are omitted; callers must check required keys.

func ReadIntFile added in v0.21.1

func ReadIntFile(path string) (int64, bool)

ReadIntFile parses a signed decimal integer (e.g. a v1 CPU quota of -1).

func ReadStringFile

func ReadStringFile(path string) string

ReadStringFile returns trimmed file contents or empty string on error.

func ReadStringFileLimited

func ReadStringFileLimited(path string, maxSize int) (string, error)

ReadStringFileLimited reads a file into a string with a maximum size (in bytes) to avoid allocating large buffers and potential panics with pseudo-files when the size is misreported.

func ReadStringFileOK

func ReadStringFileOK(path string) (string, bool)

ReadStringFileOK returns trimmed file contents and read success.

func ReadUintFile

func ReadUintFile(path string) (uint64, bool)

ReadUintFile parses a decimal uint64 value from a file.

func TwoDecimals

func TwoDecimals(value float64) float64

TwoDecimals rounds a float64 value to two decimal places.

Types

This section is empty.

Jump to

Keyboard shortcuts

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