|
1 | 1 | from abc import ABC, abstractmethod |
2 | 2 | import atexit |
3 | 3 | import heapq |
| 4 | +import logging |
4 | 5 | import math |
5 | 6 | import os |
6 | 7 | import shutil |
@@ -184,22 +185,36 @@ def create_event_queue( |
184 | 185 | sorted_by_end_path = os.path.join(out_dir, "flows_sorted_by_end.csv") |
185 | 186 | sorted_by_export_path = os.path.join(out_dir, "flows_sorted_by_export.csv") |
186 | 187 |
|
| 188 | + with open(flows_path, "r") as f: |
| 189 | + header_line = f.readline() |
| 190 | + |
| 191 | + wanted_columns = set(CSV_COLUMN_TYPES.keys()) |
| 192 | + available_columns = set(header_line.strip().split(",")) |
| 193 | + |
187 | 194 | # Load and split |
188 | 195 | df = pd.read_csv( |
189 | 196 | flows_path, |
190 | 197 | dtype=CSV_COLUMN_TYPES, |
191 | | - usecols=CSV_COLUMN_TYPES.keys(), |
| 198 | + usecols=wanted_columns & available_columns, |
192 | 199 | engine="pyarrow", |
193 | 200 | ) |
194 | 201 |
|
195 | 202 | # Filer host stats file by time |
196 | 203 | start = math.floor(df["START_TIME"].min() / 1000) |
197 | 204 | end = math.ceil(df["END_TIME"].max() / 1000) |
198 | 205 |
|
199 | | - stats_df: pd.DataFrame = pd.read_csv( |
200 | | - hosts_stats_file, sep=";", dtype=STATS_CSV_COLUMN_TYPES, engine="pyarrow" |
201 | | - ) |
202 | | - stats_df = stats_df[(stats_df["Time"] >= start) & (stats_df["Time"] <= end)] |
| 206 | + try: |
| 207 | + stats_df: pd.DataFrame = pd.read_csv( |
| 208 | + hosts_stats_file, |
| 209 | + sep=";", |
| 210 | + dtype=STATS_CSV_COLUMN_TYPES, |
| 211 | + engine="pyarrow", |
| 212 | + usecols=STATS_CSV_COLUMN_TYPES.keys(), |
| 213 | + ) |
| 214 | + stats_df = stats_df[(stats_df["Time"] >= start) & (stats_df["Time"] <= end)] |
| 215 | + except Exception as e: |
| 216 | + logging.error(e) |
| 217 | + stats_df = pd.DataFrame([], columns=STATS_CSV_COLUMN_TYPES.keys()) |
203 | 218 |
|
204 | 219 | agg_dict = {col: "sum" for col in SUM_PIDSTAT_COLS} |
205 | 220 | agg_dict.update({col: "first" for col in TAKE_PIDSTAT_COLS}) |
|
0 commit comments