-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.go
133 lines (122 loc) · 4.26 KB
/
system.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package directadmin
import (
"fmt"
"net/http"
"time"
)
type SysInfo struct {
CpuCount int `json:"cpuCount" yaml:"cpuCount"`
Cpus map[string]struct {
MHz float64 `json:"mhz"`
Model string `json:"model"`
Vendor string `json:"vendor"`
}
SystemLoad struct {
Last1Minute string `json:"last1Minute"`
Last5Minutes string `json:"last5Minutes"`
Last15Minutes string `json:"last15Minutes"`
} `json:"systemLoad"`
MemInfo struct {
Active int `json:"active"`
ActiveAnon int `json:"activeAnon"`
ActiveFile int `json:"activeFile"`
AnonHugePages int `json:"anonHugePages"`
AnonPages int `json:"anonPages"`
Bounce int `json:"bounce"`
Buffers int `json:"buffers"`
Cached int `json:"cached"`
CommitLimit int `json:"commitLimit"`
CommittedAS int `json:"committedAs"`
DirectMap1G int `json:"directMap1G"`
DirectMap2M int `json:"directMap2M"`
DirectMap4K int `json:"directMap4K"`
Dirty int `json:"Dirty"`
FileHugePages int `json:"fileHugePages"`
FilePmdMapped int `json:"filePmdMapped"`
HardwareCorrupted int `json:"hardwareCorrupted"`
HugePagesFree int `json:"hugePagesFree"`
HugePagesRsvd int `json:"hugePagesRsvd"`
HugePagesSurp int `json:"hugePagesSurp"`
HugePagesTotal int `json:"hugePagesTotal"`
HugePageSize int `json:"hugePageSize"`
HugeTlb int `json:"hugeTlb"`
Inactive int `json:"inactive"`
InactiveAnon int `json:"inactiveAnon"`
InactiveFile int `json:"inactiveFile"`
KReclaimable int `json:"kReclaimable"`
KernelStack int `json:"kernelStack"`
Mapped int `json:"mapped"`
MemAvailable int `json:"memAvailable"`
MemFree int `json:"memFree"`
MemTotal int `json:"memTotal"`
MLocked int `json:"mLocked"`
NfsUnstable int `json:"nfsUnstable"`
PageTables int `json:"pageTables"`
PerCpu int `json:"perCpu"`
SReclaimable int `json:"sReclaimable"`
SUnreclaim int `json:"sUnreclaim"`
Shmem int `json:"shmem"`
ShmemHugePages int `json:"shmemHugePages"`
ShmemPmdMapped int `json:"shmemPmdMapped"`
Slab int `json:"slab"`
SwapCached int `json:"swapCached"`
SwapFree int `json:"swapFree"`
SwapTotal int `json:"swapTotal"`
Unevictable int `json:"snevictable"`
VmallocChunk int `json:"vmallocChunk"`
VmallocTotal int `json:"vmallocTotal"`
VmallocUsed int `json:"vmallocUsed"`
Writeback int `json:"writeback"`
WritebackTmp int `json:"writebackTmp"`
} `json:"memory"`
Services map[string]struct {
Name string `json:"name"`
Status string `json:"status"`
Version string `json:"version"`
} `json:"services"`
Uptime struct {
Days string `json:"days"`
Hours string `json:"hours"`
Minutes string `json:"minutes"`
TotalSeconds string `json:"totalSeconds"`
Uptime string `json:"uptime"`
} `json:"uptime"`
}
type BasicSysInfo struct {
AllowPasswordReset bool `json:"allowPasswordReset"`
Hostname string `json:"hostname"`
Languages []string `json:"languages"`
LicenseError string `json:"licenseError"`
LicenseTrial bool `json:"licenseTrial"`
LicenseValid bool `json:"licenseValid"`
OtpTrustDays int `json:"otpTrustDays"`
Time time.Time `json:"time"`
}
func (c *UserContext) GetBasicSysInfo() (*BasicSysInfo, error) {
var basicSysInfo BasicSysInfo
if _, err := c.makeRequestNew(http.MethodGet, "info", nil, &basicSysInfo); err != nil {
return nil, fmt.Errorf("failed to get basic sys info: %v", err)
}
return &basicSysInfo, nil
}
// func (c *UserContext) GetPhpVersions() (*SysInfo, error) {
// var rawSys rawSysInfo
// var sys SysInfo
//
// if _, err := c.makeRequestOld(http.MethodGet, "API_SYSTEM_INFO", &rawSys); err != nil {
// return nil, err
// }
//
// sys = rawSys.parse()
//
// return &sys, nil
// }
func (c *UserContext) GetSysInfo() (*SysInfo, error) {
var rawSys rawSysInfo
var sys SysInfo
if _, err := c.makeRequestOld(http.MethodGet, "API_SYSTEM_INFO", nil, &rawSys); err != nil {
return nil, err
}
sys = rawSys.parse()
return &sys, nil
}