-
Notifications
You must be signed in to change notification settings - Fork 388
/
sysutil.go
54 lines (44 loc) · 1.31 KB
/
sysutil.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package sysutil
import (
"os"
"runtime"
"syscall"
"go.uber.org/multierr"
"moul.io/openfiles"
"berty.tech/berty/v2/go/pkg/bertyversion"
"berty.tech/berty/v2/go/pkg/protocoltypes"
"berty.tech/berty/v2/go/pkg/username"
)
func SystemInfoProcess() (*protocoltypes.SystemInfo_Process, error) {
var errs error
// openfiles
nofile, nofileErr := openfiles.Count()
errs = multierr.Append(errs, nofileErr)
// hostname
hn, err := os.Hostname()
errs = multierr.Append(errs, err)
// working dir
wd, err := syscall.Getwd()
errs = multierr.Append(errs, err)
reply := protocoltypes.SystemInfo_Process{
Nofile: nofile,
TooManyOpenFiles: openfiles.IsTooManyError(nofileErr),
NumCPU: int64(runtime.NumCPU()),
GoVersion: runtime.Version(),
HostName: hn,
NumGoroutine: int64(runtime.NumGoroutine()),
OperatingSystem: runtime.GOOS,
Arch: runtime.GOARCH,
Version: bertyversion.Version,
VcsRef: bertyversion.VcsRef,
PID: int64(syscall.Getpid()),
UID: int64(syscall.Getuid()),
PPID: int64(syscall.Getppid()),
WorkingDir: wd,
SystemUsername: username.GetUsername(),
}
// see sysutil_<OS>.go files
err = appendCustomSystemInfo(&reply)
errs = multierr.Append(errs, err)
return &reply, errs
}