()
| 501 | } |
| 502 | |
| 503 | func basicstate() (stateinfo [3]*status, err error) { |
| 504 | percent, err := cpu.Percent(time.Second, true) |
| 505 | if err != nil { |
| 506 | return |
| 507 | } |
| 508 | cpuinfo, err := cpu.Info() |
| 509 | if err != nil { |
| 510 | return |
| 511 | } |
| 512 | cpucore, err := cpu.Counts(false) |
| 513 | if err != nil { |
| 514 | return |
| 515 | } |
| 516 | cputhread, err := cpu.Counts(true) |
| 517 | if err != nil { |
| 518 | return |
| 519 | } |
| 520 | cores := strconv.Itoa(cpucore) + "C" + strconv.Itoa(cputhread) + "T" |
| 521 | times := "最大 " + strconv.FormatFloat(cpuinfo[0].Mhz/1000, 'f', 1, 64) + "Ghz" |
| 522 | |
| 523 | stateinfo[0] = &status{ |
| 524 | precent: math.Round(percent[0]), |
| 525 | name: "CPU", |
| 526 | text: []string{cores, times}, |
| 527 | } |
| 528 | |
| 529 | raminfo, err := mem.VirtualMemory() |
| 530 | if err != nil { |
| 531 | return |
| 532 | } |
| 533 | total := "总共 " + storagefmt(float64(raminfo.Total)) |
| 534 | used := "已用 " + storagefmt(float64(raminfo.Used)) |
| 535 | free := "剩余 " + storagefmt(float64(raminfo.Free)) |
| 536 | |
| 537 | stateinfo[1] = &status{ |
| 538 | precent: math.Round(raminfo.UsedPercent), |
| 539 | name: "RAM", |
| 540 | text: []string{total, used, free}, |
| 541 | } |
| 542 | |
| 543 | swapinfo, err := mem.SwapMemory() |
| 544 | if err != nil { |
| 545 | return |
| 546 | } |
| 547 | total = "总共 " + storagefmt(float64(swapinfo.Total)) |
| 548 | used = "已用 " + storagefmt(float64(swapinfo.Used)) |
| 549 | free = "剩余 " + storagefmt(float64(swapinfo.Free)) |
| 550 | |
| 551 | stateinfo[2] = &status{ |
| 552 | precent: math.Round(swapinfo.UsedPercent), |
| 553 | name: "SWAP", |
| 554 | text: []string{total, used, free}, |
| 555 | } |
| 556 | return |
| 557 | } |
| 558 | |
| 559 | func storagefmt(num float64) string { |
| 560 | if num /= 1024; num < 1 { |
no test coverage detected