MetricsHub
MetricsHub Community Connectors 1.0.24
-
Home
- Connector Developer Guide Computes 27
excludeMatchingLines (Compute)
When To Use
Use excludeMatchingLines to drop unwanted rows from a source table: aggregate rows such as _Total in Windows performance counters, removable media in a disk listing, or, in a collect job, N/A readings on rows that carry nothing else. It is the table equivalent of grep -v: rows that match are discarded, all other rows pass through unchanged.
To do the opposite (keep only matching rows), use keepOnlyMatchingLines[1].
Syntax
sources:
physicalDisks:
type: commandLine
commandLine: ${file::diskpart-list.bat}
computes:
- type: excludeMatchingLines
column: 4
valueList: CD-ROM,DVD-ROM,Removable
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | excludeMatchingLines. |
column |
Yes | None | 1-based index of the column tested on each row. |
regExp |
No | None | Case-insensitive regular expression. A row is removed when the regex is found anywhere in the column value (unanchored, like grep); use ^ and $ to force a full match. Follows PSL regex conventions: alternation is a backslash-escaped pipe, as in keepOnlyMatchingLines. Can be set from a connector variable, e.g. ${var::excludedDevices}. |
valueList |
No | None | Comma-separated list of exact values, e.g. CD-ROM,DVD-ROM,Removable. A row is removed when the column value equals one of the listed values (case-insensitive, whole-value comparison). |
Provide regExp, valueList, or both. When both are specified, both filters are applied one after the other: a row is removed if it matches the regExp or its value is in the valueList (only rows that pass both filters survive).
Table Transformation Example
With column: 4 and valueList: CD-ROM,DVD-ROM,Removable:
Input
| ID | Model | Size | Type |
|---|---|---|---|
| 0 | Samsung SSD 990 | 1000 GB | Fixed |
| 1 | Kingston DT USB | 64 GB | Removable |
| 2 | Virtual DVD | 0 GB | DVD-ROM |
| 3 | WDC WD40EFRX | 4000 GB | Fixed |
Result
| ID | Model | Size | Type |
|---|---|---|---|
| 0 | Samsung SSD 990 | 1000 GB | Fixed |
| 3 | WDC WD40EFRX | 4000 GB | Fixed |
Recommended Pattern
- Exclude noise early in the
computespipeline (aggregate rows, removable media, rows of another class) so later computes and the mapping only see real hardware. - In a
discoveryorsimplejob, whose rows create the instances, exclude on a type or a class only. A value or a state that can change (N/Aor all-zero readings, a size of0,Disabled) removes the instance as soon as it matches (MetricsHub Community 3.9.08 or later, see When Instances Are Removed[2]). Blank such a value instead of dropping the row, or setremovalDelay[3] on the monitor. - In a
collectjob, dropping a row also drops the status and the other metrics it carries. When the row holds more than the unwanted value, blank the value instead: anawk[4] compute that empties the reading column, or areplace[5] compute when the exact value is known. Exclude the row only when it carries nothing but that value. - Prefer
valueListwhen the unwanted values are a fixed set of literals; useregExpfor actual patterns, e.g.regExp: ^[0.]+$to drop all-zero readings from rows that carry nothing else. - Chain one
excludeMatchingLinesper column when you need to filter on several columns.
Common Mistakes
- Excluding a value or a state (
N/A,0,Disabled) in adiscoveryorsimplejob: the instance is removed when the value matches, and comes back with fresh counters when it no longer does. - Forgetting that
regExpis unanchored:regExp: 5removes every row whose column merely contains5— usevalueList: 5orregExp: ^5$to remove exact values only. - Expecting
valueListentries to support wildcards; they are literal values only (the comparison is case-insensitive, though). - Using
excludeMatchingLineswith a long value list when an anchoredkeepOnlyMatchingLineson the wanted values would be shorter and safer. - Counting columns from 0:
columnis 1-based.
Community Examples
- DiskPart[6]
- LibreHardwareMonitor[7]
- Windows[8]
From Windows (drops the _Total aggregate row of a performance counter table), included directly from the connector source:
- type: excludeMatchingLines
column: 1
regExp: _Total
- [1] keep-only-matching-lines.html
- [2] ../monitors-and-jobs.html#when-instances-are-removed
- [3] ../monitors-and-jobs.html#removaldelay
- [4] awk.html
- [5] replace.html
- [6] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/hardware/DiskPart/DiskPart.yaml
- [7] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/hardware/LibreHardwareMonitor/LibreHardwareMonitor.yaml
- [8] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/Windows/Windows.yaml
