mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: exporting hardware resources usage from api.rest
This commit is contained in:
parent
973c88fd31
commit
ee809b6083
1 changed files with 26 additions and 4 deletions
|
@ -35,11 +35,21 @@ type ifaceJSON struct {
|
|||
Addresses []addrJSON `json:"addresses"`
|
||||
}
|
||||
|
||||
type resourcesJSON struct {
|
||||
NumCPU int `json:"cpus"`
|
||||
MaxCPU int `json:"max_cpus"`
|
||||
NumGoroutine int `json:"goroutines"`
|
||||
Alloc uint64 `json:"alloc"`
|
||||
Sys uint64 `json:"sys"`
|
||||
NumGC uint32 `json:"gcs"`
|
||||
}
|
||||
|
||||
type SessionJSON struct {
|
||||
Version string `json:"version"`
|
||||
OS string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
GoVersion string `json:"goversion"`
|
||||
Resources resourcesJSON `json:"resources"`
|
||||
Interfaces []ifaceJSON `json:"interfaces"`
|
||||
Options core.Options `json:"options"`
|
||||
Interface *network.Endpoint `json:"interface"`
|
||||
|
@ -59,11 +69,23 @@ type SessionJSON struct {
|
|||
}
|
||||
|
||||
func (s *Session) MarshalJSON() ([]byte, error) {
|
||||
var m runtime.MemStats
|
||||
|
||||
runtime.ReadMemStats(&m)
|
||||
|
||||
doc := SessionJSON{
|
||||
Version: core.Version,
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
GoVersion: runtime.Version(),
|
||||
Version: core.Version,
|
||||
OS: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
GoVersion: runtime.Version(),
|
||||
Resources: resourcesJSON{
|
||||
NumCPU: runtime.NumCPU(),
|
||||
MaxCPU: runtime.GOMAXPROCS(0),
|
||||
NumGoroutine: runtime.NumGoroutine(),
|
||||
Alloc: m.Alloc,
|
||||
Sys: m.Sys,
|
||||
NumGC: m.NumGC,
|
||||
},
|
||||
Interfaces: make([]ifaceJSON, 0),
|
||||
Options: s.Options,
|
||||
Interface: s.Interface,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue