|
@@ -1,11 +1,14 @@
|
|
|
import subprocess
|
|
import subprocess
|
|
|
import re
|
|
import re
|
|
|
import time
|
|
import time
|
|
|
|
|
+import serial
|
|
|
|
|
+
|
|
|
|
|
+serial_port = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
|
|
|
|
|
|
|
|
disks = ['sda', 'sdb', 'sdc', 'sdd'] # List of disks to monitor
|
|
disks = ['sda', 'sdb', 'sdc', 'sdd'] # List of disks to monitor
|
|
|
|
|
|
|
|
while True:
|
|
while True:
|
|
|
- cmd = "iostat -xk 1 2 " + " ".join(disks)
|
|
|
|
|
|
|
+ cmd = "iostat -k 1 2 " + " ".join(disks)
|
|
|
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
output, _ = process.communicate()
|
|
output, _ = process.communicate()
|
|
|
|
|
|
|
@@ -22,13 +25,28 @@ while True:
|
|
|
if len(io_data) >= len(headers):
|
|
if len(io_data) >= len(headers):
|
|
|
current_disk = io_data[0]
|
|
current_disk = io_data[0]
|
|
|
disk_info[current_disk] = {headers[i]: io_data[i] for i in range(1, len(headers))}
|
|
disk_info[current_disk] = {headers[i]: io_data[i] for i in range(1, len(headers))}
|
|
|
-
|
|
|
|
|
|
|
+ counter = 0
|
|
|
|
|
+ byte_array = bytearray()
|
|
|
for disk in disks:
|
|
for disk in disks:
|
|
|
if disk in disk_info:
|
|
if disk in disk_info:
|
|
|
- read_bytes = disk_info[disk].get('rkB/s', '0.00')
|
|
|
|
|
- write_bytes = disk_info[disk].get('wkB/s', '0.00')
|
|
|
|
|
- if float(read_bytes) > 0 or float(write_bytes) > 0:
|
|
|
|
|
- print(f"R/W activity detected on /dev/{disk}:")
|
|
|
|
|
- print(f"Read bytes: {read_bytes}, Write bytes: {write_bytes}")
|
|
|
|
|
-
|
|
|
|
|
- time.sleep(1) # Adjust the frequency of checking disk activity (1 second in this example)
|
|
|
|
|
|
|
+ read_bytes = disk_info[disk].get('kB_read/s', '0.00')
|
|
|
|
|
+ write_bytes = disk_info[disk].get('kB_wrtn/s', '0.00')
|
|
|
|
|
+ if float(read_bytes) > 0:
|
|
|
|
|
+ # serial_port.write(f"{hex(counter)}".encode())
|
|
|
|
|
+ print(counter)
|
|
|
|
|
+ byte_array.append(counter)
|
|
|
|
|
+ else:
|
|
|
|
|
+ # serial_port.write(f"{hex(counter+1)".encode())
|
|
|
|
|
+ print(counter+1)
|
|
|
|
|
+ byte_array.append(counter+1)
|
|
|
|
|
+ if float(write_bytes) > 0:
|
|
|
|
|
+ # serial_port.write(f"{hex(counter+2})".encode())
|
|
|
|
|
+ print(counter+2)
|
|
|
|
|
+ byte_array.append(counter+2)
|
|
|
|
|
+ else:
|
|
|
|
|
+# serial_port.write(f"{hex(counter+3)".encode())
|
|
|
|
|
+ print(counter+3)
|
|
|
|
|
+ byte_array.append(counter+3)
|
|
|
|
|
+ counter += 4
|
|
|
|
|
+ serial_port.write(byte_array)
|
|
|
|
|
+ #time.sleep(0.1) # Adjust the frequency of checking disk activity (1 second in this example)
|