mirror of https://github.com/gofiber/fiber.git
Run gofumpt and goimports (#2662)
* run goimports -w -local github.com/gofiber/fiber . * run gofumpt -w -extra .pull/2664/head
parent
d25dfa4ce7
commit
ab4e731607
|
@ -177,7 +177,7 @@ func StringFromIID(iid *GUID) (str string, err error) {
|
|||
}
|
||||
|
||||
// CreateInstance of single uninitialized object with GUID.
|
||||
func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
||||
func CreateInstance(clsid, iid *GUID) (unk *IUnknown, err error) {
|
||||
if iid == nil {
|
||||
iid = IID_IUnknown
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ func CreateInstance(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
|||
}
|
||||
|
||||
// GetActiveObject retrieves pointer to active object.
|
||||
func GetActiveObject(clsid *GUID, iid *GUID) (unk *IUnknown, err error) {
|
||||
func GetActiveObject(clsid, iid *GUID) (unk *IUnknown, err error) {
|
||||
if iid == nil {
|
||||
iid = IID_IUnknown
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ func CreateDispTypeInfo(idata *INTERFACEDATA) (pptinfo *IUnknown, err error) {
|
|||
}
|
||||
|
||||
// copyMemory moves location of a block of memory.
|
||||
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {
|
||||
func copyMemory(dest, src unsafe.Pointer, length uint32) {
|
||||
procCopyMemory.Call(uintptr(dest), uintptr(src), uintptr(length))
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ func GetUserDefaultLCID() (lcid uint32) {
|
|||
// GetMessage in message queue from runtime.
|
||||
//
|
||||
// This function appears to block. PeekMessage does not block.
|
||||
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) {
|
||||
func GetMessage(msg *Msg, hwnd, MsgFilterMin, MsgFilterMax uint32) (ret int32, err error) {
|
||||
r0, _, err := procGetMessageW.Call(uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax))
|
||||
ret = int32(r0)
|
||||
return
|
||||
|
|
|
@ -92,12 +92,12 @@ func StringFromIID(iid *GUID) (string, error) {
|
|||
}
|
||||
|
||||
// CreateInstance of single uninitialized object with GUID.
|
||||
func CreateInstance(clsid *GUID, iid *GUID) (*IUnknown, error) {
|
||||
func CreateInstance(clsid, iid *GUID) (*IUnknown, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
// GetActiveObject retrieves pointer to active object.
|
||||
func GetActiveObject(clsid *GUID, iid *GUID) (*IUnknown, error) {
|
||||
func GetActiveObject(clsid, iid *GUID) (*IUnknown, error) {
|
||||
return nil, NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ func CreateDispTypeInfo(idata *INTERFACEDATA) (*IUnknown, error) {
|
|||
}
|
||||
|
||||
// copyMemory moves location of a block of memory.
|
||||
func copyMemory(dest unsafe.Pointer, src unsafe.Pointer, length uint32) {}
|
||||
func copyMemory(dest, src unsafe.Pointer, length uint32) {}
|
||||
|
||||
// GetUserDefaultLCID retrieves current user default locale.
|
||||
func GetUserDefaultLCID() uint32 {
|
||||
|
@ -160,7 +160,7 @@ func GetUserDefaultLCID() uint32 {
|
|||
// GetMessage in message queue from runtime.
|
||||
//
|
||||
// This function appears to block. PeekMessage does not block.
|
||||
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (int32, error) {
|
||||
func GetMessage(msg *Msg, hwnd, MsgFilterMin, MsgFilterMax uint32) (int32, error) {
|
||||
return int32(0), NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ func (c *Connection) Release() {
|
|||
|
||||
// Load COM object from list of programIDs or strings.
|
||||
func (c *Connection) Load(names ...string) (errors []error) {
|
||||
var tempErrors = make([]error, len(names))
|
||||
var numErrors = 0
|
||||
tempErrors := make([]error, len(names))
|
||||
numErrors := 0
|
||||
for _, name := range names {
|
||||
err := c.Create(name)
|
||||
if err != nil {
|
||||
|
|
|
@ -89,8 +89,10 @@ var (
|
|||
CLSID_COMTestScalarClass = NewGUID("{865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}")
|
||||
)
|
||||
|
||||
const hextable = "0123456789ABCDEF"
|
||||
const emptyGUID = "{00000000-0000-0000-0000-000000000000}"
|
||||
const (
|
||||
hextable = "0123456789ABCDEF"
|
||||
emptyGUID = "{00000000-0000-0000-0000-000000000000}"
|
||||
)
|
||||
|
||||
// GUID is Windows API specific GUID type.
|
||||
//
|
||||
|
@ -177,7 +179,7 @@ func decodeHexUint16(src []byte) (value uint16, ok bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func decodeHexByte64(s1 []byte, s2 []byte) (value [8]byte, ok bool) {
|
||||
func decodeHexByte64(s1, s2 []byte) (value [8]byte, ok bool) {
|
||||
var ok1, ok2, ok3, ok4, ok5, ok6, ok7, ok8 bool
|
||||
value[0], ok1 = decodeHexByte(s1[0], s1[1])
|
||||
value[1], ok2 = decodeHexByte(s1[2], s1[3])
|
||||
|
@ -269,7 +271,7 @@ func putByteHex(dst, src []byte) {
|
|||
// IsEqualGUID compares two GUID.
|
||||
//
|
||||
// Not constant time comparison.
|
||||
func IsEqualGUID(guid1 *GUID, guid2 *GUID) bool {
|
||||
func IsEqualGUID(guid1, guid2 *GUID) bool {
|
||||
return guid1.Data1 == guid2.Data1 &&
|
||||
guid1.Data2 == guid2.Data2 &&
|
||||
guid1.Data3 == guid2.Data3 &&
|
||||
|
|
|
@ -73,7 +73,7 @@ func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}
|
|||
if len(params) > 0 {
|
||||
vargs = make([]VARIANT, len(params))
|
||||
for i, v := range params {
|
||||
//n := len(params)-i-1
|
||||
// n := len(params)-i-1
|
||||
n := len(params) - i - 1
|
||||
VariantInit(&vargs[n])
|
||||
switch vv := v.(type) {
|
||||
|
|
|
@ -56,7 +56,7 @@ func dispRelease(this *ole.IUnknown) int32 {
|
|||
return pthis.ref
|
||||
}
|
||||
|
||||
func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen int, lcid int, pdisp []int32) uintptr {
|
||||
func dispGetIDsOfNames(this *ole.IUnknown, iid *ole.GUID, wnames []*uint16, namelen, lcid int, pdisp []int32) uintptr {
|
||||
pthis := (*stdDispatch)(unsafe.Pointer(this))
|
||||
names := make([]string, len(wnames))
|
||||
for i := 0; i < len(names); i++ {
|
||||
|
|
|
@ -51,7 +51,7 @@ func safeArrayCopy(original *SafeArray) (*SafeArray, error) {
|
|||
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayCopyData in Windows API.
|
||||
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) error {
|
||||
func safeArrayCopyData(original, duplicate *SafeArray) error {
|
||||
return NewError(E_NOTIMPL)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ var (
|
|||
procSafeArrayUnaccessData = modoleaut32.NewProc("SafeArrayUnaccessData")
|
||||
procSafeArrayUnlock = modoleaut32.NewProc("SafeArrayUnlock")
|
||||
procSafeArrayPutElement = modoleaut32.NewProc("SafeArrayPutElement")
|
||||
//procSafeArrayRedim = modoleaut32.NewProc("SafeArrayRedim") // TODO
|
||||
//procSafeArraySetIID = modoleaut32.NewProc("SafeArraySetIID") // TODO
|
||||
// procSafeArrayRedim = modoleaut32.NewProc("SafeArrayRedim") // TODO
|
||||
// procSafeArraySetIID = modoleaut32.NewProc("SafeArraySetIID") // TODO
|
||||
procSafeArrayGetRecordInfo = modoleaut32.NewProc("SafeArrayGetRecordInfo")
|
||||
procSafeArraySetRecordInfo = modoleaut32.NewProc("SafeArraySetRecordInfo")
|
||||
)
|
||||
|
@ -101,7 +101,7 @@ func safeArrayCopy(original *SafeArray) (safearray *SafeArray, err error) {
|
|||
// safeArrayCopyData duplicates SafeArray into another SafeArray object.
|
||||
//
|
||||
// AKA: SafeArrayCopyData in Windows API.
|
||||
func safeArrayCopyData(original *SafeArray, duplicate *SafeArray) (err error) {
|
||||
func safeArrayCopyData(original, duplicate *SafeArray) (err error) {
|
||||
err = convertHresultToError(
|
||||
procSafeArrayCopyData.Call(
|
||||
uintptr(unsafe.Pointer(original)),
|
||||
|
|
|
@ -93,7 +93,7 @@ func lpOleStrLen(p *uint16) (length int64) {
|
|||
}
|
||||
|
||||
// convertHresultToError converts syscall to error, if call is unsuccessful.
|
||||
func convertHresultToError(hr uintptr, r2 uintptr, ignore error) (err error) {
|
||||
func convertHresultToError(hr, r2 uintptr, ignore error) (err error) {
|
||||
if hr != 0 {
|
||||
err = NewError(hr)
|
||||
}
|
||||
|
|
|
@ -388,8 +388,10 @@ type coder struct {
|
|||
buf []byte
|
||||
}
|
||||
|
||||
type decoder coder
|
||||
type encoder coder
|
||||
type (
|
||||
decoder coder
|
||||
encoder coder
|
||||
)
|
||||
|
||||
func (d *decoder) uint8() uint8 {
|
||||
x := d.buf[0]
|
||||
|
|
|
@ -97,7 +97,6 @@ var ErrNotImplementedError = errors.New("not implemented yet")
|
|||
// ReadFile reads contents from a file
|
||||
func ReadFile(filename string) (string, error) {
|
||||
content, err := os.ReadFile(filename)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -320,7 +319,7 @@ func PathExists(filename string) bool {
|
|||
}
|
||||
|
||||
// GetEnv retrieves the environment variable key. If it does not exist it returns the default.
|
||||
func GetEnv(key string, dfault string, combineWith ...string) string {
|
||||
func GetEnv(key, dfault string, combineWith ...string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
value = dfault
|
||||
|
|
|
@ -60,7 +60,6 @@ func NumProcs() (uint64, error) {
|
|||
}
|
||||
|
||||
func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
||||
|
||||
system, role, err := Virtualization()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -191,7 +190,6 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|||
if PathExists(filepath.Join(filename, "self", "status")) {
|
||||
contents, err := ReadLines(filepath.Join(filename, "self", "status"))
|
||||
if err == nil {
|
||||
|
||||
if StringsContains(contents, "s_context:") ||
|
||||
StringsContains(contents, "VxID:") {
|
||||
system = "linux-vserver"
|
||||
|
@ -240,7 +238,7 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|||
return system, role, nil
|
||||
}
|
||||
|
||||
func GetOSRelease() (platform string, version string, err error) {
|
||||
func GetOSRelease() (platform, version string, err error) {
|
||||
contents, err := ReadLines(HostEtc("os-release"))
|
||||
if err != nil {
|
||||
return "", "", nil // return empty
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/wmi"
|
||||
)
|
||||
|
||||
// for double values
|
||||
|
@ -155,7 +156,7 @@ func NewWin32PerformanceCounter(postName, counterName string) (*Win32Performance
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var counter = Win32PerformanceCounter{
|
||||
counter := Win32PerformanceCounter{
|
||||
Query: query,
|
||||
PostName: postName,
|
||||
CounterName: counterName,
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
// Sleep awaits for provided interval.
|
||||
// Can be interrupted by context cancelation.
|
||||
func Sleep(ctx context.Context, interval time.Duration) error {
|
||||
var timer = time.NewTimer(interval)
|
||||
timer := time.NewTimer(interval)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
if !timer.Stop() {
|
||||
|
|
|
@ -51,8 +51,10 @@ type lastPercent struct {
|
|||
lastPerCPUTimes []TimesStat
|
||||
}
|
||||
|
||||
var lastCPUPercent lastPercent
|
||||
var invoke common.Invoker = common.Invoke{}
|
||||
var (
|
||||
lastCPUPercent lastPercent
|
||||
invoke common.Invoker = common.Invoke{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
lastCPUPercent.Lock()
|
||||
|
|
|
@ -107,5 +107,4 @@ func allCPUTimes() ([]TimesStat, error) {
|
|||
}
|
||||
|
||||
return []TimesStat{c}, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -11,18 +11,21 @@ import (
|
|||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
var ClocksPerSec = float64(128)
|
||||
var cpuMatch = regexp.MustCompile(`^CPU:`)
|
||||
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
|
||||
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
|
||||
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
|
||||
var cpuEnd = regexp.MustCompile(`^Trying to mount root`)
|
||||
var cpuTimesSize int
|
||||
var emptyTimes cpuTimes
|
||||
var (
|
||||
ClocksPerSec = float64(128)
|
||||
cpuMatch = regexp.MustCompile(`^CPU:`)
|
||||
originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
|
||||
featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
|
||||
featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
|
||||
cpuEnd = regexp.MustCompile(`^Trying to mount root`)
|
||||
cpuTimesSize int
|
||||
emptyTimes cpuTimes
|
||||
)
|
||||
|
||||
func init() {
|
||||
getconf, err := exec.LookPath("getconf")
|
||||
|
|
|
@ -11,19 +11,22 @@ import (
|
|||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
var ClocksPerSec = float64(128)
|
||||
var cpuMatch = regexp.MustCompile(`^CPU:`)
|
||||
var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
|
||||
var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
|
||||
var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
|
||||
var cpuEnd = regexp.MustCompile(`^Trying to mount root`)
|
||||
var cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`)
|
||||
var cpuTimesSize int
|
||||
var emptyTimes cpuTimes
|
||||
var (
|
||||
ClocksPerSec = float64(128)
|
||||
cpuMatch = regexp.MustCompile(`^CPU:`)
|
||||
originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`)
|
||||
featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`)
|
||||
featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`)
|
||||
cpuEnd = regexp.MustCompile(`^Trying to mount root`)
|
||||
cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`)
|
||||
cpuTimesSize int
|
||||
emptyTimes cpuTimes
|
||||
)
|
||||
|
||||
func init() {
|
||||
getconf, err := exec.LookPath("getconf")
|
||||
|
|
|
@ -37,7 +37,7 @@ func Times(percpu bool) ([]TimesStat, error) {
|
|||
|
||||
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
||||
filename := common.HostProc("stat")
|
||||
var lines = []string{}
|
||||
lines := []string{}
|
||||
if percpu {
|
||||
statlines, err := common.ReadLines(filename)
|
||||
if err != nil || len(statlines) < 2 {
|
||||
|
@ -314,7 +314,7 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
|
|||
}
|
||||
// physical cores
|
||||
// https://github.com/giampaolo/psutil/blob/122174a10b75c9beebe15f6c07dcf3afbe3b120d/psutil/_pslinux.py#L621-L629
|
||||
var threadSiblingsLists = make(map[string]bool)
|
||||
threadSiblingsLists := make(map[string]bool)
|
||||
if files, err := filepath.Glob(common.HostSys("devices/system/cpu/cpu[0-9]*/topology/thread_siblings_list")); err == nil {
|
||||
for _, file := range files {
|
||||
lines, err := common.ReadLines(file)
|
||||
|
|
|
@ -13,8 +13,9 @@ import (
|
|||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
// sys/sched.h
|
||||
|
@ -116,7 +117,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
|||
j *= 2
|
||||
}
|
||||
|
||||
var cpuTimes = make([]int32, CPUStates)
|
||||
cpuTimes := make([]int32, CPUStates)
|
||||
var mib []int32
|
||||
if percpu {
|
||||
mib = []int32{CTLKern, KernCptime2, int32(j)}
|
||||
|
|
|
@ -52,7 +52,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
|||
user := make(map[float64]float64)
|
||||
kern := make(map[float64]float64)
|
||||
iowt := make(map[float64]float64)
|
||||
//swap := make(map[float64]float64)
|
||||
// swap := make(map[float64]float64)
|
||||
kstatSysOut, err := invoke.CommandWithContext(ctx, kstatSys, "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot execute kstat: %s", err)
|
||||
|
|
|
@ -7,9 +7,10 @@ import (
|
|||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"github.com/gofiber/fiber/v2/internal/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -4,8 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
)
|
||||
|
||||
//var invoke common.Invoker = common.Invoke{}
|
||||
|
||||
// var invoke common.Invoker = common.Invoke{}
|
||||
type AvgStat struct {
|
||||
Load1 float64 `json:"load1"`
|
||||
Load5 float64 `json:"load5"`
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
var invoke common.Invoker = common.Invoke{}
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
var invoke common.Invoker = common.Invoke{}
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
type VirtualMemoryExStat struct {
|
||||
|
@ -188,7 +189,7 @@ func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
|
|||
Free: uint64(sysinfo.Freeswap) * uint64(sysinfo.Unit),
|
||||
}
|
||||
ret.Used = ret.Total - ret.Free
|
||||
//check Infinity
|
||||
// check Infinity
|
||||
if ret.Total != 0 {
|
||||
ret.UsedPercent = float64(ret.Total-ret.Free) / float64(ret.Total) * 100.0
|
||||
} else {
|
||||
|
@ -251,7 +252,6 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6
|
|||
|
||||
fn := common.HostProc("zoneinfo")
|
||||
lines, err := common.ReadLines(fn)
|
||||
|
||||
if err != nil {
|
||||
return ret.Free + ret.Cached // fallback under kernel 2.6.13
|
||||
}
|
||||
|
@ -264,7 +264,6 @@ func calcuateAvailVmem(ret *VirtualMemoryStat, retEx *VirtualMemoryExStat) uint6
|
|||
|
||||
if strings.HasPrefix(fields[0], "low") {
|
||||
lowValue, err := strconv.ParseUint(fields[1], 10, 64)
|
||||
|
||||
if err != nil {
|
||||
lowValue = 0
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"fmt"
|
||||
"os/exec"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
func GetPageSize() (uint64, error) {
|
||||
|
|
|
@ -6,8 +6,9 @@ import (
|
|||
"context"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -22,7 +22,6 @@ type IOCountersStat struct {
|
|||
Dropout uint64 `json:"dropout"` // total number of outgoing packets which were dropped (always 0 on OSX and BSD)
|
||||
Fifoin uint64 `json:"fifoin"` // total number of FIFO buffers errors while receiving
|
||||
Fifoout uint64 `json:"fifoout"` // total number of FIFO buffers errors while sending
|
||||
|
||||
}
|
||||
|
||||
// Addr is implemented compatibility to psutil
|
||||
|
@ -88,7 +87,7 @@ type ConntrackStat struct {
|
|||
SearchRestart uint32 `json:"search_restart"` // Conntrack table lookups restarted due to hashtable resizes
|
||||
}
|
||||
|
||||
func NewConntrackStat(e uint32, s uint32, f uint32, n uint32, inv uint32, ign uint32, del uint32, dlst uint32, ins uint32, insfail uint32, drop uint32, edrop uint32, ie uint32, en uint32, ec uint32, ed uint32, sr uint32) *ConntrackStat {
|
||||
func NewConntrackStat(e, s, f, n, inv, ign, del, dlst, ins, insfail, drop, edrop, ie, en, ec, ed, sr uint32) *ConntrackStat {
|
||||
return &ConntrackStat{
|
||||
Entries: e,
|
||||
Searched: s,
|
||||
|
|
|
@ -102,7 +102,6 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
|
|||
return getIOCountersAll(iocounters)
|
||||
}
|
||||
return iocounters, nil
|
||||
|
||||
}
|
||||
|
||||
// NetIOCountersByFile is an method which is added just a compatibility for linux.
|
||||
|
@ -186,7 +185,7 @@ var portMatch = regexp.MustCompile(`(.*)\.(\d+)$`)
|
|||
|
||||
// This function only works for netstat returning addresses with a "."
|
||||
// before the port (0.0.0.0.22 instead of 0.0.0.0:22).
|
||||
func parseNetstatAddr(local string, remote string, family uint32) (laddr Addr, raddr Addr, err error) {
|
||||
func parseNetstatAddr(local, remote string, family uint32) (laddr, raddr Addr, err error) {
|
||||
parse := func(l string) (Addr, error) {
|
||||
matches := portMatch.FindStringSubmatch(l)
|
||||
if matches == nil {
|
||||
|
@ -286,7 +285,7 @@ func hasCorrectInetProto(kind, proto string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func parseNetstatA(output string, kind string) ([]ConnectionStat, error) {
|
||||
func parseNetstatA(output, kind string) ([]ConnectionStat, error) {
|
||||
var ret []ConnectionStat
|
||||
lines := strings.Split(string(output), "\n")
|
||||
|
||||
|
@ -335,7 +334,6 @@ func parseNetstatA(output string, kind string) ([]ConnectionStat, error) {
|
|||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
func Connections(kind string) ([]ConnectionStat, error) {
|
||||
|
@ -343,7 +341,6 @@ func Connections(kind string) ([]ConnectionStat, error) {
|
|||
}
|
||||
|
||||
func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat, error) {
|
||||
|
||||
args := []string{"-na"}
|
||||
switch strings.ToLower(kind) {
|
||||
default:
|
||||
|
@ -367,7 +364,6 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
|
|||
return nil, err
|
||||
}
|
||||
out, err := invoke.CommandWithContext(ctx, netstat, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -378,7 +374,6 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
|
|||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) {
|
||||
|
|
|
@ -234,7 +234,6 @@ func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {
|
|||
maxfile := common.HostProc("sys/net/netfilter/nf_conntrack_max")
|
||||
|
||||
count, err := common.ReadInts(countfile)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -332,21 +331,25 @@ var kindTCP4 = netConnectionKindType{
|
|||
sockType: syscall.SOCK_STREAM,
|
||||
filename: "tcp",
|
||||
}
|
||||
|
||||
var kindTCP6 = netConnectionKindType{
|
||||
family: syscall.AF_INET6,
|
||||
sockType: syscall.SOCK_STREAM,
|
||||
filename: "tcp6",
|
||||
}
|
||||
|
||||
var kindUDP4 = netConnectionKindType{
|
||||
family: syscall.AF_INET,
|
||||
sockType: syscall.SOCK_DGRAM,
|
||||
filename: "udp",
|
||||
}
|
||||
|
||||
var kindUDP6 = netConnectionKindType{
|
||||
family: syscall.AF_INET6,
|
||||
sockType: syscall.SOCK_DGRAM,
|
||||
filename: "udp6",
|
||||
}
|
||||
|
||||
var kindUNIX = netConnectionKindType{
|
||||
family: syscall.AF_UNIX,
|
||||
filename: "unix",
|
||||
|
@ -748,7 +751,6 @@ func parseIPv6HexString(src []byte) (net.IP, error) {
|
|||
}
|
||||
|
||||
func processInet(file string, kind netConnectionKindType, inodes map[string][]inodeMap, filterPid int32) ([]connTmp, error) {
|
||||
|
||||
if strings.HasSuffix(file, "6") && !common.PathExists(file) {
|
||||
// IPv6 not supported, return empty.
|
||||
return []connTmp{}, nil
|
||||
|
@ -872,7 +874,7 @@ func processUnix(file string, kind netConnectionKindType, inodes map[string][]in
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func updateMap(src map[string][]inodeMap, add map[string][]inodeMap) map[string][]inodeMap {
|
||||
func updateMap(src, add map[string][]inodeMap) map[string][]inodeMap {
|
||||
for key, value := range add {
|
||||
a, exists := src[key]
|
||||
if !exists {
|
||||
|
|
|
@ -17,8 +17,9 @@ import (
|
|||
|
||||
var portMatch = regexp.MustCompile(`(.*)\.(\d+)$`)
|
||||
|
||||
func ParseNetstat(output string, mode string,
|
||||
iocs map[string]IOCountersStat) error {
|
||||
func ParseNetstat(output, mode string,
|
||||
iocs map[string]IOCountersStat,
|
||||
) error {
|
||||
lines := strings.Split(output, "\n")
|
||||
|
||||
exists := make([]string, 0, len(lines)-1)
|
||||
|
@ -220,7 +221,7 @@ func parseNetstatLine(line string) (ConnectionStat, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func parseNetstatAddr(local string, remote string, family uint32) (laddr Addr, raddr Addr, err error) {
|
||||
func parseNetstatAddr(local, remote string, family uint32) (laddr, raddr Addr, err error) {
|
||||
parse := func(l string) (Addr, error) {
|
||||
matches := portMatch.FindStringSubmatch(l)
|
||||
if matches == nil {
|
||||
|
@ -299,7 +300,6 @@ func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat,
|
|||
return nil, err
|
||||
}
|
||||
out, err := invoke.CommandWithContext(ctx, netstat, args...)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -80,7 +80,6 @@ func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]C
|
|||
}
|
||||
n, err := parseNetLine(rr)
|
||||
if err != nil {
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -151,7 +150,7 @@ func parseNetLine(line string) (ConnectionStat, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func parseNetAddr(line string) (laddr Addr, raddr Addr, err error) {
|
||||
func parseNetAddr(line string) (laddr, raddr Addr, err error) {
|
||||
parse := func(l string) (Addr, error) {
|
||||
host, port, err := net.SplitHostPort(l)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -44,16 +45,19 @@ var kindTCP4 = netConnectionKindType{
|
|||
sockType: syscall.SOCK_STREAM,
|
||||
filename: "tcp",
|
||||
}
|
||||
|
||||
var kindTCP6 = netConnectionKindType{
|
||||
family: syscall.AF_INET6,
|
||||
sockType: syscall.SOCK_STREAM,
|
||||
filename: "tcp6",
|
||||
}
|
||||
|
||||
var kindUDP4 = netConnectionKindType{
|
||||
family: syscall.AF_INET,
|
||||
sockType: syscall.SOCK_DGRAM,
|
||||
filename: "udp",
|
||||
}
|
||||
|
||||
var kindUDP6 = netConnectionKindType{
|
||||
family: syscall.AF_INET6,
|
||||
sockType: syscall.SOCK_DGRAM,
|
||||
|
@ -525,9 +529,7 @@ func getUDPConnections(family uint32) ([]ConnectionStat, error) {
|
|||
buf = make([]byte, size)
|
||||
}
|
||||
|
||||
var (
|
||||
index, step, length int
|
||||
)
|
||||
var index, step, length int
|
||||
|
||||
stats := make([]ConnectionStat, 0)
|
||||
switch family {
|
||||
|
@ -694,8 +696,10 @@ type mibTCP6TableOwnerPid struct {
|
|||
Table [anySize]mibTCP6RowOwnerPid
|
||||
}
|
||||
|
||||
type pmibTCPTableOwnerPidAll *mibTCPTableOwnerPid
|
||||
type pmibTCP6TableOwnerPidAll *mibTCP6TableOwnerPid
|
||||
type (
|
||||
pmibTCPTableOwnerPidAll *mibTCPTableOwnerPid
|
||||
pmibTCP6TableOwnerPidAll *mibTCP6TableOwnerPid
|
||||
)
|
||||
|
||||
// UDP
|
||||
|
||||
|
@ -750,8 +754,10 @@ type mibUDP6TableOwnerPid struct {
|
|||
Table [anySize]mibUDP6RowOwnerPid
|
||||
}
|
||||
|
||||
type pmibUDPTableOwnerPid *mibUDPTableOwnerPid
|
||||
type pmibUDP6TableOwnerPid *mibUDP6TableOwnerPid
|
||||
type (
|
||||
pmibUDPTableOwnerPid *mibUDPTableOwnerPid
|
||||
pmibUDP6TableOwnerPid *mibUDP6TableOwnerPid
|
||||
)
|
||||
|
||||
func decodePort(port uint32) uint16 {
|
||||
return syscall.Ntohs(uint16(port))
|
||||
|
|
|
@ -64,8 +64,8 @@ type SignalInfoStat struct {
|
|||
|
||||
type RlimitStat struct {
|
||||
Resource int32 `json:"resource"`
|
||||
Soft int32 `json:"soft"` //TODO too small. needs to be uint64
|
||||
Hard int32 `json:"hard"` //TODO too small. needs to be uint64
|
||||
Soft int32 `json:"soft"` // TODO too small. needs to be uint64
|
||||
Hard int32 `json:"hard"` // TODO too small. needs to be uint64
|
||||
Used uint64 `json:"used"`
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,11 @@ import (
|
|||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/cpu"
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/net"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// copied from sys/sysctl.h
|
||||
|
@ -39,11 +40,9 @@ type _Ctype_struct___0 struct {
|
|||
}
|
||||
|
||||
// MemoryInfoExStat is different between OSes
|
||||
type MemoryInfoExStat struct {
|
||||
}
|
||||
type MemoryInfoExStat struct{}
|
||||
|
||||
type MemoryMapsStat struct {
|
||||
}
|
||||
type MemoryMapsStat struct{}
|
||||
|
||||
func pidsWithContext(ctx context.Context) ([]int32, error) {
|
||||
var ret []int32
|
||||
|
@ -81,6 +80,7 @@ func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
|||
|
||||
return int32(v), err
|
||||
}
|
||||
|
||||
func (p *Process) Name() (string, error) {
|
||||
return p.NameWithContext(context.Background())
|
||||
}
|
||||
|
@ -109,9 +109,11 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
|||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func (p *Process) Tgid() (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Exe() (string, error) {
|
||||
return p.ExeWithContext(context.Background())
|
||||
}
|
||||
|
@ -163,7 +165,7 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
|
|||
elapsedDurations = append(elapsedDurations, time.Duration(p))
|
||||
}
|
||||
|
||||
var elapsed = time.Duration(elapsedDurations[0]) * time.Second
|
||||
elapsed := time.Duration(elapsedDurations[0]) * time.Second
|
||||
if len(elapsedDurations) > 1 {
|
||||
elapsed += time.Duration(elapsedDurations[1]) * time.Minute
|
||||
}
|
||||
|
@ -177,6 +179,7 @@ func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
|
|||
start := time.Now().Add(-elapsed)
|
||||
return start.Unix() * 1000, nil
|
||||
}
|
||||
|
||||
func (p *Process) Cwd() (string, error) {
|
||||
return p.CwdWithContext(context.Background())
|
||||
}
|
||||
|
@ -184,6 +187,7 @@ func (p *Process) Cwd() (string, error) {
|
|||
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Parent() (*Process, error) {
|
||||
return p.ParentWithContext(context.Background())
|
||||
}
|
||||
|
@ -206,6 +210,7 @@ func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
|||
}
|
||||
return nil, fmt.Errorf("could not find parent line")
|
||||
}
|
||||
|
||||
func (p *Process) Status() (string, error) {
|
||||
return p.StatusWithContext(context.Background())
|
||||
}
|
||||
|
@ -252,6 +257,7 @@ func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return []int32{userEffectiveUID}, nil
|
||||
}
|
||||
|
||||
func (p *Process) Gids() ([]int32, error) {
|
||||
return p.GidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -281,6 +287,7 @@ func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (p *Process) Terminal() (string, error) {
|
||||
return p.TerminalWithContext(context.Background())
|
||||
}
|
||||
|
@ -302,6 +309,7 @@ func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
|||
return termmap[ttyNr], nil
|
||||
*/
|
||||
}
|
||||
|
||||
func (p *Process) Nice() (int32, error) {
|
||||
return p.NiceWithContext(context.Background())
|
||||
}
|
||||
|
@ -313,6 +321,7 @@ func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
|||
}
|
||||
return int32(k.Proc.P_nice), nil
|
||||
}
|
||||
|
||||
func (p *Process) IOnice() (int32, error) {
|
||||
return p.IOniceWithContext(context.Background())
|
||||
}
|
||||
|
@ -320,6 +329,7 @@ func (p *Process) IOnice() (int32, error) {
|
|||
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||
return p.RlimitWithContext(context.Background())
|
||||
}
|
||||
|
@ -328,6 +338,7 @@ func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
|||
var rlimit []RlimitStat
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
||||
return p.RlimitUsageWithContext(context.Background(), gatherUsed)
|
||||
}
|
||||
|
@ -336,6 +347,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
|
|||
var rlimit []RlimitStat
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||
return p.IOCountersWithContext(context.Background())
|
||||
}
|
||||
|
@ -343,6 +355,7 @@ func (p *Process) IOCounters() (*IOCountersStat, error) {
|
|||
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||
return p.NumCtxSwitchesWithContext(context.Background())
|
||||
}
|
||||
|
@ -350,6 +363,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|||
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumFDs() (int32, error) {
|
||||
return p.NumFDsWithContext(context.Background())
|
||||
}
|
||||
|
@ -357,6 +371,7 @@ func (p *Process) NumFDs() (int32, error) {
|
|||
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumThreads() (int32, error) {
|
||||
return p.NumThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -368,6 +383,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
|||
}
|
||||
return int32(len(r)), nil
|
||||
}
|
||||
|
||||
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||
return p.ThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -422,13 +438,13 @@ func convertCPUTimes(s string) (ret float64, err error) {
|
|||
t += h
|
||||
return float64(t) / ClockTicks, nil
|
||||
}
|
||||
|
||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||
return p.TimesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||
r, err := callPsWithContext(ctx, "utime,stime", p.Pid, false)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -449,6 +465,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
|
|||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||
return p.CPUAffinityWithContext(context.Background())
|
||||
}
|
||||
|
@ -456,6 +473,7 @@ func (p *Process) CPUAffinity() ([]int32, error) {
|
|||
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||
return p.MemoryInfoWithContext(context.Background())
|
||||
}
|
||||
|
@ -486,6 +504,7 @@ func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, e
|
|||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||
return p.MemoryInfoExWithContext(context.Background())
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package process
|
|||
// #include <stdlib.h>
|
||||
// #include <libproc.h>
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
|
|
@ -25,8 +25,7 @@ type MemoryMapsStat struct {
|
|||
Swap uint64 `json:"swap"`
|
||||
}
|
||||
|
||||
type MemoryInfoExStat struct {
|
||||
}
|
||||
type MemoryInfoExStat struct{}
|
||||
|
||||
func pidsWithContext(ctx context.Context) ([]int32, error) {
|
||||
return []int32{}, common.ErrNotImplementedError
|
||||
|
@ -62,6 +61,7 @@ func (p *Process) Ppid() (int32, error) {
|
|||
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Name() (string, error) {
|
||||
return p.NameWithContext(context.Background())
|
||||
}
|
||||
|
@ -69,9 +69,11 @@ func (p *Process) Name() (string, error) {
|
|||
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Tgid() (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Exe() (string, error) {
|
||||
return p.ExeWithContext(context.Background())
|
||||
}
|
||||
|
@ -79,6 +81,7 @@ func (p *Process) Exe() (string, error) {
|
|||
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Cmdline() (string, error) {
|
||||
return p.CmdlineWithContext(context.Background())
|
||||
}
|
||||
|
@ -86,6 +89,7 @@ func (p *Process) Cmdline() (string, error) {
|
|||
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||
return p.CmdlineSliceWithContext(context.Background())
|
||||
}
|
||||
|
@ -97,6 +101,7 @@ func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error)
|
|||
func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Cwd() (string, error) {
|
||||
return p.CwdWithContext(context.Background())
|
||||
}
|
||||
|
@ -104,6 +109,7 @@ func (p *Process) Cwd() (string, error) {
|
|||
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Parent() (*Process, error) {
|
||||
return p.ParentWithContext(context.Background())
|
||||
}
|
||||
|
@ -111,6 +117,7 @@ func (p *Process) Parent() (*Process, error) {
|
|||
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Status() (string, error) {
|
||||
return p.StatusWithContext(context.Background())
|
||||
}
|
||||
|
@ -118,6 +125,7 @@ func (p *Process) Status() (string, error) {
|
|||
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Foreground() (bool, error) {
|
||||
return p.ForegroundWithContext(context.Background())
|
||||
}
|
||||
|
@ -125,6 +133,7 @@ func (p *Process) Foreground() (bool, error) {
|
|||
func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
|
||||
return false, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Uids() ([]int32, error) {
|
||||
return p.UidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -132,6 +141,7 @@ func (p *Process) Uids() ([]int32, error) {
|
|||
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||
return []int32{}, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Gids() ([]int32, error) {
|
||||
return p.GidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -143,6 +153,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
|
||||
return []int32{}, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Terminal() (string, error) {
|
||||
return p.TerminalWithContext(context.Background())
|
||||
}
|
||||
|
@ -150,6 +161,7 @@ func (p *Process) Terminal() (string, error) {
|
|||
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Nice() (int32, error) {
|
||||
return p.NiceWithContext(context.Background())
|
||||
}
|
||||
|
@ -157,6 +169,7 @@ func (p *Process) Nice() (int32, error) {
|
|||
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) IOnice() (int32, error) {
|
||||
return p.IOniceWithContext(context.Background())
|
||||
}
|
||||
|
@ -164,6 +177,7 @@ func (p *Process) IOnice() (int32, error) {
|
|||
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||
return p.RlimitWithContext(context.Background())
|
||||
}
|
||||
|
@ -171,6 +185,7 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
|
|||
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
||||
return p.RlimitUsageWithContext(context.Background(), gatherUsed)
|
||||
}
|
||||
|
@ -178,6 +193,7 @@ func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
|||
func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) ([]RlimitStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||
return p.IOCountersWithContext(context.Background())
|
||||
}
|
||||
|
@ -185,6 +201,7 @@ func (p *Process) IOCounters() (*IOCountersStat, error) {
|
|||
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||
return p.NumCtxSwitchesWithContext(context.Background())
|
||||
}
|
||||
|
@ -192,6 +209,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|||
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumFDs() (int32, error) {
|
||||
return p.NumFDsWithContext(context.Background())
|
||||
}
|
||||
|
@ -199,6 +217,7 @@ func (p *Process) NumFDs() (int32, error) {
|
|||
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumThreads() (int32, error) {
|
||||
return p.NumThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -206,6 +225,7 @@ func (p *Process) NumThreads() (int32, error) {
|
|||
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||
return p.ThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -213,6 +233,7 @@ func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
|||
func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||
return p.TimesWithContext(context.Background())
|
||||
}
|
||||
|
@ -220,6 +241,7 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
|||
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||
return p.CPUAffinityWithContext(context.Background())
|
||||
}
|
||||
|
@ -227,6 +249,7 @@ func (p *Process) CPUAffinity() ([]int32, error) {
|
|||
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||
return p.MemoryInfoWithContext(context.Background())
|
||||
}
|
||||
|
@ -234,6 +257,7 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
|||
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||
return p.MemoryInfoExWithContext(context.Background())
|
||||
}
|
||||
|
@ -241,12 +265,15 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
|||
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) PageFaults() (*PageFaultsStat, error) {
|
||||
return p.PageFaultsWithContext(context.Background())
|
||||
}
|
||||
|
||||
func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Children() ([]*Process, error) {
|
||||
return p.ChildrenWithContext(context.Background())
|
||||
}
|
||||
|
@ -254,6 +281,7 @@ func (p *Process) Children() ([]*Process, error) {
|
|||
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||
return p.OpenFilesWithContext(context.Background())
|
||||
}
|
||||
|
@ -261,6 +289,7 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
|||
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||
return []OpenFilesStat{}, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
||||
return p.ConnectionsWithContext(context.Background())
|
||||
}
|
||||
|
@ -292,6 +321,7 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
|||
func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) SendSignal(sig syscall.Signal) error {
|
||||
return p.SendSignalWithContext(context.Background(), sig)
|
||||
}
|
||||
|
@ -299,6 +329,7 @@ func (p *Process) SendSignal(sig syscall.Signal) error {
|
|||
func (p *Process) SendSignalWithContext(ctx context.Context, sig syscall.Signal) error {
|
||||
return common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Suspend() error {
|
||||
return p.SuspendWithContext(context.Background())
|
||||
}
|
||||
|
@ -306,6 +337,7 @@ func (p *Process) Suspend() error {
|
|||
func (p *Process) SuspendWithContext(ctx context.Context) error {
|
||||
return common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Resume() error {
|
||||
return p.ResumeWithContext(context.Background())
|
||||
}
|
||||
|
@ -313,6 +345,7 @@ func (p *Process) Resume() error {
|
|||
func (p *Process) ResumeWithContext(ctx context.Context) error {
|
||||
return common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Terminate() error {
|
||||
return p.TerminateWithContext(context.Background())
|
||||
}
|
||||
|
@ -320,6 +353,7 @@ func (p *Process) Terminate() error {
|
|||
func (p *Process) TerminateWithContext(ctx context.Context) error {
|
||||
return common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Kill() error {
|
||||
return p.KillWithContext(context.Background())
|
||||
}
|
||||
|
@ -327,6 +361,7 @@ func (p *Process) Kill() error {
|
|||
func (p *Process) KillWithContext(ctx context.Context) error {
|
||||
return common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Username() (string, error) {
|
||||
return p.UsernameWithContext(context.Background())
|
||||
}
|
||||
|
|
|
@ -11,18 +11,17 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
cpu "github.com/gofiber/fiber/v2/internal/gopsutil/cpu"
|
||||
net "github.com/gofiber/fiber/v2/internal/gopsutil/net"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// MemoryInfoExStat is different between OSes
|
||||
type MemoryInfoExStat struct {
|
||||
}
|
||||
type MemoryInfoExStat struct{}
|
||||
|
||||
type MemoryMapsStat struct {
|
||||
}
|
||||
type MemoryMapsStat struct{}
|
||||
|
||||
func pidsWithContext(ctx context.Context) ([]int32, error) {
|
||||
var ret []int32
|
||||
|
@ -50,6 +49,7 @@ func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
|||
|
||||
return k.Ppid, nil
|
||||
}
|
||||
|
||||
func (p *Process) Name() (string, error) {
|
||||
return p.NameWithContext(context.Background())
|
||||
}
|
||||
|
@ -78,9 +78,11 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
|||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func (p *Process) Tgid() (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Exe() (string, error) {
|
||||
return p.ExeWithContext(context.Background())
|
||||
}
|
||||
|
@ -137,6 +139,7 @@ func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error)
|
|||
func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Cwd() (string, error) {
|
||||
return p.CwdWithContext(context.Background())
|
||||
}
|
||||
|
@ -144,6 +147,7 @@ func (p *Process) Cwd() (string, error) {
|
|||
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Parent() (*Process, error) {
|
||||
return p.ParentWithContext(context.Background())
|
||||
}
|
||||
|
@ -151,6 +155,7 @@ func (p *Process) Parent() (*Process, error) {
|
|||
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||
return p, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Status() (string, error) {
|
||||
return p.StatusWithContext(context.Background())
|
||||
}
|
||||
|
@ -215,6 +220,7 @@ func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return uids, nil
|
||||
}
|
||||
|
||||
func (p *Process) Gids() ([]int32, error) {
|
||||
return p.GidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -244,6 +250,7 @@ func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return groups, nil
|
||||
}
|
||||
|
||||
func (p *Process) Terminal() (string, error) {
|
||||
return p.TerminalWithContext(context.Background())
|
||||
}
|
||||
|
@ -263,6 +270,7 @@ func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
|||
|
||||
return termmap[ttyNr], nil
|
||||
}
|
||||
|
||||
func (p *Process) Nice() (int32, error) {
|
||||
return p.NiceWithContext(context.Background())
|
||||
}
|
||||
|
@ -274,6 +282,7 @@ func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
|||
}
|
||||
return int32(k.Nice), nil
|
||||
}
|
||||
|
||||
func (p *Process) IOnice() (int32, error) {
|
||||
return p.IOniceWithContext(context.Background())
|
||||
}
|
||||
|
@ -281,6 +290,7 @@ func (p *Process) IOnice() (int32, error) {
|
|||
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||
return p.RlimitWithContext(context.Background())
|
||||
}
|
||||
|
@ -289,6 +299,7 @@ func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
|||
var rlimit []RlimitStat
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
||||
return p.RlimitUsageWithContext(context.Background(), gatherUsed)
|
||||
}
|
||||
|
@ -297,6 +308,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
|
|||
var rlimit []RlimitStat
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||
return p.IOCountersWithContext(context.Background())
|
||||
}
|
||||
|
@ -311,6 +323,7 @@ func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, e
|
|||
WriteCount: uint64(k.Rusage.Oublock),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||
return p.NumCtxSwitchesWithContext(context.Background())
|
||||
}
|
||||
|
@ -318,6 +331,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|||
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumFDs() (int32, error) {
|
||||
return p.NumFDsWithContext(context.Background())
|
||||
}
|
||||
|
@ -325,6 +339,7 @@ func (p *Process) NumFDs() (int32, error) {
|
|||
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumThreads() (int32, error) {
|
||||
return p.NumThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -337,6 +352,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
|||
|
||||
return k.Numthreads, nil
|
||||
}
|
||||
|
||||
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||
return p.ThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -345,6 +361,7 @@ func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesS
|
|||
ret := make(map[int32]*cpu.TimesStat)
|
||||
return ret, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||
return p.TimesWithContext(context.Background())
|
||||
}
|
||||
|
@ -360,6 +377,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
|
|||
System: float64(k.Rusage.Stime.Sec) + float64(k.Rusage.Stime.Usec)/1000000,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||
return p.CPUAffinityWithContext(context.Background())
|
||||
}
|
||||
|
@ -367,6 +385,7 @@ func (p *Process) CPUAffinity() ([]int32, error) {
|
|||
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||
return p.MemoryInfoWithContext(context.Background())
|
||||
}
|
||||
|
@ -387,6 +406,7 @@ func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, e
|
|||
VMS: uint64(k.Size),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||
return p.MemoryInfoExWithContext(context.Background())
|
||||
}
|
||||
|
|
|
@ -14,10 +14,11 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/cpu"
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/net"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var PageSize = uint64(os.Getpagesize())
|
||||
|
@ -332,7 +333,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
|
|||
case RLIMIT_AS:
|
||||
rs.Used = uint64(p.memInfo.VMS)
|
||||
case RLIMIT_LOCKS:
|
||||
//TODO we can get the used value from /proc/$pid/locks. But linux doesn't enforce it, so not a high priority.
|
||||
// TODO we can get the used value from /proc/$pid/locks. But linux doesn't enforce it, so not a high priority.
|
||||
case RLIMIT_SIGPENDING:
|
||||
rs.Used = p.sigInfo.PendingProcess
|
||||
case RLIMIT_NICE:
|
||||
|
@ -477,7 +478,6 @@ func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, e
|
|||
return nil, err
|
||||
}
|
||||
return pageFaults, nil
|
||||
|
||||
}
|
||||
|
||||
// Children returns a slice of Process of the process.
|
||||
|
@ -571,7 +571,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M
|
|||
lines := strings.Split(string(contents), "\n")
|
||||
|
||||
// function of parsing a block
|
||||
getBlock := func(first_line []string, block []string) (MemoryMapsStat, error) {
|
||||
getBlock := func(first_line, block []string) (MemoryMapsStat, error) {
|
||||
m := MemoryMapsStat{}
|
||||
m.Path = first_line[len(first_line)-1]
|
||||
|
||||
|
@ -703,7 +703,7 @@ func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat,
|
|||
// Remove last item from string
|
||||
str = str[:len(str)-1]
|
||||
|
||||
//Now last item is a Soft limit
|
||||
// Now last item is a Soft limit
|
||||
statItem.Soft, err = limitToInt(str[len(str)-1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -711,7 +711,7 @@ func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat,
|
|||
// Remove last item from string
|
||||
str = str[:len(str)-1]
|
||||
|
||||
//The rest is a stats name
|
||||
// The rest is a stats name
|
||||
resourceName := strings.Join(str, " ")
|
||||
switch resourceName {
|
||||
case "Max cpu time":
|
||||
|
|
|
@ -13,19 +13,18 @@ import (
|
|||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
cpu "github.com/gofiber/fiber/v2/internal/gopsutil/cpu"
|
||||
mem "github.com/gofiber/fiber/v2/internal/gopsutil/mem"
|
||||
net "github.com/gofiber/fiber/v2/internal/gopsutil/net"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// MemoryInfoExStat is different between OSes
|
||||
type MemoryInfoExStat struct {
|
||||
}
|
||||
type MemoryInfoExStat struct{}
|
||||
|
||||
type MemoryMapsStat struct {
|
||||
}
|
||||
type MemoryMapsStat struct{}
|
||||
|
||||
func pidsWithContext(ctx context.Context) ([]int32, error) {
|
||||
var ret []int32
|
||||
|
@ -53,6 +52,7 @@ func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
|||
|
||||
return k.Ppid, nil
|
||||
}
|
||||
|
||||
func (p *Process) Name() (string, error) {
|
||||
return p.NameWithContext(context.Background())
|
||||
}
|
||||
|
@ -81,9 +81,11 @@ func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
|||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
func (p *Process) Tgid() (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Exe() (string, error) {
|
||||
return p.ExeWithContext(context.Background())
|
||||
}
|
||||
|
@ -99,7 +101,6 @@ func (p *Process) CmdlineSlice() ([]string, error) {
|
|||
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||
mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv}
|
||||
buf, _, err := common.CallSyscall(mib)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -134,6 +135,7 @@ func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
|||
func (p *Process) createTimeWithContext(ctx context.Context) (int64, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Cwd() (string, error) {
|
||||
return p.CwdWithContext(context.Background())
|
||||
}
|
||||
|
@ -141,6 +143,7 @@ func (p *Process) Cwd() (string, error) {
|
|||
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Parent() (*Process, error) {
|
||||
return p.ParentWithContext(context.Background())
|
||||
}
|
||||
|
@ -148,6 +151,7 @@ func (p *Process) Parent() (*Process, error) {
|
|||
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||
return p, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Status() (string, error) {
|
||||
return p.StatusWithContext(context.Background())
|
||||
}
|
||||
|
@ -173,6 +177,7 @@ func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
|||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (p *Process) Foreground() (bool, error) {
|
||||
return p.ForegroundWithContext(context.Background())
|
||||
}
|
||||
|
@ -190,6 +195,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) {
|
|||
}
|
||||
return strings.IndexByte(string(out), '+') != -1, nil
|
||||
}
|
||||
|
||||
func (p *Process) Uids() ([]int32, error) {
|
||||
return p.UidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -206,6 +212,7 @@ func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return uids, nil
|
||||
}
|
||||
|
||||
func (p *Process) Gids() ([]int32, error) {
|
||||
return p.GidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -221,6 +228,7 @@ func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return gids, nil
|
||||
}
|
||||
|
||||
func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
|
||||
k, err := p.getKProc()
|
||||
if err != nil {
|
||||
|
@ -229,6 +237,7 @@ func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return k.Groups, nil
|
||||
}
|
||||
|
||||
func (p *Process) Terminal() (string, error) {
|
||||
return p.TerminalWithContext(context.Background())
|
||||
}
|
||||
|
@ -248,6 +257,7 @@ func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
|||
|
||||
return termmap[ttyNr], nil
|
||||
}
|
||||
|
||||
func (p *Process) Nice() (int32, error) {
|
||||
return p.NiceWithContext(context.Background())
|
||||
}
|
||||
|
@ -259,6 +269,7 @@ func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
|||
}
|
||||
return int32(k.Nice), nil
|
||||
}
|
||||
|
||||
func (p *Process) IOnice() (int32, error) {
|
||||
return p.IOniceWithContext(context.Background())
|
||||
}
|
||||
|
@ -266,6 +277,7 @@ func (p *Process) IOnice() (int32, error) {
|
|||
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||
return p.RlimitWithContext(context.Background())
|
||||
}
|
||||
|
@ -274,6 +286,7 @@ func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
|||
var rlimit []RlimitStat
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
||||
return p.RlimitUsageWithContext(context.Background(), gatherUsed)
|
||||
}
|
||||
|
@ -282,6 +295,7 @@ func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) (
|
|||
var rlimit []RlimitStat
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||
return p.IOCountersWithContext(context.Background())
|
||||
}
|
||||
|
@ -296,6 +310,7 @@ func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, e
|
|||
WriteCount: uint64(k.Uru_oublock),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||
return p.NumCtxSwitchesWithContext(context.Background())
|
||||
}
|
||||
|
@ -303,6 +318,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|||
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumFDs() (int32, error) {
|
||||
return p.NumFDsWithContext(context.Background())
|
||||
}
|
||||
|
@ -310,6 +326,7 @@ func (p *Process) NumFDs() (int32, error) {
|
|||
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumThreads() (int32, error) {
|
||||
return p.NumThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -318,6 +335,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
|||
/* not supported, just return 1 */
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||
return p.ThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -326,6 +344,7 @@ func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesS
|
|||
ret := make(map[int32]*cpu.TimesStat)
|
||||
return ret, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||
return p.TimesWithContext(context.Background())
|
||||
}
|
||||
|
@ -341,6 +360,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
|
|||
System: float64(k.Ustime_sec) + float64(k.Ustime_usec)/1000000,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||
return p.CPUAffinityWithContext(context.Background())
|
||||
}
|
||||
|
@ -348,6 +368,7 @@ func (p *Process) CPUAffinity() ([]int32, error) {
|
|||
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||
return p.MemoryInfoWithContext(context.Background())
|
||||
}
|
||||
|
@ -368,6 +389,7 @@ func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, e
|
|||
uint64(k.Vm_ssize),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||
return p.MemoryInfoExWithContext(context.Background())
|
||||
}
|
||||
|
@ -453,7 +475,6 @@ func ProcessesWithContext(ctx context.Context) ([]*Process, error) {
|
|||
results := []*Process{}
|
||||
|
||||
buf, length, err := CallKernProcSyscall(KernProcAll, 0)
|
||||
|
||||
if err != nil {
|
||||
return results, err
|
||||
}
|
||||
|
@ -506,11 +527,11 @@ func (p *Process) getKProcWithContext(ctx context.Context) (*KinfoProc, error) {
|
|||
return &k, nil
|
||||
}
|
||||
|
||||
func CallKernProcSyscall(op int32, arg int32) ([]byte, uint64, error) {
|
||||
func CallKernProcSyscall(op, arg int32) ([]byte, uint64, error) {
|
||||
return CallKernProcSyscallWithContext(context.Background(), op, arg)
|
||||
}
|
||||
|
||||
func CallKernProcSyscallWithContext(ctx context.Context, op int32, arg int32) ([]byte, uint64, error) {
|
||||
func CallKernProcSyscallWithContext(ctx context.Context, op, arg int32) ([]byte, uint64, error) {
|
||||
mib := []int32{CTLKern, KernProc, op, arg, sizeOfKinfoProc, 0}
|
||||
mibptr := unsafe.Pointer(&mib[0])
|
||||
miblen := uint64(len(mib))
|
||||
|
|
|
@ -14,8 +14,9 @@ import (
|
|||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
)
|
||||
|
||||
// POSIX
|
||||
|
@ -82,7 +83,7 @@ func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(common.HostProc()); err == nil { //Means that proc filesystem exist
|
||||
if _, err := os.Stat(common.HostProc()); err == nil { // Means that proc filesystem exist
|
||||
// Checking PID existence based on existence of /<HOST_PROC>/proc/<PID> folder
|
||||
// This covers the case when running inside container with a different process namespace (by default)
|
||||
|
||||
|
|
|
@ -11,10 +11,11 @@ import (
|
|||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/gofiber/fiber/v2/internal/gopsutil/common"
|
||||
cpu "github.com/gofiber/fiber/v2/internal/gopsutil/cpu"
|
||||
net "github.com/gofiber/fiber/v2/internal/gopsutil/net"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -76,11 +77,9 @@ type systemInfo struct {
|
|||
}
|
||||
|
||||
// Memory_info_ex is different between OSes
|
||||
type MemoryInfoExStat struct {
|
||||
}
|
||||
type MemoryInfoExStat struct{}
|
||||
|
||||
type MemoryMapsStat struct {
|
||||
}
|
||||
type MemoryMapsStat struct{}
|
||||
|
||||
// ioCounters is an equivalent representation of IO_COUNTERS in the Windows API.
|
||||
// https://docs.microsoft.com/windows/win32/api/winnt/ns-winnt-io_counters
|
||||
|
@ -128,8 +127,10 @@ type winTokenPriviledges struct {
|
|||
Privileges [1]winLUIDAndAttributes
|
||||
}
|
||||
|
||||
type winLong int32
|
||||
type winDWord uint32
|
||||
type (
|
||||
winLong int32
|
||||
winDWord uint32
|
||||
)
|
||||
|
||||
func init() {
|
||||
var systemInfo systemInfo
|
||||
|
@ -194,7 +195,6 @@ func pidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
|
||||
|
@ -337,6 +337,7 @@ func (p *Process) Cwd() (string, error) {
|
|||
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Parent() (*Process, error) {
|
||||
return p.ParentWithContext(context.Background())
|
||||
}
|
||||
|
@ -349,6 +350,7 @@ func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
|||
|
||||
return NewProcess(ppid)
|
||||
}
|
||||
|
||||
func (p *Process) Status() (string, error) {
|
||||
return p.StatusWithContext(context.Background())
|
||||
}
|
||||
|
@ -401,6 +403,7 @@ func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
|||
|
||||
return uids, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Gids() ([]int32, error) {
|
||||
return p.GidsWithContext(context.Background())
|
||||
}
|
||||
|
@ -414,6 +417,7 @@ func (p *Process) GroupsWithContext(ctx context.Context) ([]int32, error) {
|
|||
var groups []int32
|
||||
return groups, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Terminal() (string, error) {
|
||||
return p.TerminalWithContext(context.Background())
|
||||
}
|
||||
|
@ -455,6 +459,7 @@ func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
|||
}
|
||||
return priority, nil
|
||||
}
|
||||
|
||||
func (p *Process) IOnice() (int32, error) {
|
||||
return p.IOniceWithContext(context.Background())
|
||||
}
|
||||
|
@ -462,6 +467,7 @@ func (p *Process) IOnice() (int32, error) {
|
|||
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||
return p.RlimitWithContext(context.Background())
|
||||
}
|
||||
|
@ -471,6 +477,7 @@ func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
|||
|
||||
return rlimit, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
||||
return p.RlimitUsageWithContext(context.Background(), gatherUsed)
|
||||
}
|
||||
|
@ -505,6 +512,7 @@ func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, e
|
|||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||
return p.NumCtxSwitchesWithContext(context.Background())
|
||||
}
|
||||
|
@ -512,6 +520,7 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|||
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumFDs() (int32, error) {
|
||||
return p.NumFDsWithContext(context.Background())
|
||||
}
|
||||
|
@ -519,6 +528,7 @@ func (p *Process) NumFDs() (int32, error) {
|
|||
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||
return 0, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) NumThreads() (int32, error) {
|
||||
return p.NumThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -530,6 +540,7 @@ func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
|||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||
return p.ThreadsWithContext(context.Background())
|
||||
}
|
||||
|
@ -538,6 +549,7 @@ func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesS
|
|||
ret := make(map[int32]*cpu.TimesStat)
|
||||
return ret, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||
return p.TimesWithContext(context.Background())
|
||||
}
|
||||
|
@ -565,6 +577,7 @@ func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)
|
|||
System: kernel,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||
return p.CPUAffinityWithContext(context.Background())
|
||||
}
|
||||
|
@ -572,6 +585,7 @@ func (p *Process) CPUAffinity() ([]int32, error) {
|
|||
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||
return p.MemoryInfoWithContext(context.Background())
|
||||
}
|
||||
|
@ -589,6 +603,7 @@ func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, e
|
|||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||
return p.MemoryInfoExWithContext(context.Background())
|
||||
}
|
||||
|
@ -878,7 +893,7 @@ func is32BitProcess(procHandle syscall.Handle) bool {
|
|||
return true
|
||||
}
|
||||
} else {
|
||||
//if the OS does not support the call, we fallback into the bitness of the app
|
||||
// if the OS does not support the call, we fallback into the bitness of the app
|
||||
if unsafe.Sizeof(wow64) == 4 {
|
||||
return true
|
||||
}
|
||||
|
@ -919,7 +934,7 @@ func getProcessCommandLine(pid int32) (string, error) {
|
|||
procIs32Bits = is32BitProcess(syscall.Handle(h))
|
||||
|
||||
default:
|
||||
//for other unknown platforms, we rely on process platform
|
||||
// for other unknown platforms, we rely on process platform
|
||||
if unsafe.Sizeof(processorArchitecture) == 8 {
|
||||
procIs32Bits = false
|
||||
}
|
||||
|
@ -937,17 +952,17 @@ func getProcessCommandLine(pid int32) (string, error) {
|
|||
}
|
||||
userProcParams := uint64(buf[0]) | (uint64(buf[1]) << 8) | (uint64(buf[2]) << 16) | (uint64(buf[3]) << 24)
|
||||
|
||||
//read CommandLine field from PRTL_USER_PROCESS_PARAMETERS
|
||||
// read CommandLine field from PRTL_USER_PROCESS_PARAMETERS
|
||||
remoteCmdLine := readProcessMemory(syscall.Handle(h), procIs32Bits, userProcParams+uint64(64), 8)
|
||||
if len(remoteCmdLine) != 8 {
|
||||
return "", errors.New("cannot read cmdline field")
|
||||
}
|
||||
|
||||
//remoteCmdLine is actually a UNICODE_STRING32
|
||||
//the first two bytes has the length
|
||||
// remoteCmdLine is actually a UNICODE_STRING32
|
||||
// the first two bytes has the length
|
||||
cmdLineLength := uint(remoteCmdLine[0]) | (uint(remoteCmdLine[1]) << 8)
|
||||
if cmdLineLength > 0 {
|
||||
//and, at offset 4, is the pointer to the buffer
|
||||
// and, at offset 4, is the pointer to the buffer
|
||||
bufferAddress := uint32(remoteCmdLine[4]) | (uint32(remoteCmdLine[5]) << 8) |
|
||||
(uint32(remoteCmdLine[6]) << 16) | (uint32(remoteCmdLine[7]) << 24)
|
||||
|
||||
|
@ -966,17 +981,17 @@ func getProcessCommandLine(pid int32) (string, error) {
|
|||
userProcParams := uint64(buf[0]) | (uint64(buf[1]) << 8) | (uint64(buf[2]) << 16) | (uint64(buf[3]) << 24) |
|
||||
(uint64(buf[4]) << 32) | (uint64(buf[5]) << 40) | (uint64(buf[6]) << 48) | (uint64(buf[7]) << 56)
|
||||
|
||||
//read CommandLine field from PRTL_USER_PROCESS_PARAMETERS
|
||||
// read CommandLine field from PRTL_USER_PROCESS_PARAMETERS
|
||||
remoteCmdLine := readProcessMemory(syscall.Handle(h), procIs32Bits, userProcParams+uint64(112), 16)
|
||||
if len(remoteCmdLine) != 16 {
|
||||
return "", errors.New("cannot read cmdline field")
|
||||
}
|
||||
|
||||
//remoteCmdLine is actually a UNICODE_STRING64
|
||||
//the first two bytes has the length
|
||||
// remoteCmdLine is actually a UNICODE_STRING64
|
||||
// the first two bytes has the length
|
||||
cmdLineLength := uint(remoteCmdLine[0]) | (uint(remoteCmdLine[1]) << 8)
|
||||
if cmdLineLength > 0 {
|
||||
//and, at offset 8, is the pointer to the buffer
|
||||
// and, at offset 8, is the pointer to the buffer
|
||||
bufferAddress := uint64(remoteCmdLine[8]) | (uint64(remoteCmdLine[9]) << 8) |
|
||||
(uint64(remoteCmdLine[10]) << 16) | (uint64(remoteCmdLine[11]) << 24) |
|
||||
(uint64(remoteCmdLine[12]) << 32) | (uint64(remoteCmdLine[13]) << 40) |
|
||||
|
@ -991,7 +1006,7 @@ func getProcessCommandLine(pid int32) (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
//if we reach here, we have no command line
|
||||
// if we reach here, we have no command line
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ type PROCESS_MEMORY_COUNTERS struct {
|
|||
|
||||
func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) uint64 {
|
||||
if is32BitProcess {
|
||||
//we are on a 32-bit process reading an external 32-bit process
|
||||
// we are on a 32-bit process reading an external 32-bit process
|
||||
var info processBasicInformation32
|
||||
|
||||
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
|
||||
|
@ -38,8 +38,8 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) uint64 {
|
|||
return uint64(info.PebBaseAddress)
|
||||
}
|
||||
} else {
|
||||
//we are on a 32-bit process reading an external 64-bit process
|
||||
if common.ProcNtWow64QueryInformationProcess64.Find() == nil { //avoid panic
|
||||
// we are on a 32-bit process reading an external 64-bit process
|
||||
if common.ProcNtWow64QueryInformationProcess64.Find() == nil { // avoid panic
|
||||
var info processBasicInformation64
|
||||
|
||||
ret, _, _ := common.ProcNtWow64QueryInformationProcess64.Call(
|
||||
|
@ -55,7 +55,7 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) uint64 {
|
|||
}
|
||||
}
|
||||
|
||||
//return 0 on error
|
||||
// return 0 on error
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -76,19 +76,19 @@ func readProcessMemory(h syscall.Handle, is32BitProcess bool, address uint64, si
|
|||
return buffer[:read]
|
||||
}
|
||||
} else {
|
||||
//reading a 64-bit process from a 32-bit one
|
||||
if common.ProcNtWow64ReadVirtualMemory64.Find() == nil { //avoid panic
|
||||
// reading a 64-bit process from a 32-bit one
|
||||
if common.ProcNtWow64ReadVirtualMemory64.Find() == nil { // avoid panic
|
||||
var read uint64
|
||||
|
||||
buffer := make([]byte, size)
|
||||
|
||||
ret, _, _ := common.ProcNtWow64ReadVirtualMemory64.Call(
|
||||
uintptr(h),
|
||||
uintptr(address&0xFFFFFFFF), //the call expects a 64-bit value
|
||||
uintptr(address&0xFFFFFFFF), // the call expects a 64-bit value
|
||||
uintptr(address>>32),
|
||||
uintptr(unsafe.Pointer(&buffer[0])),
|
||||
uintptr(size), //the call expects a 64-bit value
|
||||
uintptr(0), //but size is 32-bit so pass zero as the high dword
|
||||
uintptr(size), // the call expects a 64-bit value
|
||||
uintptr(0), // but size is 32-bit so pass zero as the high dword
|
||||
uintptr(unsafe.Pointer(&read)),
|
||||
)
|
||||
if int(ret) >= 0 && read > 0 {
|
||||
|
@ -97,6 +97,6 @@ func readProcessMemory(h syscall.Handle, is32BitProcess bool, address uint64, si
|
|||
}
|
||||
}
|
||||
|
||||
//if we reach here, an error happened
|
||||
// if we reach here, an error happened
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ type PROCESS_MEMORY_COUNTERS struct {
|
|||
|
||||
func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) uint64 {
|
||||
if is32BitProcess {
|
||||
//we are on a 64-bit process reading an external 32-bit process
|
||||
// we are on a 64-bit process reading an external 32-bit process
|
||||
var wow64 uint
|
||||
|
||||
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
|
||||
|
@ -38,7 +38,7 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) uint64 {
|
|||
return uint64(wow64)
|
||||
}
|
||||
} else {
|
||||
//we are on a 64-bit process reading an external 64-bit process
|
||||
// we are on a 64-bit process reading an external 64-bit process
|
||||
var info processBasicInformation64
|
||||
|
||||
ret, _, _ := common.ProcNtQueryInformationProcess.Call(
|
||||
|
@ -53,7 +53,7 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) uint64 {
|
|||
}
|
||||
}
|
||||
|
||||
//return 0 on error
|
||||
// return 0 on error
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -153,9 +153,11 @@ type Posix_cred C.struct_posix_cred
|
|||
|
||||
type Label C.struct_label
|
||||
|
||||
type AuditinfoAddr C.struct_auditinfo_addr
|
||||
type AuMask C.struct_au_mask
|
||||
type AuTidAddr C.struct_au_tid_addr
|
||||
type (
|
||||
AuditinfoAddr C.struct_auditinfo_addr
|
||||
AuMask C.struct_au_mask
|
||||
AuTidAddr C.struct_au_tid_addr
|
||||
)
|
||||
|
||||
// TAILQ(ucred)
|
||||
type UcredQueue C.struct_ucred_queue
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
func Test_Memory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var store = New()
|
||||
store := New()
|
||||
var (
|
||||
key = "john"
|
||||
val interface{} = []byte("doe")
|
||||
|
@ -75,7 +75,6 @@ func Benchmark_Memory(b *testing.B) {
|
|||
}
|
||||
for _, key := range keys {
|
||||
d.Delete(key)
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -64,9 +64,7 @@ func Test_Storage_Memory_Set_Expiration(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_Storage_Memory_Get_Expired(t *testing.T) {
|
||||
var (
|
||||
key = "john"
|
||||
)
|
||||
key := "john"
|
||||
|
||||
result, err := testStore.Get(key)
|
||||
utils.AssertEqual(t, nil, err)
|
||||
|
@ -101,9 +99,7 @@ func Test_Storage_Memory_Delete(t *testing.T) {
|
|||
|
||||
func Test_Storage_Memory_Reset(t *testing.T) {
|
||||
t.Parallel()
|
||||
var (
|
||||
val = []byte("doe")
|
||||
)
|
||||
val := []byte("doe")
|
||||
|
||||
err := testStore.Set("john1", val, 0)
|
||||
utils.AssertEqual(t, nil, err)
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
|
||||
// SWbemServices is used to access wmi. See https://msdn.microsoft.com/en-us/library/aa393719(v=vs.85).aspx
|
||||
type SWbemServices struct {
|
||||
//TODO: track namespace. Not sure if we can re connect to a different namespace using the same instance
|
||||
cWMIClient *Client //This could also be an embedded struct, but then we would need to branch on Client vs SWbemServices in the Query method
|
||||
// TODO: track namespace. Not sure if we can re connect to a different namespace using the same instance
|
||||
cWMIClient *Client // This could also be an embedded struct, but then we would need to branch on Client vs SWbemServices in the Query method
|
||||
sWbemLocatorIUnknown *ole.IUnknown
|
||||
sWbemLocatorIDispatch *ole.IDispatch
|
||||
queries chan *queryRequest
|
||||
|
@ -33,8 +33,8 @@ type queryRequest struct {
|
|||
|
||||
// InitializeSWbemServices will return a new SWbemServices object that can be used to query WMI
|
||||
func InitializeSWbemServices(c *Client, connectServerArgs ...interface{}) (*SWbemServices, error) {
|
||||
//fmt.Println("InitializeSWbemServices: Starting")
|
||||
//TODO: implement connectServerArgs as optional argument for init with connectServer call
|
||||
// fmt.Println("InitializeSWbemServices: Starting")
|
||||
// TODO: implement connectServerArgs as optional argument for init with connectServer call
|
||||
s := new(SWbemServices)
|
||||
s.cWMIClient = c
|
||||
s.queries = make(chan *queryRequest)
|
||||
|
@ -43,9 +43,9 @@ func InitializeSWbemServices(c *Client, connectServerArgs ...interface{}) (*SWbe
|
|||
|
||||
err, ok := <-initError
|
||||
if ok {
|
||||
return nil, err //Send error to caller
|
||||
return nil, err // Send error to caller
|
||||
}
|
||||
//fmt.Println("InitializeSWbemServices: Finished")
|
||||
// fmt.Println("InitializeSWbemServices: Finished")
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
@ -60,23 +60,23 @@ func (s *SWbemServices) Close() error {
|
|||
s.lQueryorClose.Unlock()
|
||||
return fmt.Errorf("SWbemServices has been closed")
|
||||
}
|
||||
//fmt.Println("Close: sending close request")
|
||||
// fmt.Println("Close: sending close request")
|
||||
var result error
|
||||
ce := make(chan error)
|
||||
s.closeError = ce //Race condition if multiple callers to close. May need to lock here
|
||||
close(s.queries) //Tell background to shut things down
|
||||
s.closeError = ce // Race condition if multiple callers to close. May need to lock here
|
||||
close(s.queries) // Tell background to shut things down
|
||||
s.lQueryorClose.Unlock()
|
||||
err, ok := <-ce
|
||||
if ok {
|
||||
result = err
|
||||
}
|
||||
//fmt.Println("Close: finished")
|
||||
// fmt.Println("Close: finished")
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *SWbemServices) process(initError chan error) {
|
||||
//fmt.Println("process: starting background thread initialization")
|
||||
//All OLE/WMI calls must happen on the same initialized thead, so lock this goroutine
|
||||
// fmt.Println("process: starting background thread initialization")
|
||||
// All OLE/WMI calls must happen on the same initialized thead, so lock this goroutine
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
|
@ -110,22 +110,22 @@ func (s *SWbemServices) process(initError chan error) {
|
|||
s.sWbemLocatorIDispatch = dispatch
|
||||
|
||||
// we can't do the ConnectServer call outside the loop unless we find a way to track and re-init the connectServerArgs
|
||||
//fmt.Println("process: initialized. closing initError")
|
||||
// fmt.Println("process: initialized. closing initError")
|
||||
close(initError)
|
||||
//fmt.Println("process: waiting for queries")
|
||||
// fmt.Println("process: waiting for queries")
|
||||
for q := range s.queries {
|
||||
//fmt.Printf("process: new query: len(query)=%d\n", len(q.query))
|
||||
// fmt.Printf("process: new query: len(query)=%d\n", len(q.query))
|
||||
errQuery := s.queryBackground(q)
|
||||
//fmt.Println("process: s.queryBackground finished")
|
||||
// fmt.Println("process: s.queryBackground finished")
|
||||
if errQuery != nil {
|
||||
q.finished <- errQuery
|
||||
}
|
||||
close(q.finished)
|
||||
}
|
||||
//fmt.Println("process: queries channel closed")
|
||||
s.queries = nil //set channel to nil so we know it is closed
|
||||
//TODO: I think the Release/Clear calls can panic if things are in a bad state.
|
||||
//TODO: May need to recover from panics and send error to method caller instead.
|
||||
// fmt.Println("process: queries channel closed")
|
||||
s.queries = nil // set channel to nil so we know it is closed
|
||||
// TODO: I think the Release/Clear calls can panic if things are in a bad state.
|
||||
// TODO: May need to recover from panics and send error to method caller instead.
|
||||
close(s.closeError)
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ func (s *SWbemServices) Query(query string, dst interface{}, connectServerArgs .
|
|||
return fmt.Errorf("SWbemServices has been closed")
|
||||
}
|
||||
|
||||
//fmt.Println("Query: Sending query request")
|
||||
// fmt.Println("Query: Sending query request")
|
||||
qr := queryRequest{
|
||||
query: query,
|
||||
dst: dst,
|
||||
|
@ -161,10 +161,10 @@ func (s *SWbemServices) Query(query string, dst interface{}, connectServerArgs .
|
|||
s.lQueryorClose.Unlock()
|
||||
err, ok := <-qr.finished
|
||||
if ok {
|
||||
//fmt.Println("Query: Finished with error")
|
||||
return err //Send error to caller
|
||||
// fmt.Println("Query: Finished with error")
|
||||
return err // Send error to caller
|
||||
}
|
||||
//fmt.Println("Query: Finished")
|
||||
// fmt.Println("Query: Finished")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -172,8 +172,8 @@ func (s *SWbemServices) queryBackground(q *queryRequest) error {
|
|||
if s == nil || s.sWbemLocatorIDispatch == nil {
|
||||
return fmt.Errorf("SWbemServices is not Initialized")
|
||||
}
|
||||
wmi := s.sWbemLocatorIDispatch //Should just rename in the code, but this will help as we break things apart
|
||||
//fmt.Println("queryBackground: Starting")
|
||||
wmi := s.sWbemLocatorIDispatch // Should just rename in the code, but this will help as we break things apart
|
||||
// fmt.Println("queryBackground: Starting")
|
||||
|
||||
dv := reflect.ValueOf(q.dst)
|
||||
if dv.Kind() != reflect.Ptr || dv.IsNil() {
|
||||
|
@ -256,6 +256,6 @@ func (s *SWbemServices) queryBackground(q *queryRequest) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
//fmt.Println("queryBackground: Finished")
|
||||
// fmt.Println("queryBackground: Finished")
|
||||
return errFieldMismatch
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat
|
|||
}
|
||||
defer prop.Clear()
|
||||
|
||||
if prop.VT == 0x1 { //VT_NULL
|
||||
if prop.VT == 0x1 { // VT_NULL
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,11 @@ import (
|
|||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/mattn/go-runewidth"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -7,10 +7,11 @@ import (
|
|||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
"github.com/valyala/fasthttp"
|
||||
"github.com/valyala/fasthttp/fasthttpadaptor"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
)
|
||||
|
||||
// HTTPHandlerFunc wraps net/http handler func to fiber handler
|
||||
|
|
|
@ -12,9 +12,10 @@ import (
|
|||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func Test_HTTPHandler(t *testing.T) {
|
||||
|
|
3
path.go
3
path.go
|
@ -13,8 +13,9 @@ import (
|
|||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/gofiber/fiber/v2/utils"
|
||||
)
|
||||
|
||||
// routeParser holds the path segments and param names
|
||||
|
|
|
@ -12,8 +12,9 @@ import (
|
|||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
"github.com/valyala/fasthttp/reuseport"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in New Issue