ValueLogReader
Introduction
A Sequencer block for reading data from CDP Logger or LogServer and exposing it as a message-based API.
Usage
To set up a ValueLogReader, add it to the configuration and connect it to a CDP Logger or LogServer by setting the ServerAddress and ServerPort properties.
When extracting data, it is recommended to first call ReqDefinitions to get a list of all logged nodes with their tags and then call ReqData to read the actual data.
The following is a block diagram of the typical usage of the ValueLogReader block. See below for instructions on how to replicate the example.
Tips
- Combine the ValueLogReader with RangeScanner and LogWriter to extract a part of the log to a new Datastore.
- The logs can be quite large, so it is recommended to use the Limit property to read data in batches.
- Disable the IncludeInitialValues property to prevent repeating values at batch borders when extracting data in batches (meaning the RangeEnd emitted with the last ReqDataDone is the RangeStart of the next ReqData). Otherwise, the first row of each batch always contains the initial value of every node.
Configuration
See below for a list of configuration options specific to this block.
Message Events
Name | Type | Description |
---|---|---|
Init | Input | Clears any internal buffers and connects or reconnects to the log server. It is mandatory to call this when the WaitForInit property is true . Will emit Inited when done. |
Inited | Output | Will be emitted after Init is done meaning the logger connection is up and the block is ready to serve requests. Note when the WaitForInit property is false , the block will automatically connect at startup and emit Inited. |
ReqBounds | Input | Requests the available history range (i.e. timestamp of the first and last logged sample). Will emit either ReqBoundsDone or Error when done. |
ReqBoundsDone | Output | Emits the timestamps of the first and last sample in the datastore as RangeStart and RangeEnd. |
ReqDefinitions | Input | Requests a list of all logged nodes. Will emit ReqDefDone or Error when done. |
Definition | Output | Definition of a single logged value. For each logged value, emits its LoggedName, Path, Tags and TagSources (if available). |
ReqDefDone | Output | Emitted once all Definition messages are sent. |
ReqData | Input | Requests data between RangeStart and RangeEnd with the specified Limit for batch size and includes nodes allowed by the PathFilter. When Resolution is non-zero, low-resolution compacted data is returned. Will emit ReqDataDone or Error when done. |
Data | Output | A single value change. For each cell (row and column) in ReqData response, emits its Timestamp, Value, LoggedName, Path, ValueType, ValueMin, ValueMax, Tags and TagSources (if available). |
ReqDataDone | Output | Emitted once all Data messages are sent. Includes RangeStart (timestamp of the first Data message) and RangeEnd (timestamp of the last Data message). In case no data was found, RangeStart is the same as the input to ReqData and RangeEnd is capped at the log range end. |
Error | Output | Failure when requesting data described by ErrorMsg. |
Reading Tags
When reading data, the associated tags can be accessed in two ways:
- Parse the semicolon-separated list in the Tags argument.
- Add each tag as a separate output argument with the tag name as the argument name. In that case, the tag value will be set to the argument value. Note each user-added argument must be listed in the Data property of the message event.
This affects the Definition and Data messages.
Arguments
Name | Type | Description |
---|---|---|
ServerAddress | Input | IP address (e.g. 127.0.0.1) or NetworkInterface Name (defined under application node, e.g. ETH0) of the CDP Logger's built-in server or LogServer. |
ServerPort | Input | Port of the CDP Logger's built-in server or LogServer. |
RangeStart | Input | Start timestamp for log reading (inclusive). When used as input to ReqData, leave it empty to read values from the beginning of the log. The unit is specified by the TimeUnit property. |
RangeEnd | Input | End timestamp for log reading (inclusive). When used as input to ReqData, leave it empty to read values until the end of the log. The unit is specified by the TimeUnit property. |
Resolution | Input | The sampling rate (Hz) for the data to read. Use this to limit the data resolution or set it to 0 for full resolution. |
PathFilter | Input | Semicolon-separated list of node paths to read. See the FilterMode property for wildcard and regex support. Leave empty to read all logged nodes. |
Limit | Input | Maximum batch size (the number of samples). Reading in large batches will improve performance but also allocate more memory. When combined with RangeScanner, the Limit must be at least two times the number of logged nodes, so each node would get the initial value and one extra sample. |
Timestamp | Output | Unix timestamp of a value change. The unit is specified by the TimeUnit property. |
Value | Output | The value change of a single node. For low-resolution data, this is the last value in the time span. |
ValueMin | Output | The minimum value in a time span when requesting low-resolution data. |
ValueMax | Output | The maximum value in a time span when requesting low-resolution data. |
ValueType | Output | The value type of a value change. Valid values are "undefined", "double", "uint64_t", "int64_t", "float", "unsigned int", "int", "unsigned short", "short", "unsigned char", "char", "bool" and "string". |
LoggedName | Output | A friendly name to a logged node (defined in the CDPLogger's LoggedValues table Name column). Guaranteed to be unique within a logger instance. |
Path | Output | The path (full Routing) to a node that emitted the value change. |
Tags | Output | Semicolon-separated tagname=value list of all tags associated with a logged node. |
TagSources | Output | A semicolon-separated tagname=source list that describes the path where the Tags information was fetched from. Note: for CDPLogger, the tag source is only available when found using TagLookup rules, not entered manually by the user under LoggedValues. |
ErrorMsg | Output | The error message emitted when a request fails. |
Properties
Name | Description |
---|---|
Debug | The debug level. Increase it to see more printouts. |
FilterMode | Affects the PathFilter argument behavior. Note, the ExactMatch means the full path must match, use Wildcard or Regex for partial match support. |
IncludeInitialValues | Disable to prevent repeating values at batch borders when extracting data in batches (meaning the RangeEnd emitted with the last ReqDataDone is the RangeStart of the next ReqData). Otherwise, the first row of each batch always contains the initial value of every node. |
TimeUnit | Unit of the Timestamp argument. Can be set to Second, Millisecond, Microsecond or Nanosecond since epoch (Unix timestamp). Affects Timestamp, RangeStart, and RangeEnd. |
Example
Here is a minimal example using the ValueLogReader. The example ValueLogReader connects to a CDP Logger logging a CPULoad signal and extracts all logged values to a CSV file in small batches and keeps extracting as new values are logged.
To run the example, start the application and trigger manually the ValueLogReader's ReqDefinitions message. The extracted values will be written to a "log.csv"
file in the application's working directory.
Here is how to replicate the example:
- Create a system.
- From the Resource tree, add
- CDPLogger.CDPLogger - the built-in logger component which by default logs values to CDPCompactDatastore.
- Sequencer.RangeScanner - scans the time range by small batches.
- CDPLogger.ValueLogReader - reads values from the CDPLogger component. In this minimal example, we have not set any filters, so it will read all values in full resolution and forward them to the LogWriter.
- CDPLogger.LogWriter - writes the received values to a new Datastore (CSVDatastore in this example).
- Optionally, add two Sequencer.DebugPrinter blocks to print any Error messages.
- Add a CDPLogger.CSVDatastore into the LogWriter block to store extracted values in a CSV file.
- Right-click on the CPULoad signal in the application and use the Add to Logger... menu to add it to the CDPLogger component.
- Connect the blocks as shown in the image above.
Possible Improvements
Some ideas not implemented in this minimal example:
- Instead of directly extracting to LogWriter on localhost, use Retagger and LogDataAggregator to re-tag and serialize the data for uploading to a cloud service. In the cloud side, deserialize using LogDataDisaggregator before passing the data to LogWriter. This way multiple edge devices can upload data to a central cloud database.
- Replace the CSVDatastore in the LogWriter block with a time-series database such as InfluxDatastore for better performance, scalability and data analysis capabilities.
- Set the Resolution (Hz) property to a non-zero value to extract low-resolution data for long-term storage.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.