wrapped collect in try catch for keyboard interupt
This commit is contained in:
63
collect.py
63
collect.py
@@ -259,12 +259,6 @@ def zpoolIostat():
|
|||||||
|
|
||||||
|
|
||||||
def collect_data(minutes):
|
def collect_data(minutes):
|
||||||
if is_freebsd():
|
|
||||||
gstat_command = ["gstat", "-C", "-s", "-d", "-o", "-p", "-I", "5s"]
|
|
||||||
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)
|
|
||||||
|
|
||||||
for i in range(minutes):
|
for i in range(minutes):
|
||||||
if i == 0:
|
if i == 0:
|
||||||
print("Minute:", end="", flush=True)
|
print("Minute:", end="", flush=True)
|
||||||
@@ -290,10 +284,6 @@ def collect_data(minutes):
|
|||||||
|
|
||||||
time.sleep(45)
|
time.sleep(45)
|
||||||
|
|
||||||
# kill gstat if freebsd
|
|
||||||
if is_freebsd():
|
|
||||||
process.kill()
|
|
||||||
|
|
||||||
|
|
||||||
def run_debug():
|
def run_debug():
|
||||||
print("Taking new debug.")
|
print("Taking new debug.")
|
||||||
@@ -380,20 +370,51 @@ def main():
|
|||||||
minutes = int(input("Enter the duration in minutes: "))
|
minutes = int(input("Enter the duration in minutes: "))
|
||||||
minutesToWait = int(input("Enter the delay before capture in minutes: "))
|
minutesToWait = int(input("Enter the delay before capture in minutes: "))
|
||||||
|
|
||||||
if not minutesToWait:
|
try:
|
||||||
minutesToWait = 0
|
if not minutesToWait:
|
||||||
|
minutesToWait = 0
|
||||||
|
|
||||||
if minutesToWait:
|
if minutesToWait:
|
||||||
print(f"Delaying capture by {minutesToWait} minutes...")
|
print(f"Delaying capture by {minutesToWait} minutes...")
|
||||||
for i in range(minutesToWait):
|
for i in range(minutesToWait):
|
||||||
print(f"{i} ", end="", flush=True)
|
print(f"{i} ", end="", flush=True)
|
||||||
time.sleep(minutesToWait * 60)
|
time.sleep(minutesToWait * 60)
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
print("Starting Collection")
|
print("Starting Collection")
|
||||||
|
|
||||||
# Collect data
|
# Collect data
|
||||||
collect_data(minutes)
|
if is_freebsd():
|
||||||
|
timeout = f"{minutes}m"
|
||||||
|
gstat_command = [
|
||||||
|
"timeout",
|
||||||
|
timeout,
|
||||||
|
"gstat",
|
||||||
|
"-C",
|
||||||
|
"-s",
|
||||||
|
"-d",
|
||||||
|
"-o",
|
||||||
|
"-p",
|
||||||
|
"-I",
|
||||||
|
"5s",
|
||||||
|
]
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
collect_data(minutes)
|
||||||
|
|
||||||
|
# kill gstat if freebsd
|
||||||
|
if is_freebsd():
|
||||||
|
process.kill()
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Caught Ctrl-C, cancelling collection...")
|
||||||
|
# kill gstat if freebsd
|
||||||
|
if is_freebsd():
|
||||||
|
process.kill()
|
||||||
|
exit()
|
||||||
|
|
||||||
# Copy data files to /var/log (replace with appropriate copying function)
|
# Copy data files to /var/log (replace with appropriate copying function)
|
||||||
collect_csv()
|
collect_csv()
|
||||||
|
|||||||
Reference in New Issue
Block a user