MetricsHub
MetricsHub Community Connectors 1.0.22
-
Home
- Connector Developer Guide Computes 24
keepOnlyMatchingLines (Compute)
When To Use
Use keepOnlyMatchingLines to filter a source table down to the rows you actually want to monitor: keep only the sensors of a given type, only the services whose name matches a connector variable, only the rows with a valid status. It is the table equivalent of grep: rows that do not match are discarded, rows that match pass through unchanged.
To do the opposite (discard matching rows), use excludeMatchingLines[1]. To drop columns instead of rows, use keepColumns[2].
Syntax
sources:
temperatureSensors:
type: commandLine
commandLine: ${file::ipmi-sensors.sh}
computes:
- type: keepOnlyMatchingLines
column: 1
valueList: temperature
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | keepOnlyMatchingLines. |
column |
Yes | None | 1-based index of the column tested on each row. Rows shorter than this index are discarded. |
regExp |
No | None | Case-insensitive regular expression. A row is kept 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 (see Common Mistakes). Often set from a connector variable, e.g. ${var::matchName}. |
valueList |
No | None | Comma-separated list of exact values, e.g. temperature,fan. A row is kept 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 are applied one after the other: a row is kept only if it matches the regExp and its value is in the valueList.
Table Transformation Example
With column: 1 and valueList: temperature:
Input
| Type | ID | Reading |
|---|---|---|
| temperature | CPU1 Temp | 42 |
| fan | Fan1A | 4800 |
| Temperature | Ambient | 24 |
| voltage | 12V Rail | 12.1 |
Result
| Type | ID | Reading |
|---|---|---|
| temperature | CPU1 Temp | 42 |
| Temperature | Ambient | 24 |
Note that Temperature is kept: valueList comparison is case-insensitive.
Recommended Pattern
- Prefer
valueListfor exact category values (temperature,fan,enclosure); reserveregExpfor real patterns. - Filter as early as possible in the
computespipeline so subsequent computes process fewer rows. - Drive
regExpfrom a connector variable (regExp: ${var::serviceNames}) when the user should choose what to monitor, as done inLinuxServiceandWindowsProcess. - Anchor the regex (
^value$) when you need an exact match with regex features; otherwiseabcalso keepsxabcy.
Common Mistakes
- Forgetting that
regExpis unanchored:regExp: 5keeps every row whose column merely contains5— usevalueList: 5orregExp: ^5$for an exact match. - Expecting
valueListto support patterns; it is a list of literal values only. - Combining
regExpandvalueListand expecting an OR: the two criteria are ANDed. - Counting columns from 0:
columnis 1-based. - Writing Java-style alternation
a|bwhere PSL-stylea\|bis expected.
Community Examples
- IpmiTool[3]
- WindowsProcess[4]
- LinuxService[5]
From IpmiTool:
# Temperature;SensorID;SensorName;Location;Value;WarningThreshold;AlarmThreshold
- type: keepOnlyMatchingLines
column: 1
valueList: temperature
- [1] exclude-matching-lines.html
- [2] keep-columns.html
- [3] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/hardware/IpmiTool/IpmiTool.yaml
- [4] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/WindowsProcess/WindowsProcess.yaml
- [5] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/LinuxService/LinuxService.yaml
