diff --git a/collect.py b/collect.py index d496fcf..f878dcc 100644 --- a/collect.py +++ b/collect.py @@ -82,29 +82,28 @@ def scaleIostat_cpu(): print(f"Error running command: {collect}") -def coreIostat_cpu(): - command = ["iostat", "-c", "1", "1"] - filename = "cpuStat.csv" +def ifstat(): + command = ["ifstat", "-znq", "1", "1"] + filename = "ifStat.csv" collect = runCollect(command) - if collect: - byline = re.split("\n", collect.strip()) - data = byline[3].strip() - lineData = data.split() + # process collection string + bylines = collect.split("\n") + interfaces = bylines[0].split() + stats = bylines[2].split() - if lineData: - with open(filename, "a", newline="") as csvfile: - csv_writer = csv.writer(csvfile) - lineData.insert(0, "cpu") - lineData.insert(0, getTimestamp()) - csv_writer.writerow(lineData) - - else: - print(f"Error running command: {collect}") + for nic in interfaces: + lineData = [getTimestamp(), nic, stats.pop(0), stats.pop(0)] + if lineData: + with open(filename, "a", newline="") as csvfile: + csv_writer = csv.writer(csvfile) + csv_writer.writerow(lineData) + else: + print(f"Error running command: {collect}") -def coreifstat(): +def coreCPUstat(): command = ["iostat", "-C", "-t", "proc", "-d"] filename = "cpuStat.csv" @@ -194,14 +193,14 @@ def collect_data(minutes, interval): print(f" {i}", end="") zpoolIostat() - coreifstat() + ifstat() if is_debian(): scaleIostat_cpu() scaleIostat_disk() if is_freebsd(): - coreIostat_cpu() + coreCPUstat() if i == minutes: break @@ -209,6 +208,7 @@ def collect_data(minutes, interval): time.sleep(interval) print("") + # kill gstat if freebsd if is_freebsd(): process.kill()