MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / basicstate

Function basicstate

plugin/aifalse/main.go:585–639  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

583}
584
585func basicstate() (stateinfo [3]*status, err error) {
586 percent, err := cpu.Percent(time.Second, true)
587 if err != nil {
588 return
589 }
590 cpuinfo, err := cpu.Info()
591 if err != nil {
592 return
593 }
594 cpucore, err := cpu.Counts(false)
595 if err != nil {
596 return
597 }
598 cputhread, err := cpu.Counts(true)
599 if err != nil {
600 return
601 }
602 cores := strconv.Itoa(cpucore) + "C" + strconv.Itoa(cputhread) + "T"
603 times := "最大 " + strconv.FormatFloat(cpuinfo[0].Mhz/1000, 'f', 1, 64) + "Ghz"
604
605 stateinfo[0] = &status{
606 precent: math.Round(percent[0]),
607 name: "CPU",
608 text: []string{cores, times},
609 }
610
611 raminfo, err := mem.VirtualMemory()
612 if err != nil {
613 return
614 }
615 total := "总共 " + storagefmt(float64(raminfo.Total))
616 used := "已用 " + storagefmt(float64(raminfo.Used))
617 free := "剩余 " + storagefmt(float64(raminfo.Free))
618
619 stateinfo[1] = &status{
620 precent: math.Round(raminfo.UsedPercent),
621 name: "RAM",
622 text: []string{total, used, free},
623 }
624
625 swapinfo, err := mem.SwapMemory()
626 if err != nil {
627 return
628 }
629 total = "总共 " + storagefmt(float64(swapinfo.Total))
630 used = "已用 " + storagefmt(float64(swapinfo.Used))
631 free = "剩余 " + storagefmt(float64(swapinfo.Free))
632
633 stateinfo[2] = &status{
634 precent: math.Round(swapinfo.UsedPercent),
635 name: "SWAP",
636 text: []string{total, used, free},
637 }
638 return
639}
640
641func storagefmt(num float64) string {
642 if num /= 1024; num < 1 {

Callers 1

drawstatusFunction · 0.85

Calls 1

storagefmtFunction · 0.85

Tested by

no test coverage detected