Read data from CSV
Introduction to CSV
What?
CSV (Comma-Separated Values) is a simple file format used to store tabular data, such as measurements or sensor readings. Each line in the file represents a row, and each value is separated by a delimiter (commonly a comma).
Why?
- Compatibility with existing systems: Most data exporters, sensors, and logging tools support CSV.
- Broad usage: Easy to read, process, and share across platforms and programming languages.
CSV settings
The Measurement Settings section configures how CSV data is interpreted and mapped into measurements. This includes defining how each column in the CSV file is used, setting up filters for data inclusion, and specifying data quality indicators.
ValueColumn
Description: Column of the value in the csv file for this measurement. Required: yes Example: 6
StatusGood
Description: All values that are mapped to status 'Good'. Multiple statuses can be configured using semicolon separated values. Required: no Example: "Valid;correct"
TimestampLayout
Description: The layout of the timestamp, defaults to the TimestampLayout setting on the collector. More info: https://pkg.go.dev/time#Layout\ Required: no
TagsInCSV
Description:This allows to add tags to the measurement with the tag value coming from csv data. The structure of this setting is similar as the Filter setting. The json key is the column index (as string) where the tag value is present, and the json value is the tag key (or tag name) under which the data should be stored upon the measurement: Required: no Example:{"4": "Description"}
FilterByRegularExpression
Description: If true, values in Filter will be treated as a regular expression. If false, values in Filter will be treated as a (list of) value to match. Default is false. Required: no
Locale
Description: The locale with which numbers should be parsed. Default is the value of the corresponding setting on the collector. Required: no
This table lists some examples of number formats and the locale with which they can be correctly parsed to a number the collector can process. The output in these examples is always the same: 1234.56
input | locale |
|---|---|
1 234.56 | en-GB |
1,234.56 | en-US |
1.234,56 | de-DE |
1 234,56 | fr-FR |
1234,56 | nl-BE |
Read CSV data
Use JSON settings
Filters can be configured via JSON:
Filter
Description: Filter to parse only the rows that match the filter. The filter is a JSON object where the key is the column index (as a string) and the value is an exact value to match. To match against a set of exact values, separate them with a semicolon. To use the value as a regular expression, set FilterByRegularExpression to true. Backslashes in regulars expressions need to be escaped with another backslash. Use {} to leave empty. Required: no Details:
- Key: CSV column index as a string.
- Value: Names used for mapping, separated by semicolons if multiple.
Example: In the following example (with FilterByRegularExpression set to false), the filter will only parse rows where the value of the first column is Example value and the value of the second column is match with this or also match with this.
{
"0": "Example value",
"1": "match with this;also match with this"
}In the following example (with FilterByRegularExpression set to true), the filter will only parse rows where the value of the first column contains Example and the value of the second column is match with this or also match with this.
{
"0": "Example",
"1": "^(match with this|also match with this)$"
}Examples
Example 1
Given the following CSV format, with files being provided by a data source located in `Europe/Brussels`.
Time,Name,Value,Unit,Quality
"1/12/2023 13:00:01.868",P99,"0.00",,Good
"1/12/2023 13:01:01.876",P99,"0.00",,Good
"1/12/2023 13:02:01.863",P99,"100.00",,Good
"1/12/2023 13:03:01.840",P99,"100.00",,Good
"1/12/2023 13:00:01.868",TT100,"27.51",,Good
"1/12/2023 13:01:01.876",TT100,"26.04",,Good
"1/12/2023 13:02:01.863",TT100,"25.97",,Good
"1/12/2023 13:03:01.840",TT100,"26.23",,Good
Settings of the collector and the measurement would be configured as below:
Collector settings:
Setting | Value |
|---|---|
Delimiter | , |
CSVHeader | true |
TimestampColumn | 0 |
TimestampLayout | 2/01/2006 15:04:05.000 |
StatusColumn | 4 |
TrimString | No Value |
Advanced Setting | Value |
|---|---|
SourceTimezone | Europe/Brussels |
Measurement settings:
Setting | Value |
|---|---|
Name | Area_Pump99 |
ValueColumn | 2 |
Filter | { "1": "P99" } |
StatusGood | Good |
TagsInCSV | {} |
TimestampLayout | No Value |
Setting | Value |
|---|---|
Name | Area_Temperature100 |
ValueColumn | 2 |
Filter | { "1": "TT100" } |
StatusGood | Good |
TagsInCSV | {} |
TimestampLayout | No Value |
Troubleshooting
Incorrect value parsing
Check Locale and number format.
Timestamp errors
Check TimestampLayout and confirm it is correct.