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
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():
command = ["iostat", "-xyd", "1", "1"]
filename = "ioStat.csv"
@@ -212,7 +234,7 @@ def coreCPUstat():
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)
if collect:
@@ -276,13 +298,14 @@ def collect_data(minutes):
if is_freebsd():
coreCPUstat()
coreMemstat()
coreIostat_disk()
if i == minutes:
print("")
print("")
break
time.sleep(45)
time.sleep(55)
def run_debug():
@@ -410,40 +433,40 @@ 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",
# ]
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, stdout=output_file)
collect_data(minutes)
# kill gstat if freebsd
if is_freebsd():
process.terminate()
process.kill()
# # kill gstat if freebsd
# 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()