Log Clustering¶
This script computes clusters of similar log lines from the provided log files. It uses the drain3 library to extract templates from log lines. It can filter log lines based on a regex pattern and display the clusters.
compute_margin_for_display(max_number)
¶
Compute the margin for displaying numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_number
|
int
|
The maximum number to display. |
required |
Source code in src/gool/log_clustering.py
138 139 140 141 142 143 144 145 146 147 148 149 | |
create_config_file_if_needed(home_config)
¶
Create default config file if does not exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
home_config
|
Path
|
path of the default config file |
required |
Source code in src/gool/log_clustering.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
create_file_line_generators(logfile_paths, progress)
¶
Create progress tasks for all files and return a chained generator yielding lines from all files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logfile_paths
|
tuple[Path, ...]
|
Paths to the log files. |
required |
progress
|
Progress
|
The progress instance to track file processing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Generator |
chain
|
A single generator yielding lines from all files. |
Source code in src/gool/log_clustering.py
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 | |
display_clusters(template_miner, order_by='count', raw=False, table_title='Log Clusters')
¶
Display all clusters in a table with 3 columns: Count - Char Size (KB) - Template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_miner
|
LogsMiner
|
The logs miner which has run. |
required |
order_by
|
str
|
How to order clusters: "count", "size", or "template". Defaults to "count". |
'count'
|
raw
|
bool
|
display the data without rich if true. |
False
|
table_title
|
str
|
title of the table displayed on top. |
'Log Clusters'
|
Source code in src/gool/log_clustering.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
display_diff_baseline(missing, added, common, raw=False, display_common=False)
¶
Display the difference between baseline clusters and current clusters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
missing
|
list[str]
|
Clusters present in baseline but missing in current. |
required |
added
|
list[str]
|
Clusters present in current but missing in baseline. |
required |
common
|
list[str]
|
Clusters present in both baseline and current. |
required |
raw
|
bool
|
If True, display in plain text format for bash processing. Defaults to False. |
False
|
display_common
|
bool
|
If True, also display common clusters. Defaults to False. |
False
|
Source code in src/gool/log_clustering.py
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 | |
estimate_lines(path, nb_sample_lines=1000)
¶
Estimate total lines based on file size and sample average. Args: path (pathlib.Path): Path to the log file. nb_sample_lines (int): Number of lines to sample for average calculation.
Source code in src/gool/log_clustering.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
main(args)
¶
Extract the cluster templates from the provided log files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Arguments
|
paths and options for the log extractor |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
0 if everything went well |
Source code in src/gool/log_clustering.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
main_cli()
¶
Main entry point for the CLI.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Exit code. |
Source code in src/gool/log_clustering.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
sanity_check(total_nb_lines_clusters, total_nb_lines)
¶
Check if the total number of lines in clusters matches the processed lines.
Source code in src/gool/log_clustering.py
312 313 314 315 316 317 318 319 320 321 322 323 324 | |
surrogate_non_printable(s)
¶
Surrogate non-printable characters from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
The input string. |
required |
Returns: str: The cleaned string.
Source code in src/gool/log_clustering.py
126 127 128 129 130 131 132 133 134 135 | |