()
| 1416 | |
| 1417 | @staticmethod |
| 1418 | def runConsole(): |
| 1419 | cons = f"{gethostname()}@MHTools:~#" |
| 1420 | |
| 1421 | while 1: |
| 1422 | cmd = input(cons + " ").strip() |
| 1423 | if not cmd: continue |
| 1424 | if " " in cmd: |
| 1425 | cmd, args = cmd.split(" ", 1) |
| 1426 | |
| 1427 | cmd = cmd.upper() |
| 1428 | if cmd == "HELP": |
| 1429 | print("Tools:" + ", ".join(ToolsConsole.METHODS)) |
| 1430 | print("Commands: HELP, CLEAR, BACK, EXIT") |
| 1431 | continue |
| 1432 | |
| 1433 | if {cmd} & {"E", "EXIT", "Q", "QUIT", "LOGOUT", "CLOSE"}: |
| 1434 | exit(-1) |
| 1435 | |
| 1436 | if cmd == "CLEAR": |
| 1437 | print("\033c") |
| 1438 | continue |
| 1439 | |
| 1440 | if not {cmd} & ToolsConsole.METHODS: |
| 1441 | print(f"{cmd} command not found") |
| 1442 | continue |
| 1443 | |
| 1444 | if cmd == "DSTAT": |
| 1445 | with suppress(KeyboardInterrupt): |
| 1446 | ld = net_io_counters(pernic=False) |
| 1447 | |
| 1448 | while True: |
| 1449 | sleep(1) |
| 1450 | |
| 1451 | od = ld |
| 1452 | ld = net_io_counters(pernic=False) |
| 1453 | |
| 1454 | t = [(last - now) for now, last in zip(od, ld)] |
| 1455 | |
| 1456 | logger.info( |
| 1457 | ("Bytes Sent %s\n" |
| 1458 | "Bytes Received %s\n" |
| 1459 | "Packets Sent %s\n" |
| 1460 | "Packets Received %s\n" |
| 1461 | "ErrIn %s\n" |
| 1462 | "ErrOut %s\n" |
| 1463 | "DropIn %s\n" |
| 1464 | "DropOut %s\n" |
| 1465 | "Cpu Usage %s\n" |
| 1466 | "Memory %s\n") % |
| 1467 | (Tools.humanbytes(t[0]), Tools.humanbytes(t[1]), |
| 1468 | Tools.humanformat(t[2]), Tools.humanformat(t[3]), |
| 1469 | t[4], t[5], t[6], t[7], str(cpu_percent()) + "%", |
| 1470 | str(virtual_memory().percent) + "%")) |
| 1471 | if cmd in ["CFIP", "DNS"]: |
| 1472 | print("Soon") |
| 1473 | continue |
| 1474 | |
| 1475 | if cmd == "CHECK": |
no test coverage detected