| 1 |
package rundeck |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/xml" |
| 5 |
"time" |
| 6 |
) |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
type SystemInfo struct { |
| 11 |
XMLName xml.Name `xml:"system"` |
| 12 |
ServerTime SystemTimestamp `xml:"timestamp"` |
| 13 |
Rundeck About `xml:"rundeck"` |
| 14 |
OS SystemOS `xml:"os"` |
| 15 |
JVM SystemJVM `xml:"jvm"` |
| 16 |
Stats SystemStats `xml:"stats"` |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
type About struct { |
| 21 |
XMLName xml.Name `xml:"rundeck"` |
| 22 |
Version string `xml:"version"` |
| 23 |
APIVersion int64 `xml:"apiversion"` |
| 24 |
Build string `xml:"build"` |
| 25 |
Node string `xml:"node"` |
| 26 |
BaseDir string `xml:"base"` |
| 27 |
ServerUUID string `xml:"serverUUID,omitempty"` |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
type SystemTimestamp struct { |
| 32 |
Epoch string `xml:"epoch,attr"` |
| 33 |
EpochUnit string `xml:"unit,attr"` |
| 34 |
DateTimeStr string `xml:"datetime"` |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
type SystemOS struct { |
| 39 |
Architecture string `xml:"arch"` |
| 40 |
Name string `xml:"name"` |
| 41 |
Version string `xml:"version"` |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
type SystemJVM struct { |
| 46 |
Name string `xml:"name"` |
| 47 |
Vendor string `xml:"vendor"` |
| 48 |
Version string `xml:"version"` |
| 49 |
ImplementationVersion string `xml:"implementationVersion"` |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
type SystemStats struct { |
| 54 |
XMLName xml.Name `xml:"stats"` |
| 55 |
Uptime SystemUptime `xml:"uptime"` |
| 56 |
CPU SystemCPUStats `xml:"cpu"` |
| 57 |
Memory SystemMemoryUsage `xml:"memory"` |
| 58 |
Scheduler SystemSchedulerStats `xml:"scheduler"` |
| 59 |
Threads SystemThreadStats `xml:"threads"` |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
type SystemUptime struct { |
| 64 |
XMLName xml.Name `xml:"uptime"` |
| 65 |
Duration string `xml:"duration,attr"` |
| 66 |
DurationUnit string `xml:"unit,attr"` |
| 67 |
BootTimestamp SystemTimestamp `xml:"since"` |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
type SystemCPUStats struct { |
| 73 |
XMLName xml.Name `xml:"cpu"` |
| 74 |
LoadAverage struct { |
| 75 |
Unit string `xml:"unit,attr"` |
| 76 |
Value float64 `xml:",chardata"` |
| 77 |
} `xml:"loadAverage"` |
| 78 |
ProcessorCount int64 `xml:"processors"` |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
type SystemMemoryUsage struct { |
| 84 |
XMLName xml.Name `xml:"memory"` |
| 85 |
Unit string `xml:"unit,attr"` |
| 86 |
Max int64 `xml:"max"` |
| 87 |
Free int64 `xml:"free"` |
| 88 |
Total int64 `xml:"total"` |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
type SystemSchedulerStats struct { |
| 93 |
RunningJobCount int64 `xml:"running"` |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
type SystemThreadStats struct { |
| 98 |
ActiveThreadCount int64 `xml:"active"` |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
func (c *Client) GetSystemInfo() (*SystemInfo, error) { |
| 104 |
sysInfo := &SystemInfo{} |
| 105 |
err := c.get([]string{"system", "info"}, nil, sysInfo) |
| 106 |
return sysInfo, err |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
func (ts *SystemTimestamp) DateTime() time.Time { |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
t, _ := time.Parse(time.RFC3339, ts.DateTimeStr) |
| 115 |
return t |
| 116 |
} |