MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / updateDisk

Method updateDisk

internal/nodes/node_status_executor.go:209–279  ·  view source on GitHub ↗

更新硬盘

(status *nodeconfigs.NodeStatus)

Source from the content-addressed store, hash-verified

207
208// 更新硬盘
209func (this *NodeStatusExecutor) updateDisk(status *nodeconfigs.NodeStatus) {
210 status.DiskWritingSpeedMB = int(fsutils.DiskSpeedMB)
211
212 partitions, err := disk.Partitions(false)
213 if err != nil {
214 remotelogs.Error("NODE_STATUS", err.Error())
215 return
216 }
217 lists.Sort(partitions, func(i int, j int) bool {
218 p1 := partitions[i]
219 p2 := partitions[j]
220 return p1.Mountpoint > p2.Mountpoint
221 })
222
223 // 当前TeaWeb所在的fs
224 var rootFS = ""
225 var rootTotal = uint64(0)
226 var totalUsed = uint64(0)
227 if lists.ContainsString([]string{"darwin", "linux", "freebsd"}, runtime.GOOS) {
228 for _, p := range partitions {
229 if p.Mountpoint == "/" {
230 rootFS = p.Fstype
231 usage, _ := disk.Usage(p.Mountpoint)
232 if usage != nil {
233 rootTotal = usage.Total
234 totalUsed = usage.Used
235 }
236 break
237 }
238 }
239 }
240
241 var total = rootTotal
242 var maxUsage = float64(0)
243 for _, partition := range partitions {
244 if runtime.GOOS != "windows" && !strings.Contains(partition.Device, "/") && !strings.Contains(partition.Device, "\\") {
245 continue
246 }
247
248 // 跳过不同fs的
249 if len(rootFS) > 0 && rootFS != partition.Fstype {
250 continue
251 }
252
253 usage, err := disk.Usage(partition.Mountpoint)
254 if err != nil {
255 continue
256 }
257
258 if partition.Mountpoint != "/" && (usage.Total != rootTotal || total == 0) {
259 total += usage.Total
260 totalUsed += usage.Used
261 if usage.UsedPercent >= maxUsage {
262 maxUsage = usage.UsedPercent
263 status.DiskMaxUsagePartition = partition.Mountpoint
264 }
265 }
266 }

Callers 1

updateMethod · 0.95

Calls 6

ErrorFunction · 0.92
SortMethod · 0.80
UsageMethod · 0.80
AddMethod · 0.65
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected