File Parsing Plugin
The File Parsing Plugin (files.py) scans directories for log files, extracts metrics using configuration-driven regular expressions, applies transformations, filters, and aggregations, and writes structured LML files (for LLview's dbupdate action) or CSV files.
It typically runs periodically on LLview Server (or on LLview Remote / a system node if the target log directories are only mounted there), using a tracker file to process only newly generated logs.
Command-Line Interface
| Flag | Required | Default | Description |
|---|---|---|---|
--config <file> |
Yes | — | Path to the YAML configuration file. |
--loglevel <level> |
No | INFO |
Logging verbosity (DEBUG, INFO, WARNING, ERROR, CRITICAL). |
--outfolder <dir> |
No | — | Base output directory prepended to relative file paths in the output section (created automatically if missing). |
Processing Pipeline
Each top-level group (<group_name>) in the YAML configuration is processed sequentially in the following order:
- File Discovery & Tracker Filtering:
- Expands environment variables,
~, andstrftimedate placeholders infolderaccording totimeframe. - If
processed_filesis configured, loads previously seen file paths, intersects them with currently discoverable files, and filters down to only new files (all_discoverable_files - seen_files).
- Expands environment variables,
- Regex Extraction (
FileParser.parse_file_content):- Pre-compiles all regular expressions defined under
metrics. - Evaluates
from: filenamemetrics against the base filename (filepath.name) to populate initialfile_contextdata. - Reads each new file line by line (UTF-8 with replacement on decode errors), updating
file_contextvalues whenscope: file_contextmetrics match and merging a copy of the currentfile_contextinto every matchingline-scoped record.
- Pre-compiles all regular expressions defined under
- Transformation & Filtering (
FileParser.process_transformed_records):- Runs Python transformation functions listed in
apply(such asto_timestamp); records are dropped if a configured transform fails, is undefined, or ifto_timestampreturnsNonefrom a non-Nonevalue. - Evaluates
excludeandincluderegex rules against the (possibly transformed) values, dropping records that matchexcludeor fail to matchinclude.
- Runs Python transformation functions listed in
- Aggregation & Output Generation (
OutputAggregator.generate_outputs):- Combines kept records from all new files in the group and dispatches each
outputspecification bymode(file,entry, or a custom_output_<mode>handler). - Writes
.csvor.xml(LML) files. When LML outputs are configured, output generation still runs even if 0 new files were found, producing an LML file with apstatmetadata object reportingnelems="0".
- Combines kept records from all new files in the group and dispatches each
- Tracker Update:
- Updates
processed_fileswith the sorted, resolved paths of previously seen and newly succeeded files that remain discoverable (pruning stale entries when necessary).
- Updates
Configuration Reference
Group Options (<group_name>)
Each top-level YAML key defines a logical group of input files and its corresponding outputs. Groups missing folder, metrics, or output are skipped.
| Key | Type | Default | Description |
|---|---|---|---|
folder |
string |
— | Path or strftime template for input log files (required). Supports environment variables and ~. |
timeframe |
int |
0 |
Number of past days (including today) to scan with strftime. 0 enables literal path or directory-pattern discovery. |
processed_files |
string |
— | Path to a tracker file storing already processed file paths (supports env vars and ~). |
metrics |
list |
— | List of metric extraction definitions (required). |
output |
list |
— | List of output file specifications (required). |
Metric Options (metrics[])
Each entry in metrics defines a regex extraction rule—either a simple metric (with name, capturing group 1) or a grouped metric (without name, using named regex capture groups (?P<key>...)).
| Key | Type | Default | Description |
|---|---|---|---|
regex |
string |
— | Python regular expression (required). Simple metrics must include capture group 1; grouped metrics use named capture groups. |
name |
string |
— | Metric name for simple metrics (omit for grouped metrics using named capture groups). |
scope |
string |
'line' |
'line' (produces/augments a line record) or 'file_context' (merged into all line records from the same file). |
from |
string |
'content' |
'content' (matched against each line) or 'filename' (matched against the base filename; intended for scope: file_context). |
apply |
dict |
— | Map of {<metric_or_group_name>: "<func_name>"} specifying Python transformation functions (e.g., to_timestamp). |
include |
string / list / dict |
— | Regex pattern(s) (re.search) a value must match to keep the record. Dict keyed by group name for grouped metrics. |
exclude |
string / list / dict |
— | Regex pattern(s) (re.search) that drop the record if matched. Dict keyed by group name for grouped metrics. |
default |
any / dict |
— | Fallback value (or {<group_name>: <value>} dict for grouped metrics) used when a key is missing in a record. |
Output Options (output[])
Each entry in output generates a single .csv or .xml (LML) file. Unsupported extensions are skipped.
| Key | Type | Default | Description |
|---|---|---|---|
file |
string |
— | Output file path (required). Extension (.csv or .xml) determines format; relative paths are resolved against --outfolder. |
mode |
string |
— | Output mode (required): 'file', 'entry', or a custom handler name (_output_<mode>). |
index |
string |
— | Metric name used as the grouping key (file mode), CSV ID base (entry mode), or LML <object name="..."> (required). |
fields |
dict |
— | Dictionary mapping <output_column> names to field extraction/aggregation rules (required). |
prefix |
string |
'i' |
(LML .xml only) Prefix for auto-generated <object id="..."> attributes (e.g., msg001). |
type |
string |
'item' |
(LML .xml only) Entity type written to <object type="..."> and __nelems_<type>. |
Field Options (fields.<column_name>)
Each key under fields defines an output column in CSV or <data key="..."> tag in LML. If a column name equals index and omits source, static, and aggregate, it receives the index value (file mode) or <index>_<counter> (entry mode for CSV).
| Key | Type | Default | Description |
|---|---|---|---|
source |
string |
— | Metric name to read from (or to aggregate over when aggregate is also set). |
aggregate |
string |
— | (file mode only) Aggregation applied to source: 'count', 'min', 'max', or 'avg'. |
unique |
bool |
false |
(file mode only) Deduplicates values before joining (source) or counts only distinct non-None values (aggregate: count). |
joiner |
string |
'' |
(file mode only) Separator string used to join multiple line-scoped source values. |
wrap |
string |
'{}' |
(file mode only) Python .format() template applied to each source value or final aggregate result (e.g., '{:.2f}%'). |
static |
any |
— | Fixed constant value written to the column for every output row. |
File Discovery, Filtering & Aggregations
Path Discovery (folder and timeframe)
| Setting | Behavior | Example |
|---|---|---|
timeframe > 0 |
Evaluates folder with strftime for each of the past timeframe days (including today) and scans recursively with rglob('*'). |
/var/logs/%Y/%m/%d with timeframe: 2 |
timeframe: 0 (no %) |
Treats folder as a literal file path or scans a literal directory recursively with rglob('*'). |
/var/logs/app/ |
timeframe: 0 (with %) |
Walks directory segments containing % by validating directory names with datetime.strptime, then scans matching directories with rglob('*'). |
/var/logs/%Y/%m/%d with timeframe: 0 |
Simple vs. Grouped Metrics & Transformations
- Simple Metrics: Specify
nameand a regex with one unnamed capture group ((...)).apply,include,exclude, anddefaulttarget the metric directly. - Grouped Metrics: Omit
nameand use named capture groups ((?P<metric_a>...)).apply,include,exclude, anddefaultare specified as dictionaries keyed by the capture group names. - Built-in Transformation (
to_timestamp): Converts ISO 8601 strings (e.g.,2025-05-24T14:27:55+02:00or trailingZ) into integer Unix epoch timestamps. If parsing fails on a non-Nonevalue, the record is discarded.
Built-in aggregate Functions (mode: file)
When aggregate is specified alongside source, records grouped by index are reduced to a single value per group:
| Method | Behavior |
|---|---|
count |
Counts non-None occurrences of source (or unique non-None values when unique: true). Optional wrap formatting applies. |
min |
Converts non-None values to float (skipping non-numeric values with a warning) and returns the minimum, formatted with wrap if set, or "" if none are numeric. |
max |
Converts non-None values to float and returns the maximum (same error handling and wrap behavior as min). |
avg |
Converts non-None values to float and returns the arithmetic mean (same error handling and wrap behavior as min). |
Output Modes & LML Generation
fileMode: Groups all kept records byindex(skipping records whereindexisNone). Metrics matchingindexor havingscope: file_contextare treated as singular (taken from the first record in the group);line-scopedsourcemetrics collect all non-Nonevalues, optionally deduplicate (unique: true), format each withwrap, and concatenate withjoiner.entryMode: Emits one row per kept log record. In CSV output, a column matchingindexwithoutsource/staticreceives<index>_<counter>. In LML output, the rawindexvalue populates<object name="...">without adding an extra<data>tag unless explicitly listed underfields.- Custom Modes: Any other
modevalue invokes a global function_output_<mode>(aggregator, spec)returning(rows, headers). - CSV & LML (
.xml) Details:- If a non-XML output yields 0 rows but has column headers, a header-only
.csvfile is written. - For
.xmloutputs, duplicate LML<object name="...">values are automatically disambiguated with_2,_3, etc., and double quotes in string<data>values are escaped as". - Every LML output automatically includes a
pstatobject (name="get<group_name>",oid="pstat_get<group_name>_<type>") recordingstartts,datats,endts,duration,nelems, and__nelems_<type>.
- If a non-XML output yields 0 rows but has column headers, a header-only
Example Configurations
A reference healthchecker configuration is maintained in the LLview configuration repository:
Log Aggregation & LML Output Example
node_errors:
folder: '/var/log/healthchecker/%Y/%m/%d'
timeframe: 2
processed_files: '${LLVIEW_DATA}/seen_hc_files.txt'
metrics:
# Extract job ID from the log filename as file-wide context
- name: jobid
from: filename
scope: file_context
regex: '^job_(\d+)\.log$'
# Extract timestamp, node, severity, and numeric duration per log line
- regex: '^(?P<msgdate>\S+)\s+(?P<node>\S+)\s+(?P<level>\w+):\s+(?P<msg>.*?)(?:\s+latency=(?P<latency>\d+\.?\d*)ms)?$'
apply:
msgdate: to_timestamp
exclude:
level: '^DEBUG$'
default:
latency: 0
output:
# One LML object per matching log line
- file: 'nodes_errmsg_LML.xml'
mode: entry
prefix: msg
type: nodeerr
index: node
fields:
SLURM_JOBID:
source: jobid
HOSTNAME:
source: node
MESSAGE:
source: msg
timestamp:
source: msgdate
GID:
static: 0
# Summary CSV aggregated per node
- file: 'nodes_summary.csv'
mode: file
index: node
fields:
node: {}
jobs:
source: jobid
unique: true
joiner: ','
error_count:
aggregate: count
source: msg
avg_latency_ms:
aggregate: avg
source: latency
wrap: '{:.2f}'