6. Write a python program to get information about I/O.
import psutil
def get_io_info():
# Get disk I/O statistics
disk_io = psutil.disk_io_counters()
print("Disk I/O statistics:")
print(" Total read bytes:", disk_io.read_bytes)
print(" Total write bytes:", disk_io.write_bytes)
print(" Total read time:", disk_io.read_time)
print(" Total write time:", disk_io.write_time)
print()
# Get network I/O statistics
net_io = psutil.net_io_counters()
print("Network I/O statistics:")
print(" Total bytes sent:", net_io.bytes_sent)
print(" Total bytes received:", net_io.bytes_recv)
print(" Total packets sent:", net_io.packets_sent)
print(" Total packets received:", net_io.packets_recv)
if __name__ == "__main__":
get_io_info()
Output 6:
Disk I/O statistics:
Total read bytes: 2024574464
Total write bytes: 1696656384
Total read time: 1379011
Total write time: 1440066
Network I/O statistics:
Total bytes sent: 23960489
Total bytes received: 80777166
Total packets sent: 77405
Total packets received: 103989