diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16f2dc5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.csv \ No newline at end of file diff --git a/collect.sh b/collect.sh index 404768d..5d46e8f 100755 --- a/collect.sh +++ b/collect.sh @@ -8,12 +8,23 @@ echo "Will auto upload to iXsystem when completed." echo "Airgapped Systems will need to exfiltrate /root/*.csv" echo "" -python3 ./collect.zpool.iostat.py --minutes $minutes & -echo "running gstat" -timeout "$minutes"m gstat -C -s -d -o -p -I 60s > /root/gstat.csv -cp /root/zpool_iostat.csv /root/gstat.csv /var/log +iostat="python3 ixiostat.py " +gstat="gstat -C -s -d -o -p -I 60s >> /root/gstat.csv" + +iterations=$1 + +for (( i=1; i<=$iterations; i++ )); do + # Execute the command + $gstat + $iostat + + # Wait for 60 seconds before the next iteration + sleep 60 +done + +cp *.csv /var/log DEBUGFILE=`midclt call system.debug_generate -job` && export DEBUGFILE curl --user customer:ixcustomer -T $DEBUGFILE ftp.ixsystems.com/debug-`hostname`-`date +%Y%m%d%H%M`.tgz diff --git a/ixiostat.py b/ixiostat.py new file mode 100644 index 0000000..0373bfe --- /dev/null +++ b/ixiostat.py @@ -0,0 +1,115 @@ +import subprocess +import re +import csv +import os +from datetime import datetime + + +def convert_to_machine_readable(date_string): + # Define the format string considering the time zone information (EDT) + format_string = "%a %b %d %H:%M:%S %p %Z %Y" + try: + # Parse the date string using the format string + datetime_obj = datetime.strptime(date_string, format_string) + return datetime_obj + except ValueError: + print( + f"Error: Invalid date format. Please provide a string in the format '{format_string}'." + ) + return None + + +# Define your shell command +command = ["zpool", "iostat", "-Td", "-l", "-p", "-v", "-y", "1", "1"] + +headerRow = [ + "time", + "capacity_alloc", + "capacity_free", + "ops_read", + "ops_write", + "bandwidth_read", + "bandwidth_write", + "total_wait_read", + "total_wait_write", + "disk_wait_read", + "disk_wait_write", + "syncq_wait_read", + "syncq_wait_write", + "asyncq_wait_read", + "asyncq_wait_write", + "scrub_wait", + "trim_wait", +] + + +def runZpoolIostat(): + # Run the command and capture output + result = subprocess.run(command, capture_output=True, text=True) + + # Check the return code (0 for success) + if result.returncode == 0: + # Access the captured output as a string + output = result.stdout + + # split output by pools + pools = re.split(r"^-", output, flags=re.MULTILINE) + + i = 0 + for pool in pools: + if i == 0: + # get timestamp + timestamp = pool.splitlines()[0].strip() + + if timestamp: + timestamp = str(convert_to_machine_readable(timestamp)) + + else: + # remove ------ lines + pool = re.sub("^---.*", "", pool).strip() + + # turn - values into 0 + pool = re.sub(" -", "0", pool) + + y = 0 + + poolbyline = re.split("\n", pool) + + for line in poolbyline: + lineData = line.split() + + if not lineData: + break + + if y == 0: + poolname = lineData[0] + filename = poolname + "-zio.csv" + + # Check if the file exists + if not os.path.exists(filename): + # Create the file in write mode ('w') if it doesn't exist + with open(filename, "w", newline="") as csvfile: + csv_writer = csv.writer(csvfile) + # Write the header row (optional) + csv_writer.writerow(headerRow) + + # Now open the file in append mode ('a') + with open(filename, "a", newline="") as csvfile: + csv_writer = csv.writer(csvfile) + lineData.insert(0, timestamp) + csv_writer.writerow(lineData) + + y += 1 + + i += 1 + + else: + print(f"Error running command: {result.stderr}") + + +def main(): + runZpoolIostat() + + +if __name__ == "__main__": + main()