moved gstat to iostat in bsd

This commit is contained in:
Marc Mance
2024-08-02 14:40:09 -04:00
parent 4d323ffb8e
commit 7df502be8c

View File

@@ -38,6 +38,28 @@ def runCollect(command):
return result.stderr return result.stderr
def coreIostat_disk():
command = ["iostat", "-xd", "-t", "da", "1", "1"]
filename = "ioStat.csv"
collect = runCollect(command)
if collect:
byline = re.split("\n", collect.strip())
data = byline[2:]
for line in data:
lineData = line.split()
if lineData:
with open(filename, "a", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
lineData.insert(0, getTimestamp())
csv_writer.writerow(lineData)
else:
print(f"Error running command: {collect}")
def scaleIostat_disk(): def scaleIostat_disk():
command = ["iostat", "-xyd", "1", "1"] command = ["iostat", "-xyd", "1", "1"]
filename = "ioStat.csv" filename = "ioStat.csv"
@@ -212,7 +234,7 @@ def coreCPUstat():
def zpoolIostat(): def zpoolIostat():
command = ["zpool", "iostat", "-Tu", "-l", "-p", "-v", "-y", "15", "1"] command = ["zpool", "iostat", "-Tu", "-l", "-p", "-v", "-y", "5", "1"]
collect = runCollect(command) collect = runCollect(command)
if collect: if collect:
@@ -276,13 +298,14 @@ def collect_data(minutes):
if is_freebsd(): if is_freebsd():
coreCPUstat() coreCPUstat()
coreMemstat() coreMemstat()
coreIostat_disk()
if i == minutes: if i == minutes:
print("") print("")
print("") print("")
break break
time.sleep(45) time.sleep(55)
def run_debug(): def run_debug():
@@ -410,40 +433,40 @@ def main():
print("Starting Collection") print("Starting Collection")
# Collect data # Collect data
if is_freebsd(): # if is_freebsd():
# timeout = f"{minutes}m" # # timeout = f"{minutes}m"
# "timeout", # # "timeout",
# timeout, # # timeout,
gstat_command = [ # gstat_command = [
"gstat", # "gstat",
"-C", # "-C",
"-s", # "-s",
"-d", # "-d",
"-o", # "-o",
"-p", # "-p",
"-I", # "-I",
"5s", # "5s",
] # ]
with open("gstat.csv", "a") as output_file: # with open("gstat.csv", "a") as output_file:
# Create a Popen object with stdout redirected to the file # # Create a Popen object with stdout redirected to the file
process = subprocess.Popen(gstat_command, stdout=output_file) # process = subprocess.Popen(gstat_command, stdout=output_file)
collect_data(minutes) collect_data(minutes)
# kill gstat if freebsd # # kill gstat if freebsd
if is_freebsd(): # if is_freebsd():
process.terminate() # process.terminate()
process.kill() # process.kill()
except KeyboardInterrupt: except KeyboardInterrupt:
print("Caught Ctrl-C, cancelling collection...") print("Caught Ctrl-C, cancelling collection...")
# kill gstat if freebsd # kill gstat if freebsd
if is_freebsd(): # if is_freebsd():
process.terminate() # process.terminate()
process.kill() # process.kill()
exit() # 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()