forked from NetManAIOps/LogClass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_params.py
214 lines (207 loc) · 5.85 KB
/
init_params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import os
import argparse
from uuid import uuid4
import sys
def init_main_args():
"""Init command line args used for configuration."""
parser = argparse.ArgumentParser(
description="Runs experiment using LogClass Framework",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--raw_logs",
metavar="raw_logs",
type=str,
nargs=1,
help="input raw logs file path",
)
base_dir_default = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "output"
)
parser.add_argument(
"--base_dir",
metavar="base_dir",
type=str,
nargs=1,
default=[base_dir_default],
help="base output directory for pipeline output files",
)
parser.add_argument(
"--logs",
metavar="logs",
type=str,
nargs=1,
help="input logs file path and output for raw logs preprocessing",
)
parser.add_argument(
"--models_dir",
metavar="models_dir",
type=str,
nargs=1,
help="trained models input/output directory path",
)
parser.add_argument(
"--features_dir",
metavar="features_dir",
type=str,
nargs=1,
help="trained features_dir input/output directory path",
)
parser.add_argument(
"--logs_type",
metavar="logs_type",
type=str,
nargs=1,
default=["open_Apache"],
choices=[
"bgl",
"open_Apache",
"open_bgl",
"open_hadoop",
"open_hdfs",
"open_hpc",
"open_proxifier",
"open_zookeeper",
],
help="Input type of logs.",
)
parser.add_argument(
"--kfold",
metavar="kfold",
type=int,
nargs=1,
help="kfold crossvalidation",
)
parser.add_argument(
"--healthy_label",
metavar='healthy_label',
type=str,
nargs=1,
default=["unlabeled"],
help="the labels of unlabeled logs",
)
parser.add_argument(
"--features",
metavar="features",
type=str,
nargs='+',
default=["tfilf"],
choices=["tfidf", "tfilf", "length", "tf"],
help="Features to be extracted from the logs messages.",
)
parser.add_argument(
"--report",
metavar="report",
type=str,
nargs='+',
default=["confusion_matrix"],
choices=["confusion_matrix",
"acc",
"multi_acc",
"top_k_svm",
"micro",
"macro"
],
help="Reports to be generated from the model and its predictions.",
)
parser.add_argument(
"--binary_classifier",
metavar="binary_classifier",
type=str,
nargs=1,
default=["pu_learning"],
choices=["pu_learning", "regular"],
help="Binary classifier to be used as anomaly detector.",
)
parser.add_argument(
"--multi_classifier",
metavar="multi_classifier",
type=str,
nargs=1,
default=["svm"],
choices=["svm"],
help="Multi-clas classifier to classify anomalies.",
)
parser.add_argument(
"--train",
action="store_true",
default=False,
help="If set, logclass will train on the given data. Otherwise"
+ "it will run inference on it.",
)
parser.add_argument(
"--force",
action="store_true",
default=False,
help="Force training overwriting previous output with same id.",
)
parser.add_argument(
"--id",
metavar="id",
type=str,
nargs=1,
help="Experiment id. Automatically generated if not specified.",
)
parser.add_argument(
"--swap",
action="store_true",
default=False,
help="Swap testing/training data in kfold cross validation.",
)
return parser
def parse_main_args(args):
"""Parse provided args for runtime configuration."""
params = {
"report": args.report,
"train": args.train,
"force": args.force,
"base_dir": args.base_dir[0],
"logs_type": args.logs_type[0],
"healthy_label": args.healthy_label[0],
"features": args.features,
"binary_classifier": args.binary_classifier[0],
"multi_classifier": args.multi_classifier[0],
"swap": args.swap,
}
if args.raw_logs:
params["raw_logs"] = os.path.normpath(args.raw_logs[0])
if args.kfold:
params["kfold"] = args.kfold[0]
if args.logs:
params['logs'] = os.path.normpath(args.logs[0])
else:
params['logs'] = os.path.join(
params['base_dir'],
"preprocessed_logs",
f"{params['logs_type']}.txt"
)
if args.id:
params['id'] = args.id[0]
else:
params['id'] = str(uuid4().time_low)
print(f"\nExperiment ID: {params['id']}")
# Creating experiments results folder with the format
# {experiment_module_name}_{logs_type}_{id}
experiment_name = os.path.basename(sys.argv[0]).split('.')[0]
params['id_dir'] = os.path.join(
params['base_dir'],
'_'.join((
experiment_name, params['logs_type'], params['id']
))
)
if args.models_dir:
params['models_dir'] = os.path.normpath(args.models_dir[0])
else:
params['models_dir'] = os.path.join(
params['id_dir'],
"models",
)
if args.features_dir:
params['features_dir'] = os.path.normpath(args.features_dir[0])
else:
params['features_dir'] = os.path.join(
params['id_dir'],
"features",
)
params['results_dir'] = os.path.join(params['id_dir'], "results")
return params