-
Notifications
You must be signed in to change notification settings - Fork 21
/
cellListView.go
150 lines (111 loc) · 4.94 KB
/
cellListView.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package cellView
import (
"fmt"
"github.com/jroimartin/gocui"
"github.com/kkellner/cloudfoundry-top-plugin/eventdata"
"github.com/kkellner/cloudfoundry-top-plugin/metadata"
"github.com/kkellner/cloudfoundry-top-plugin/ui/masterUIInterface"
"github.com/kkellner/cloudfoundry-top-plugin/ui/uiCommon"
"github.com/kkellner/cloudfoundry-top-plugin/ui/views/dataView"
"github.com/kkellner/cloudfoundry-top-plugin/ui/views/displaydata"
)
const MEGABYTE = (1024 * 1024)
type CellListView struct {
*dataView.DataListView
}
func NewCellListView(masterUI masterUIInterface.MasterUIInterface,
name string, topMargin, bottomMargin int,
eventProcessor *eventdata.EventProcessor) *CellListView {
asUI := &CellListView{}
defaultSortColumns := []*uiCommon.SortColumn{
uiCommon.NewSortColumn("IP", false),
//uiCommon.NewSortColumn("colB", true),
}
dataListView := dataView.NewDataListView(masterUI,
name, topMargin, bottomMargin,
eventProcessor, asUI.columnDefinitions(),
defaultSortColumns)
dataListView.UpdateHeaderCallback = asUI.updateHeader
dataListView.GetListData = asUI.GetListData
dataListView.SetTitle("Cell List")
dataListView.HelpText = helpText
asUI.DataListView = dataListView
return asUI
}
func (asUI *CellListView) columnDefinitions() []*uiCommon.ListColumn {
columns := make([]*uiCommon.ListColumn, 0)
columns = append(columns, asUI.columnIp())
columns = append(columns, asUI.columnTotalCpuPercentage())
columns = append(columns, asUI.columnTotalReportingContainers())
columns = append(columns, asUI.columnNumOfCpus())
columns = append(columns, asUI.columnCapacityTotalMemory())
columns = append(columns, asUI.columnCapacityRemainingMemory())
columns = append(columns, asUI.columnTotalContainerReservedMemory())
columns = append(columns, asUI.columnTotalContainerUsedMemory())
columns = append(columns, asUI.columnCapacityTotalDisk())
columns = append(columns, asUI.columnCapacityRemainingDisk())
columns = append(columns, asUI.columnTotalContainerReservedDisk())
columns = append(columns, asUI.columnTotalContainerUsedDisk())
columns = append(columns, asUI.columnCapacityTotalContainers())
columns = append(columns, asUI.columnContainerCount())
columns = append(columns, asUI.columnDeploymentName())
columns = append(columns, asUI.columnJobName())
columns = append(columns, asUI.columnJobIndex())
return columns
}
func (asUI *CellListView) GetListData() []uiCommon.IData {
displayDataList := asUI.postProcessData()
listData := asUI.convertToListData(displayDataList)
return listData
}
func (asUI *CellListView) postProcessData() map[string]*displaydata.DisplayCellStats {
cellMap := asUI.GetDisplayedEventData().CellMap
displayCellMap := make(map[string]*displaydata.DisplayCellStats)
for ip, cellStats := range cellMap {
displayStat := displaydata.NewDisplayCellStats(cellStats)
displayCellMap[ip] = displayStat
}
appMap := asUI.GetDisplayedEventData().AppMap
for _, appStats := range appMap {
for _, containerStats := range appStats.ContainerArray {
if containerStats != nil {
cellStats := displayCellMap[containerStats.Ip]
if cellStats != nil {
logOutCount := containerStats.OutCount
cellStats.TotalLogOutCount = cellStats.TotalLogOutCount + logOutCount
logErrCount := containerStats.ErrCount
cellStats.TotalLogErrCount = cellStats.TotalLogErrCount + logErrCount
if containerStats.ContainerMetric != nil {
appMetadata := metadata.FindAppMetadata(appStats.AppId)
cellStats.TotalReportingContainers = cellStats.TotalReportingContainers + 1
cpuValue := containerStats.ContainerMetric.GetCpuPercentage()
cellStats.TotalContainerCpuPercentage = cellStats.TotalContainerCpuPercentage + cpuValue
//reservedMemoryValue := containerStats.ContainerMetric.GetMemoryBytesQuota()
cellStats.TotalContainerReservedMemory = cellStats.TotalContainerReservedMemory + uint64(appMetadata.MemoryMB*MEGABYTE)
usedMemoryValue := containerStats.ContainerMetric.GetMemoryBytes()
cellStats.TotalContainerUsedMemory = cellStats.TotalContainerUsedMemory + usedMemoryValue
//reservedDiskValue := containerStats.ContainerMetric.GetDiskBytesQuota()
cellStats.TotalContainerReservedDisk = cellStats.TotalContainerReservedDisk + uint64(appMetadata.DiskQuotaMB*MEGABYTE)
usedDiskValue := containerStats.ContainerMetric.GetDiskBytes()
cellStats.TotalContainerUsedDisk = cellStats.TotalContainerUsedDisk + usedDiskValue
}
}
}
}
}
return displayCellMap
}
func (asUI *CellListView) convertToListData(displayCellMap map[string]*displaydata.DisplayCellStats) []uiCommon.IData {
listData := make([]uiCommon.IData, 0, len(displayCellMap))
for _, d := range displayCellMap {
listData = append(listData, d)
}
return listData
}
func (asUI *CellListView) PreRowDisplay(data uiCommon.IData, isSelected bool) string {
return ""
}
func (asUI *CellListView) updateHeader(g *gocui.Gui, v *gocui.View) error {
fmt.Fprintf(v, "\nTODO: Show summary Cell stats")
return nil
}