-
Notifications
You must be signed in to change notification settings - Fork 142
/
mountpath.go
219 lines (201 loc) · 4.95 KB
/
mountpath.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Package teb contains templates and (templated) tables to format CLI output.
/*
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
*/
package teb
import (
"fmt"
"sort"
"strconv"
"strings"
"github.com/NVIDIA/aistore/api/apc"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/fs"
"github.com/NVIDIA/aistore/stats"
)
const (
// colTarget
colNumMpaths = "MOUNTPATHS"
colMountpath = "MOUNTPATH"
colUsedAvgMax = "USED(min%, avg%, max%)"
colDisksFS = "Disks & File System"
colFS = "File System"
colCapStatus = "CAP STATUS"
)
func NewMpathCapTab(st StstMap, c *PerfTabCtx, showMpaths bool) *Table {
var cols []*header
// 1. columns
if showMpaths {
cols = []*header{
{name: colTarget},
{name: colMountpath},
{name: colCapUsed},
{name: colCapAvail},
{name: colDisk},
{name: colFS},
{name: colCapStatus},
}
} else { // show num mountpaths and aggregated used/avail stats
cols = []*header{
{name: colTarget},
{name: colNumMpaths},
{name: colUsedAvgMax},
{name: colCapAvail},
{name: colDisksFS},
{name: colCapStatus},
}
}
// filter columns
if c.Regex != nil {
cols = _flt(cols, c.Regex)
if _idx(cols, colCapStatus) < 0 && _inclStatus(st) {
cols = append(cols, &header{name: colCapStatus}) // add it back
}
}
table := newTable(cols...)
tids := st.sortedSIDs()
for _, tid := range tids {
ds := st[tid]
if c.Sid != "" && c.Sid != tid {
continue
}
if ds.Status != NodeOnline {
row := make([]string, 0, len(cols))
row = append(row, fmtDaemonID(tid, c.Smap, ds.Status))
for _, h := range cols[1:] {
if h.name == colCapStatus {
row = append(row, fred(ds.Status))
} else {
row = append(row, unknownVal)
}
}
table.addRow(row)
continue
}
if showMpaths {
var (
i, num = 0, len(ds.TargetCDF.Mountpaths)
mpaths = make([]string, 0, num)
)
for mp := range ds.TargetCDF.Mountpaths {
mpaths = append(mpaths, mp)
}
sort.Strings(mpaths)
// add rows: one per mountpath
for _, mp := range mpaths {
row := make([]string, 0, len(cols))
if i == 0 {
row = append(row, fmtDaemonID(tid, c.Smap, ds.Status))
} else {
row = append(row, "")
}
cdf := ds.TargetCDF.Mountpaths[mp]
row = mpathRow(c, cols, mp, cdf, row)
if _idx(cols, colCapStatus) >= 0 {
if i == 0 {
row = append(row, _capStatus(ds.TargetCDF))
} else {
row = append(row, "")
}
}
table.addRow(row)
i++
}
} else {
// add row
row := make([]string, 0, len(cols))
row = append(row, fmtDaemonID(tid, c.Smap, ds.Status))
row = numMpathsRow(ds, c, cols, row)
table.addRow(row)
}
}
return table
}
func mpathRow(c *PerfTabCtx, cols []*header, mpath string, cdf *fs.CDF, row []string) []string {
if _idx(cols, colMountpath) >= 0 {
debug.Assert(_idx(cols, colNumMpaths) < 0)
row = append(row, mpath)
}
if _idx(cols, colCapUsed) >= 0 {
row = append(row, strconv.Itoa(int(cdf.PctUsed))+"%")
}
if _idx(cols, colCapAvail) >= 0 {
row = append(row, FmtSize(int64(cdf.Avail), c.Units, 2))
}
if _idx(cols, colDisk) >= 0 {
if len(cdf.Disks) > 1 {
row = append(row, fmt.Sprintf("%v", cdf.Disks))
} else if len(cdf.Disks) == 1 {
row = append(row, cdf.Disks[0])
} else {
row = append(row, unknownVal)
}
}
if _idx(cols, colFS) >= 0 {
row = append(row, cdf.FS.String())
}
return row
}
func numMpathsRow(ds *stats.NodeStatus, c *PerfTabCtx, cols []*header, row []string) []string {
tcdf := ds.TargetCDF
if _idx(cols, colNumMpaths) >= 0 {
debug.Assert(_idx(cols, colMountpath) < 0)
row = append(row, strconv.Itoa(len(tcdf.Mountpaths)))
}
if _idx(cols, colUsedAvgMax) >= 0 {
// len("USED(")
row = append(row, " "+fmtCapPctMAM(&tcdf, false /*list*/))
}
if _idx(cols, colCapAvail) >= 0 {
avail := _sumupMpathsAvail(tcdf, ds.DeploymentType)
row = append(row, FmtSize(int64(avail), c.Units, 2))
}
if i := _idx(cols, colDisksFS); i >= 0 {
row = append(row, _fmtMpathDisks(tcdf.Mountpaths, i))
}
if _idx(cols, colCapStatus) >= 0 {
row = append(row, _capStatus(tcdf))
}
return row
}
func _capStatus(tcdf fs.TargetCDF) (s string) {
if tcdf.CsErr == "" {
if len(tcdf.Mountpaths) == 1 {
s = "good"
} else {
s = fcyan("good")
}
} else {
s = fred("Error: ") + tcdf.CsErr
}
return
}
func _fmtMpathDisks(cdfs map[string]*fs.CDF, idx int) (s string) {
var next bool
for _, cdf := range cdfs {
if next {
s += "\n" + strings.Repeat("\t", idx) + " "
}
s += cdf.FS.String()
next = true
}
return
}
func _inclStatus(st StstMap) bool {
for _, ds := range st {
if ds.Status != NodeOnline || ds.TargetCDF.CsErr != "" {
return true
}
}
return false
}
// compare with "total num disks" (daeclu.go)
func _sumupMpathsAvail(cdf fs.TargetCDF, deploymentType string) (avail uint64) {
for _, c := range cdf.Mountpaths {
avail += c.Capacity.Avail
if deploymentType == apc.DeploymentDev {
return // simplifying HACK that'll be true most of the time
}
}
return
}