moved file check into statcollect function only if results are true
This commit is contained in:
16
ifstat.py
16
ifstat.py
@@ -16,14 +16,6 @@ headerRow = [
|
|||||||
|
|
||||||
filename = "ifStat.csv"
|
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():
|
def runifstat():
|
||||||
# Run the command and capture output
|
# Run the command and capture output
|
||||||
@@ -36,6 +28,14 @@ def runifstat():
|
|||||||
|
|
||||||
# Check the return code (0 for success)
|
# Check the return code (0 for success)
|
||||||
if result.returncode == 0:
|
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
|
# Access the captured output as a string
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
|
|
||||||
|
|||||||
16
iostat.py
16
iostat.py
@@ -21,14 +21,6 @@ headerRow = [
|
|||||||
|
|
||||||
filename = "cpuStat.csv"
|
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():
|
def runIostat():
|
||||||
# Run the command and capture output
|
# Run the command and capture output
|
||||||
@@ -41,6 +33,14 @@ def runIostat():
|
|||||||
|
|
||||||
# Check the return code (0 for success)
|
# Check the return code (0 for success)
|
||||||
if result.returncode == 0:
|
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
|
# Access the captured output as a string
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
byline = re.split("\n", output)
|
byline = re.split("\n", output)
|
||||||
|
|||||||
16
topstat.py
16
topstat.py
@@ -38,14 +38,6 @@ headerRow = [
|
|||||||
|
|
||||||
filename = "topStat.csv"
|
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):
|
def convert_to_megabytes(data_size):
|
||||||
"""
|
"""
|
||||||
@@ -89,6 +81,14 @@ def runtopstat():
|
|||||||
|
|
||||||
# Check the return code (0 for success)
|
# Check the return code (0 for success)
|
||||||
if result.returncode == 0:
|
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
|
# Access the captured output as a string
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ def runZpoolIostat():
|
|||||||
|
|
||||||
# Check the return code (0 for success)
|
# Check the return code (0 for success)
|
||||||
if result.returncode == 0:
|
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
|
# Access the captured output as a string
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
|
|
||||||
@@ -73,14 +81,6 @@ def runZpoolIostat():
|
|||||||
poolname = lineData[0]
|
poolname = lineData[0]
|
||||||
filename = poolname + "-zio.csv"
|
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')
|
# Now open the file in append mode ('a')
|
||||||
with open(filename, "a", newline="") as csvfile:
|
with open(filename, "a", newline="") as csvfile:
|
||||||
csv_writer = csv.writer(csvfile)
|
csv_writer = csv.writer(csvfile)
|
||||||
|
|||||||
Reference in New Issue
Block a user