|
| 1 | +from utils.parser_utils import * |
| 2 | + |
| 3 | +from run_parser import LILAC, LogBatcher, DivLog, LogPrompt, SelfLog, OpenLogParser, LLM_TD |
| 4 | +from run_parser import Drain, ULP, Brain, SPELL, AEL |
| 5 | + |
| 6 | +from utils.evaluate import evaluate_metrics |
| 7 | +from itertools import product |
| 8 | + |
| 9 | +def evaluate(dataset, parser, out_dir, corrected_LogHub=True,): |
| 10 | + limit = 2000 |
| 11 | + input_dir = params["in_dir"] |
| 12 | + print(f"--- {dataset} - {parser}", flush=True) |
| 13 | + corrected_str = "_corrected" if corrected_LogHub else "" |
| 14 | + groundtruth_path = os.path.join(input_dir, dataset, f"{dataset}_{params["dataset_type"]}.log_structured{corrected_str}.csv") |
| 15 | + result_path = os.path.join(out_dir, f"{dataset}_{params["dataset_type"]}.log_structured.csv") |
| 16 | + #result_path = os.path.join(OUTPUT_FOLDER, parser, f"{dataset}_{params["dataset_type"]}.log_structured.csv") |
| 17 | + if not os.path.exists(result_path): |
| 18 | + print("Path doesn't exist:", result_path) |
| 19 | + raise FileNotFoundError |
| 20 | + df_result = evaluate_metrics(dataset, groundtruth_path, result_path, limit=limit) |
| 21 | + return df_result |
| 22 | + |
| 23 | +parsers = { |
| 24 | + # baseline |
| 25 | + "Drain": Drain, |
| 26 | + # "ULP": ULP, |
| 27 | + "Brain": Brain, |
| 28 | + "SPELL": SPELL, |
| 29 | + "AEL": AEL, |
| 30 | + # unsupervised parsers |
| 31 | + # "OpenLogParser": OpenLogParser, |
| 32 | + # # "LogPrompt": LogPrompt, |
| 33 | + # "LLM_TD": LLM_TD, |
| 34 | + # "LogBatcher": LogBatcher, |
| 35 | + # # supervised parsers |
| 36 | + # "SelfLog": SelfLog, |
| 37 | + # "LILAC-2": LILAC, |
| 38 | + # "LILAC-4": LILAC, |
| 39 | + # "DivLog-2": DivLog, |
| 40 | + # "DivLog-4": DivLog, |
| 41 | +} |
| 42 | + |
| 43 | +multiple_runs_list = list(parsers.keys()) |
| 44 | + |
| 45 | +datasets = [ |
| 46 | + # 'Android', |
| 47 | + # 'Apache', |
| 48 | + # 'BGL', |
| 49 | + # 'HDFS', |
| 50 | + # 'HPC', |
| 51 | + # 'Hadoop', |
| 52 | + # 'HealthApp', |
| 53 | + # 'Linux', |
| 54 | + # 'Mac', |
| 55 | + # 'OpenSSH', |
| 56 | + # 'OpenStack', |
| 57 | + # 'Proxifier', |
| 58 | + # 'Spark', |
| 59 | + # 'Thunderbird', |
| 60 | + # 'Windows', |
| 61 | + # 'Zookeeper', |
| 62 | + "Audit" # custom |
| 63 | +] |
| 64 | + |
| 65 | +model = "no-LLM" |
| 66 | +# model = "gpt-3.5-turbo" # openai api |
| 67 | +# model="deepseek-ai/DeepSeek-R1" # togetherai api |
| 68 | +# model = "deepseek-reasoner" # deepseek api |
| 69 | +# model = "codellama:7b-instruct" # ollama local api |
| 70 | + |
| 71 | +dataset_type = "2k" |
| 72 | + |
| 73 | +total_runs = 1 |
| 74 | + |
| 75 | +gs_params = { |
| 76 | + "Drain": { |
| 77 | + "depth": [4,5,6,7,8,9,10,11,12,13,14], |
| 78 | + "st": [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9], |
| 79 | + }, |
| 80 | + "Brain": { |
| 81 | + "threshold": [2,3,4,5,6,7,8,9,10], |
| 82 | + }, |
| 83 | + "AEL": { |
| 84 | + "minEventCount": [1,2,3,4,5,6,7,8,9,10,11,12], |
| 85 | + "merge_percent": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], |
| 86 | + }, |
| 87 | + "SPELL": { |
| 88 | + "tau": [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95, 0.99], |
| 89 | + }, |
| 90 | +} |
| 91 | + |
| 92 | +params = { |
| 93 | + #"in_dir": DATA_FOLDER + "2k/", |
| 94 | + "in_dir": DATA_FOLDER + f"{dataset_type}/", |
| 95 | + "settings": settings, |
| 96 | + "dataset_type": dataset_type, |
| 97 | + "model": model, |
| 98 | + "log_format": True, |
| 99 | + "corrected_LH": True ### ATTENTION !!!!!! ### |
| 100 | +} |
| 101 | + |
| 102 | +if __name__ == "__main__": |
| 103 | + output_folder = OUTPUT_FOLDER[:-1] + "-GridSearch/" |
| 104 | + for dataset in datasets: # per dataset |
| 105 | + params["dataset"] = dataset |
| 106 | + for parser_name, parser in parsers.items(): # per parser |
| 107 | + # Generate grid search combinations for the current parser |
| 108 | + param_grid = gs_params[parser_name] |
| 109 | + param_combinations = list(product(*param_grid.values())) |
| 110 | + param_names = list(param_grid.keys()) |
| 111 | + |
| 112 | + gs_results = [] |
| 113 | + |
| 114 | + for i, param_values in enumerate(param_combinations): # per parameter combination |
| 115 | + param_dict = dict(zip(param_names, param_values)) |
| 116 | + if parser_name in ["Drain"]: |
| 117 | + params["settings"]["Audit"].update(param_dict) |
| 118 | + else: |
| 119 | + params["settings"][f"{parser_name}_settings"]["Audit"].update(param_dict) |
| 120 | + |
| 121 | + run_dir = f"run{"_".join([f"{k}_{v}" for k, v in param_dict.items()])}" |
| 122 | + print(f"Running {parser_name} on {dataset}") |
| 123 | + out_dir = os.path.join(output_folder, model, parser_name, run_dir) |
| 124 | + params["out_dir"] = out_dir |
| 125 | + if not os.path.exists(out_dir): |
| 126 | + os.makedirs(out_dir) |
| 127 | + |
| 128 | + runtime, invoc_time = parser.parse(**params) |
| 129 | + |
| 130 | + df_result = evaluate(dataset, parser_name, out_dir, corrected_LogHub=params["corrected_LH"]) |
| 131 | + df_result["params"] = [param_dict] |
| 132 | + |
| 133 | + print(df_result) |
| 134 | + |
| 135 | + gs_results.append(df_result) |
| 136 | + |
| 137 | + gs_results_all = pd.concat(gs_results, ignore_index=True) |
| 138 | + # gs_results_all = gs_results_all.sort_values(by=["GA"], ascending=False) |
| 139 | + gs_results_all.to_csv(os.path.join(output_folder, parser_name + "_gs_results.csv"), index=False) |
| 140 | + print("Grid search results saved to:", os.path.join(output_folder, parser_name + "_gs_results.csv")) |
| 141 | + |
0 commit comments