From cb448cc1fbb4fc0f51fbe65f076f48bc1b21f375 Mon Sep 17 00:00:00 2001 From: Marc Mance Date: Fri, 2 Aug 2024 17:03:27 -0400 Subject: [PATCH] added logging --- collect.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/collect.py b/collect.py index 8e56dd4..00db243 100644 --- a/collect.py +++ b/collect.py @@ -7,6 +7,7 @@ import shutil import socket import platform import argparse +import logging from datetime import datetime @@ -287,16 +288,23 @@ def collect_data(minutes): print(f" {i}", end="", flush=True) + logging.info("running zpool iostat") zpoolIostat() + logging.info("running ifstat") ifstat() if is_debian(): + logging.info("running iostat_cpu") scaleIostat_cpu() + logging.info("running iostat_disk") scaleIostat_disk() + logging.info("running memstat") scaleMemstat() if is_freebsd(): + logging.info("running cpustat") coreCPUstat() + logging.info("running memstat") coreMemstat() # gives same data each interval @@ -305,6 +313,7 @@ def collect_data(minutes): if i == minutes: print("") print("") + logging.info("collection over") break time.sleep(55) @@ -312,6 +321,7 @@ def collect_data(minutes): def run_debug(): print("Taking new debug.") + logging.info("taking debug") command = ["midclt", "call", "system.debug_generate", "-job"] try: result = subprocess.run(command, capture_output=True, text=True, check=True) @@ -388,6 +398,12 @@ def welcome(): def main(): welcome() + logging.basicConfig( + filename="perf.log", + level=logging.DEBUG, + format="%(asctime)s %(levelname)s %(message)s", + ) + # setup argparse parser = argparse.ArgumentParser(description="TrueNAS Performance Capture Script") parser.add_argument( @@ -416,6 +432,8 @@ def main(): f"Set to wait {minutesToWait} minutes and then capture for {minutes} minutes." ) + logging.info(f"SETUP: {minutesToWait}m delay, {minutes}m of capture.") + if minutesToWait: print(f"Delaying capture by {minutesToWait} minutes...") for i in range(minutesToWait): @@ -424,11 +442,12 @@ def main(): print("") except KeyboardInterrupt: print("") - print("Caught control-c, exiting...") + logging.info("Caught control-c, exiting...") exit() try: print("Starting Collection") + logging.info("Starting Collection") # Collect data if is_freebsd(): # timeout = f"{minutes}m" @@ -442,11 +461,14 @@ def main(): "15s", ] + logging.info("opening gstat.csv") gstatData = open("gstat.csv", "ab") + logging.info("opening gstat.err") gstatError = open("gstat.err", "a") # with as output_file: # # Create a Popen object with stdout redirected to the file + logging.info("starting Popen") process = subprocess.Popen( gstat_command, stdout=gstatData, stderr=gstatError ) @@ -455,6 +477,7 @@ def main(): # # kill gstat if freebsd if is_freebsd(): + logging.info("killing gstat") process.terminate() gstatData.flush() @@ -467,6 +490,7 @@ def main(): print("Caught Ctrl-C, cancelling collection...") # kill gstat if freebsd if is_freebsd(): + logging.info("killing gstat") process.terminate() gstatData.flush()