/
process_stats.go
67 lines (59 loc) · 2.16 KB
/
process_stats.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
package presenter
import "code.cloudfoundry.org/korifi/api/actions"
type ProcessStatsResponse struct {
Resources []ProcessStatsResource `json:"resources"`
}
type ProcessStatsResource struct {
Type string `json:"type"`
Index int `json:"index"`
State string `json:"state"`
Usage ProcessUsage `json:"usage"`
Host *string `json:"host"`
InstancePorts *[]ProcessInstancePort `json:"instance_ports,omitempty"`
Uptime *int `json:"uptime"`
MemQuota *int64 `json:"mem_quota"`
DiskQuota *int64 `json:"disk_quota"`
FDSQuota *int `json:"fds_quota"`
IsolationSegment *string `json:"isolation_segment"`
Details *ProcessDetails `json:"details"`
}
type ProcessUsage struct {
Time *string `json:"time,omitempty"`
CPU *float64 `json:"cpu,omitempty"`
Mem *int64 `json:"mem,omitempty"`
Disk *int64 `json:"disk,omitempty"`
}
type ProcessInstancePort struct {
External int `json:"external"`
Internal int `json:"internal"`
ExternalTLSProxyPort int `json:"external_tls_proxy_port"`
InternalTLSProxyPort int `json:"internal_tls_proxy_port"`
}
type ProcessDetails struct{}
func ForProcessStats(records []actions.PodStatsRecord) ProcessStatsResponse {
resources := []ProcessStatsResource{}
for _, record := range records {
resources = append(resources, statRecordToResource(record))
}
return ProcessStatsResponse{resources}
}
func statRecordToResource(record actions.PodStatsRecord) ProcessStatsResource {
var processInstancePorts *[]ProcessInstancePort
if record.State != "DOWN" {
processInstancePorts = &[]ProcessInstancePort{}
}
return ProcessStatsResource{
Type: record.Type,
Index: record.Index,
State: record.State,
InstancePorts: processInstancePorts,
Usage: ProcessUsage{
Time: record.Usage.Time,
CPU: record.Usage.CPU,
Mem: record.Usage.Mem,
Disk: record.Usage.Disk,
},
MemQuota: record.MemQuota,
DiskQuota: record.DiskQuota,
}
}