moved file check into statcollect function only if results are true

This commit is contained in:
Marc Mance
2024-06-06 14:50:24 -04:00
parent 9c24ca5a56
commit 0bdc036f01
4 changed files with 32 additions and 32 deletions

View File

@@ -16,14 +16,6 @@ headerRow = [
filename = "ifStat.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)
def runifstat():
# Run the command and capture output
@@ -36,6 +28,14 @@ def runifstat():
# Check the return code (0 for success)
if result.returncode == 0:
# 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)
# Access the captured output as a string
output = result.stdout

View File

@@ -21,14 +21,6 @@ headerRow = [
filename = "cpuStat.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)
def runIostat():
# Run the command and capture output
@@ -41,6 +33,14 @@ def runIostat():
# Check the return code (0 for success)
if result.returncode == 0:
# 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)
# Access the captured output as a string
output = result.stdout
byline = re.split("\n", output)

View File

@@ -38,14 +38,6 @@ headerRow = [
filename = "topStat.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)
def convert_to_megabytes(data_size):
"""
@@ -89,6 +81,14 @@ def runtopstat():
# Check the return code (0 for success)
if result.returncode == 0:
# 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)
# Access the captured output as a string
output = result.stdout

View File

@@ -36,6 +36,14 @@ def runZpoolIostat():
# Check the return code (0 for success)
if result.returncode == 0:
# 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)
# Access the captured output as a string
output = result.stdout
@@ -73,14 +81,6 @@ def runZpoolIostat():
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)