moved file check into statcollect function only if results are true
This commit is contained in:
16
iostat.py
16
iostat.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user