131 lines
3.6 KiB
Go
131 lines
3.6 KiB
Go
package sprigx
|
|
|
|
import (
|
|
`os`
|
|
`os/user`
|
|
`path`
|
|
`path/filepath`
|
|
`runtime`
|
|
|
|
`github.com/davecgh/go-spew/spew`
|
|
`github.com/shirou/gopsutil/v4/cpu`
|
|
`github.com/shirou/gopsutil/v4/disk`
|
|
`github.com/shirou/gopsutil/v4/host`
|
|
`github.com/shirou/gopsutil/v4/load`
|
|
`github.com/shirou/gopsutil/v4/mem`
|
|
psnet `github.com/shirou/gopsutil/v4/net`
|
|
`github.com/shirou/gopsutil/v4/process`
|
|
`github.com/shirou/gopsutil/v4/sensors`
|
|
`r00t2.io/sysutils`
|
|
)
|
|
|
|
var (
|
|
// genericMap holds functions usable/intended for use in either an [html/template.FuncMap] or [text/template.FuncMap].
|
|
genericMap map[string]any = map[string]any{
|
|
// Debugging
|
|
"dump": spew.Sdump,
|
|
/*
|
|
"Meta"/Template-Helpers
|
|
*/
|
|
"metaIsNil": metaIsNil,
|
|
/*
|
|
OS
|
|
*/
|
|
"osFQDN": osFQDN,
|
|
"osGroupById": osGroupById,
|
|
"osGroupByName": user.LookupGroup,
|
|
"osHost": osHost,
|
|
"osHostname": os.Hostname,
|
|
"osIdState": sysutils.GetIDState,
|
|
"osUser": user.Current,
|
|
"osUserById": osUserById,
|
|
"osUserByName": user.Lookup,
|
|
/*
|
|
Paths
|
|
*/
|
|
// Paths: Generic
|
|
"pathJoin": path.Join,
|
|
"pathPipeJoin": pathPipeJoin,
|
|
"pathSliceJoin": pathSliceJoin,
|
|
"pathSlicePipeJoin": pathSlicePipeJoin,
|
|
"pathSubJoin": pathSubJoin,
|
|
// Paths: OS/Platform
|
|
"osPathJoin": filepath.Join,
|
|
"osPathPipeJoin": osPathPipeJoin,
|
|
"osPathSep": osPathSep,
|
|
"osPathSliceJoin": osPathSliceJoin,
|
|
"osPathSlicePipeJoin": osPathSlicePipeJoin,
|
|
"osPathSubJoin": osPathSubJoin,
|
|
/*
|
|
PSUtil
|
|
(https://pkg.go.dev/github.com/shirou/gopsutil/v4)
|
|
*/
|
|
// .../cpu
|
|
"psCpuCnts": cpu.Counts,
|
|
"psCpuInfo": cpu.Info,
|
|
"psCpuPct": cpu.Percent,
|
|
"psCpuTimes": cpu.Times,
|
|
// .../disk
|
|
"psDiskIoCnts": disk.IOCounters,
|
|
"psDiskLabel": disk.Label,
|
|
"psDiskParts": disk.Partitions,
|
|
"psDiskSerial": disk.SerialNumber,
|
|
"psDiskUsage": disk.Usage,
|
|
// .../host
|
|
"psHostBoot": host.BootTime,
|
|
"psHostId": host.HostID,
|
|
"psHostInfo": host.Info,
|
|
"psHostKernArch": host.KernelArch,
|
|
"psHostKernVer": host.KernelVersion,
|
|
"psHostPlatInfo": psHostPlatInfo,
|
|
"psHostUptime": host.Uptime,
|
|
"psHostUsers": host.Users,
|
|
"psHostVirt": psHostVirt,
|
|
// .../load
|
|
"psLoadAvg": load.Avg,
|
|
"psLoadMisc": load.Misc,
|
|
// .../mem
|
|
"psMemSwap": mem.SwapMemory,
|
|
"psMemSwapDevs": mem.SwapDevices,
|
|
"psMemVMem": mem.VirtualMemory,
|
|
// .../net
|
|
"psNetConns": psnet.Connections,
|
|
"psNetConnsMax": psnet.ConnectionsMax,
|
|
"psNetConnsPid": psnet.ConnectionsPid,
|
|
"psNetConnsPidMax": psnet.ConnectionsPidMax,
|
|
"psNetCTStats": psnet.ConntrackStats,
|
|
"psNetCTStatList": psnet.NewConntrackStatList,
|
|
"psNetFilterCnts": psnet.FilterCounters,
|
|
"psNetIoCnts": psnet.IOCounters,
|
|
"psNetIoCntsFile": psnet.IOCountersByFile,
|
|
"psNetIfaces": psnet.Interfaces,
|
|
"psNetPids": psnet.Pids,
|
|
"psNetProtoCnt": psnet.ProtoCounters,
|
|
// .../process
|
|
"psProcs": process.Processes,
|
|
"psProcNew": process.NewProcess,
|
|
"psProcPids": process.Pids,
|
|
"psProcPidExists": process.PidExists,
|
|
// .../sensors
|
|
"psSensorTemps": sensors.SensorsTemperatures,
|
|
/*
|
|
Strings
|
|
*/
|
|
"extIndent": extIndent, // PR in: https://github.com/Masterminds/sprig/pull/468
|
|
/*
|
|
System/Platform
|
|
*/
|
|
"sysArch": sysArch,
|
|
"sysNumCpu": runtime.NumCPU,
|
|
"sysOsName": sysOsNm,
|
|
"sysRuntime": sysRuntime,
|
|
|
|
}
|
|
|
|
// htmlMap holds functions usable/intended for use in only an [html/template.FuncMap].
|
|
htmlMap map[string]any = map[string]any{}
|
|
|
|
// txtMap holds functions usable/intended for use in only a [text/template.FuncMap].
|
|
txtMap map[string]any = map[string]any{}
|
|
)
|