moved gstat command to a redirect

This commit is contained in:
Marc Mance
2024-08-02 14:57:35 -04:00
parent 7df502be8c
commit b5908618e2

View File

@@ -298,7 +298,9 @@ def collect_data(minutes):
if is_freebsd():
coreCPUstat()
coreMemstat()
coreIostat_disk()
# gives same data each interval
# coreIostat_disk()
if i == minutes:
print("")
@@ -433,40 +435,42 @@ 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",
">",
"gstat.csv",
]
# 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)
collect_data(minutes)
# # kill gstat if freebsd
# if is_freebsd():
# process.terminate()
# process.kill()
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()