added logging
This commit is contained in:
26
collect.py
26
collect.py
@@ -7,6 +7,7 @@ import shutil
|
|||||||
import socket
|
import socket
|
||||||
import platform
|
import platform
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -287,16 +288,23 @@ def collect_data(minutes):
|
|||||||
|
|
||||||
print(f" {i}", end="", flush=True)
|
print(f" {i}", end="", flush=True)
|
||||||
|
|
||||||
|
logging.info("running zpool iostat")
|
||||||
zpoolIostat()
|
zpoolIostat()
|
||||||
|
logging.info("running ifstat")
|
||||||
ifstat()
|
ifstat()
|
||||||
|
|
||||||
if is_debian():
|
if is_debian():
|
||||||
|
logging.info("running iostat_cpu")
|
||||||
scaleIostat_cpu()
|
scaleIostat_cpu()
|
||||||
|
logging.info("running iostat_disk")
|
||||||
scaleIostat_disk()
|
scaleIostat_disk()
|
||||||
|
logging.info("running memstat")
|
||||||
scaleMemstat()
|
scaleMemstat()
|
||||||
|
|
||||||
if is_freebsd():
|
if is_freebsd():
|
||||||
|
logging.info("running cpustat")
|
||||||
coreCPUstat()
|
coreCPUstat()
|
||||||
|
logging.info("running memstat")
|
||||||
coreMemstat()
|
coreMemstat()
|
||||||
|
|
||||||
# gives same data each interval
|
# gives same data each interval
|
||||||
@@ -305,6 +313,7 @@ def collect_data(minutes):
|
|||||||
if i == minutes:
|
if i == minutes:
|
||||||
print("")
|
print("")
|
||||||
print("")
|
print("")
|
||||||
|
logging.info("collection over")
|
||||||
break
|
break
|
||||||
|
|
||||||
time.sleep(55)
|
time.sleep(55)
|
||||||
@@ -312,6 +321,7 @@ def collect_data(minutes):
|
|||||||
|
|
||||||
def run_debug():
|
def run_debug():
|
||||||
print("Taking new debug.")
|
print("Taking new debug.")
|
||||||
|
logging.info("taking debug")
|
||||||
command = ["midclt", "call", "system.debug_generate", "-job"]
|
command = ["midclt", "call", "system.debug_generate", "-job"]
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
||||||
@@ -388,6 +398,12 @@ def welcome():
|
|||||||
def main():
|
def main():
|
||||||
welcome()
|
welcome()
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
filename="perf.log",
|
||||||
|
level=logging.DEBUG,
|
||||||
|
format="%(asctime)s %(levelname)s %(message)s",
|
||||||
|
)
|
||||||
|
|
||||||
# setup argparse
|
# setup argparse
|
||||||
parser = argparse.ArgumentParser(description="TrueNAS Performance Capture Script")
|
parser = argparse.ArgumentParser(description="TrueNAS Performance Capture Script")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -416,6 +432,8 @@ def main():
|
|||||||
f"Set to wait {minutesToWait} minutes and then capture for {minutes} minutes."
|
f"Set to wait {minutesToWait} minutes and then capture for {minutes} minutes."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logging.info(f"SETUP: {minutesToWait}m delay, {minutes}m of capture.")
|
||||||
|
|
||||||
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):
|
||||||
@@ -424,11 +442,12 @@ def main():
|
|||||||
print("")
|
print("")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("")
|
print("")
|
||||||
print("Caught control-c, exiting...")
|
logging.info("Caught control-c, exiting...")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("Starting Collection")
|
print("Starting Collection")
|
||||||
|
logging.info("Starting Collection")
|
||||||
# Collect data
|
# Collect data
|
||||||
if is_freebsd():
|
if is_freebsd():
|
||||||
# timeout = f"{minutes}m"
|
# timeout = f"{minutes}m"
|
||||||
@@ -442,11 +461,14 @@ def main():
|
|||||||
"15s",
|
"15s",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
logging.info("opening gstat.csv")
|
||||||
gstatData = open("gstat.csv", "ab")
|
gstatData = open("gstat.csv", "ab")
|
||||||
|
logging.info("opening gstat.err")
|
||||||
gstatError = open("gstat.err", "a")
|
gstatError = open("gstat.err", "a")
|
||||||
|
|
||||||
# with as output_file:
|
# with as output_file:
|
||||||
# # Create a Popen object with stdout redirected to the file
|
# # Create a Popen object with stdout redirected to the file
|
||||||
|
logging.info("starting Popen")
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
gstat_command, stdout=gstatData, stderr=gstatError
|
gstat_command, stdout=gstatData, stderr=gstatError
|
||||||
)
|
)
|
||||||
@@ -455,6 +477,7 @@ def main():
|
|||||||
|
|
||||||
# # kill gstat if freebsd
|
# # kill gstat if freebsd
|
||||||
if is_freebsd():
|
if is_freebsd():
|
||||||
|
logging.info("killing gstat")
|
||||||
process.terminate()
|
process.terminate()
|
||||||
|
|
||||||
gstatData.flush()
|
gstatData.flush()
|
||||||
@@ -467,6 +490,7 @@ def main():
|
|||||||
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():
|
||||||
|
logging.info("killing gstat")
|
||||||
process.terminate()
|
process.terminate()
|
||||||
|
|
||||||
gstatData.flush()
|
gstatData.flush()
|
||||||
|
|||||||
Reference in New Issue
Block a user