From 7df502be8c56a46288606d945a88f633b88d5ed2 Mon Sep 17 00:00:00 2001 From: Marc Mance Date: Fri, 2 Aug 2024 14:40:09 -0400 Subject: [PATCH] moved gstat to iostat in bsd --- collect.py | 77 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/collect.py b/collect.py index 1c4ca24..2398824 100644 --- a/collect.py +++ b/collect.py @@ -38,6 +38,28 @@ def runCollect(command): return result.stderr +def coreIostat_disk(): + command = ["iostat", "-xd", "-t", "da", "1", "1"] + filename = "ioStat.csv" + collect = runCollect(command) + + if collect: + byline = re.split("\n", collect.strip()) + data = byline[2:] + + for line in data: + lineData = line.split() + + if lineData: + with open(filename, "a", newline="") as csvfile: + csv_writer = csv.writer(csvfile) + lineData.insert(0, getTimestamp()) + csv_writer.writerow(lineData) + + else: + print(f"Error running command: {collect}") + + def scaleIostat_disk(): command = ["iostat", "-xyd", "1", "1"] filename = "ioStat.csv" @@ -212,7 +234,7 @@ def coreCPUstat(): def zpoolIostat(): - command = ["zpool", "iostat", "-Tu", "-l", "-p", "-v", "-y", "15", "1"] + command = ["zpool", "iostat", "-Tu", "-l", "-p", "-v", "-y", "5", "1"] collect = runCollect(command) if collect: @@ -276,13 +298,14 @@ def collect_data(minutes): if is_freebsd(): coreCPUstat() coreMemstat() + coreIostat_disk() if i == minutes: print("") print("") break - time.sleep(45) + time.sleep(55) def run_debug(): @@ -410,40 +433,40 @@ def main(): print("Starting Collection") # Collect data - if is_freebsd(): - # timeout = f"{minutes}m" - # "timeout", - # timeout, + # if is_freebsd(): + # # timeout = f"{minutes}m" + # # "timeout", + # # timeout, - gstat_command = [ - "gstat", - "-C", - "-s", - "-d", - "-o", - "-p", - "-I", - "5s", - ] + # gstat_command = [ + # "gstat", + # "-C", + # "-s", + # "-d", + # "-o", + # "-p", + # "-I", + # "5s", + # ] - with open("gstat.csv", "a") as output_file: - # Create a Popen object with stdout redirected to the file - process = subprocess.Popen(gstat_command, stdout=output_file) + # with open("gstat.csv", "a") as output_file: + # # Create a Popen object with stdout redirected to the file + # process = subprocess.Popen(gstat_command, stdout=output_file) collect_data(minutes) - # kill gstat if freebsd - if is_freebsd(): - process.terminate() - process.kill() + # # kill gstat if freebsd + # if is_freebsd(): + # process.terminate() + # process.kill() except KeyboardInterrupt: print("Caught Ctrl-C, cancelling collection...") # kill gstat if freebsd - if is_freebsd(): - process.terminate() - process.kill() - exit() + # if is_freebsd(): + # process.terminate() + # process.kill() + # exit() # Copy data files to /var/log (replace with appropriate copying function) collect_csv()