Debian Codegraph @

rundeck/system_info.go

raw symbols SCIP
1 package rundeck
2
3 import (
4 "encoding/xml"
5 "time"
6 )
7
8 // SystemInfo represents a set of miscellaneous system information properties about the
9 // Rundeck server.
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 // About describes the Rundeck server itself.
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 // SystemTimestamp gives a timestamp from the Rundeck server.
31 type SystemTimestamp struct {
32 Epoch string `xml:"epoch,attr"`
33 EpochUnit string `xml:"unit,attr"`
34 DateTimeStr string `xml:"datetime"`
35 }
36
37 // SystemOS describes the operating system of the Rundeck server.
38 type SystemOS struct {
39 Architecture string `xml:"arch"`
40 Name string `xml:"name"`
41 Version string `xml:"version"`
42 }
43
44 // SystemJVM describes the Java Virtual Machine that the Rundeck server is running in.
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 // SystemStats provides some basic system statistics about the server that Rundeck is running on.
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 // SystemUptime describes how long Rundeck's host machine has been running.
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 // SystemCPUStats describes the available processors and the system load average of the machine on
71 // which the Rundeck server is running.
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 // SystemMemoryUsage describes how much memory is available and used on the machine on which
82 // the Rundeck server is running.
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 // SystemSchedulerStats provides statistics about the Rundeck scheduler.
92 type SystemSchedulerStats struct {
93 RunningJobCount int64 `xml:"running"`
94 }
95
96 // SystemThreadStats provides statistics about the thread usage of the Rundeck server.
97 type SystemThreadStats struct {
98 ActiveThreadCount int64 `xml:"active"`
99 }
100
101 // GetSystemInfo retrieves and returns miscellaneous system information about the Rundeck server
102 // and the machine it's running on.
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 // DateTime produces a time.Time object from a SystemTimestamp object.
110 func (ts *SystemTimestamp) DateTime() time.Time {
111 // Assume the server will always give us a valid timestamp,
112 // so we don't need to handle the error case.
113 // (Famous last words?)
114 t, _ := time.Parse(time.RFC3339, ts.DateTimeStr)
115 return t
116 }