Skip to content

Commit c7050ee

Browse files
committed
first draft
1 parent 19bf369 commit c7050ee

File tree

1 file changed

+132
-81
lines changed

1 file changed

+132
-81
lines changed

docs/data-ai/capture-data/capture-sync.md

Lines changed: 132 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,27 @@ aliases:
4343
You can use the data management service to capture data from [supported components and services](#supported-resources), then sync it to the cloud.
4444
You can also sync data from arbitrary folders on your machine.
4545

46-
## Configure the data management service
46+
## Overview
4747

48-
To start, configure the data management service to capture and sync data.
48+
Data capture and sync in Viam involves two key pieces:
49+
50+
- A data management {{< glossary_tooltip term_id="service" text="service" >}} that writes captured data to local edge device storage and syncs that data with the cloud.
51+
- Individual {{< glossary_tooltip term_id="resource" text="resource" >}} configurations that specify what data to capture and how often.
52+
53+
## How data capture and data sync works
54+
55+
- The data management service stores captured data locally in <file>~/.viam/capture<file> by default.
56+
- Data is synced to the Viam cloud at a configured sync interval using encrypted gRPC calls and deleted from the disk once synced.
57+
- You can capture and sync data independently, one can run without the other.
58+
59+
## Set up data capture and data sync
60+
61+
### Configure a data management service for your machine
62+
63+
The data management service is responsible for:
64+
65+
- Writing data from your configured Viam resources to local storage on your edge device
66+
- Syncing data from the edge device to the cloud
4967

5068
{{< tabs >}}
5169
{{% tab name="Config Builder" %}}
@@ -117,6 +135,8 @@ Click the **Save** button in the top right corner of the page to save your confi
117135

118136
The following attributes are available for the data management service:
119137

138+
{{< expand "Click to view data management attributes" >}}
139+
120140
<!-- prettier-ignore -->
121141
| Name | Type | Required? | Description | `viam-micro-server` Support |
122142
| ------------------ | ------ | --------- | ----------- | ------------------- |
@@ -135,74 +155,16 @@ The following attributes are available for the data management service:
135155
| `cache_size_kb` | float | Optional | `viam-micro-server` only. The maximum amount of storage bytes (in kilobytes) allocated to a data collector. <br> Default: `1` KB. | <p class="center-text"><i class="fas fa-check" title="yes"></i></p> |
136156
| `file_last_modified_millis` | float | Optional | The amount of time to pass since arbitrary files were last modified until they are synced. Normal <file>.capture</file> files are synced as soon as they are able to be synced. <br> Default: `10000` milliseconds. | <p class="center-text"><i class="fas fa-times" title="no"></i></p> |
137157

138-
### Capture directly to MongoDB
139-
140-
Data capture supports capturing tabular data directly to MongoDB in addition to capturing to disk.
141-
142-
This feature is intended to support use cases like offline dashboards which don't require strong data delivery or consistency guarantees.
143-
144-
Here is a sample configuration that will capture fake sensor readings both to the configured MongoDB URI as well as to the `~/.viam/capture` directory on disk:
145-
146-
```json
147-
{
148-
"components": [
149-
{
150-
"name": "sensor-1",
151-
"namespace": "rdk",
152-
"type": "sensor",
153-
"model": "fake",
154-
"attributes": {},
155-
"service_configs": [
156-
{
157-
"type": "data_manager",
158-
"attributes": {
159-
"capture_methods": [
160-
{
161-
"method": "Readings",
162-
"capture_frequency_hz": 0.5,
163-
"additional_params": {}
164-
}
165-
]
166-
}
167-
}
168-
]
169-
}
170-
],
171-
"services": [
172-
{
173-
"name": "data_manager-1",
174-
"namespace": "rdk",
175-
"type": "data_manager",
176-
"attributes": {
177-
"mongo_capture_config": {
178-
"uri": "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000"
179-
}
180-
}
181-
}
182-
]
183-
}
184-
```
185-
186-
When `mongo_capture_config.uri` is configured, data capture will attempt to connect to the configured MongoDB server and write captured tabular data to the configured `mongo_capture_config.database` and `mongo_capture_config.collection` (or their defaults if unconfigured) after enqueuing that data to be written to disk.
187-
188-
If writes to MongoDB fail for any reason, data capture will log an error for each failed write and continue capturing.
189-
190-
Failing to write to MongoDB doesn't affect capturing and syncing data to cloud storage other than adding capture latency.
191-
192-
{{< alert title="Caution" color="caution" >}}
158+
{{< /expand >}}
193159

194-
- Capturing directly to MongoDB may write data to MongoDB that later fails to be written to disk (and therefore never gets synced to cloud storage).
195-
- Capturing directly to MongoDB does not retry failed writes to MongoDB. As a consequence, it is NOT guaranteed all data captured will be written to MongoDB.
196-
This can happen in cases such as MongoDB being inaccessible to `viam-server` or writes timing out.
197-
- Capturing directly to MongoDB may reduce the maximum frequency that data capture can capture data due to the added latency of writing to MongoDB.
198-
If your use case needs to support very high capture rates, this feature may not be appropriate.
160+
### Configure data capture for individual resources
199161

200-
{{< /alert >}}
162+
You can capture data for any {{< glossary_tooltip term_id="resource" text="resource" >}} that supports it, including resources on {{< glossary_tooltip term_id="remote-part" text="remote parts" >}}.
201163

202-
## Configure data capture
164+
Configure data capture for individual resources by:
203165

204-
You can capture data for any {{< glossary_tooltip term_id="resource" text="resource" >}} that supports it, including resources on {{< glossary_tooltip term_id="remote-part" text="remote parts" >}}.
205-
Scroll to the resource card you wish to configure data capture and sync on.
166+
- Selecting which resource methods to capture data fromm
167+
- Setting the capture frequency for each method
206168

207169
{{< tabs >}}
208170
{{% tab name="Regular" %}}
@@ -652,6 +614,8 @@ The following example of a configuration with a remote part captures data from t
652614

653615
The following attributes are available for data capture configuration:
654616

617+
{{< expand "Click to view data capture attributes" >}}
618+
655619
<!-- prettier-ignore -->
656620
| Name | Type | Required? | Description |
657621
| ------------------ | ------ | --------- | ----------- |
@@ -660,6 +624,8 @@ The following attributes are available for data capture configuration:
660624
| `retention_policy` | object | Optional | Option to configure how long data collected by this component or service should remain stored in the Viam Cloud. You must set this in JSON mode. See the JSON example for a camera component. <br> **Options:** `"days": <int>`, `"binary_limit_gb": <int>`, `"tabular_limit_gb": <int>`. <br> Days are in UTC time. Setting a retention policy of 1 day means that data stored now will be deleted the following day **in UTC time**. You can set either or both of the size limit options and size is in gigabytes. |
661625
| `additional_params` | depends | depends | Varies based on the method. For example, `ReadImage` requires a MIME type. |
662626

627+
{{< /expand >}}
628+
663629
Click the **Save** button in the top right corner of the page to save your config.
664630

665631
If cloud sync is enabled, the data management service deletes captured data once it has successfully synced to the cloud.
@@ -693,7 +659,8 @@ You can also control how local data is deleted if your machine's local storage b
693659

694660
## Stop data capture
695661

696-
If this is a test project, make sure you stop data capture to avoid charges for a large amount of unwanted data.
662+
If you don't need to capture data, for instance in a test scenario, you can turn off data capture to reduce unnecessary storage.
663+
Alternatively, see [advanced data capture and sync configurations](/data-ai/capture-data/capture-sync/#advanced-data-capture-and-sync-configurations) for other ways to control data usage, such as conditional sync or retention policies.
697664

698665
In the **Data capture** section of your resource's configuration card, toggle the switch to **Off**.
699666

@@ -705,25 +672,109 @@ To view all the captured data you have access to, go to the [**DATA** tab](https
705672

706673
You can also access data from a resource or machine part menu.
707674

708-
## Supported resources
675+
## Advanced data capture and sync configurations
709676

710-
The following components and services support data capture and cloud sync:
677+
### Direct to MongoDB capture
711678

712-
{{< readfile "/static/include/data/capture-supported.md" >}}
679+
You can configure direct capture of tabular data to a MongoDB instance alongside disk storage on your edge device.
680+
This can be useful for powering real-time dashboards before data is synced from the edge to the cloud.
681+
682+
Configure using `mongo_capture_config` attributes in your data manager service.
683+
684+
Here is a sample configuration that will capture fake sensor readings both to the configured MongoDB URI as well as to the `~/.viam/capture` directory on disk:
685+
686+
{{< expand "Click to view configuration" >}}
687+
688+
```json
689+
{
690+
"components": [
691+
{
692+
"name": "sensor-1",
693+
"namespace": "rdk",
694+
"type": "sensor",
695+
"model": "fake",
696+
"attributes": {},
697+
"service_configs": [
698+
{
699+
"type": "data_manager",
700+
"attributes": {
701+
"capture_methods": [
702+
{
703+
"method": "Readings",
704+
"capture_frequency_hz": 0.5,
705+
"additional_params": {}
706+
}
707+
]
708+
}
709+
}
710+
]
711+
}
712+
],
713+
"services": [
714+
{
715+
"name": "data_manager-1",
716+
"namespace": "rdk",
717+
"type": "data_manager",
718+
"attributes": {
719+
"mongo_capture_config": {
720+
"uri": "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000"
721+
}
722+
}
723+
}
724+
]
725+
}
726+
```
713727

714-
## Considerations
728+
{{< /expand >}}
715729

716-
- **Capturing too much data**: You can [use filtering to collect and sync only certain images](/data-ai/capture-data/filter-before-sync/) to capture data selectively.
717-
- **Retention policy**: Set a `retention_policy` attribute in your [data capture configuration](#configure-data-capture) to avoid keeping data stored in the Viam Cloud longer than a specified number of days.
718-
- **Pausing sync**: You can pause cloud sync at any time by navigating to your machine's **CONFIGURE** tab and disabling **Syncing** for your data management service.
730+
When `mongo_capture_config.uri` is configured, data capture will attempt to connect to the configured MongoDB server and write captured tabular data to the configured `mongo_capture_config.database` and `mongo_capture_config.collection` (or their defaults if unconfigured) after enqueuing that data to be written to disk.
719731

720-
If you have captured data that you do not want to sync, delete the data on the machine before resuming cloud sync.
721-
To delete the data locally, `ssh` into your machine and delete the data in the directory where you capture data.
732+
If writes to MongoDB fail for any reason, data capture will log an error for each failed write and continue capturing.
722733

723-
- **Sync data conditionally**: You can use a {{< glossary_tooltip term_id="module" text="module" >}} to sync data only when a certain logic condition is met, instead of at a regular time interval.
724-
For example, if you rely on mobile data but have intermittent WiFi connection in certain locations or at certain times of the day, you may want to trigger sync to only occur when these conditions are met.
725-
To set up triggers for syncing see [Conditional cloud sync](/data-ai/capture-data/conditional-sync/).
734+
Failing to write to MongoDB doesn't affect capturing and syncing data to cloud storage other than adding capture latency.
726735

727-
## Next steps
736+
{{< alert title="Caution" color="caution" >}}
737+
738+
- Capturing directly to MongoDB may write data to MongoDB that later fails to be written to disk (and therefore never gets synced to cloud storage).
739+
- Capturing directly to MongoDB does not retry failed writes to MongoDB. As a consequence, it is NOT guaranteed all data captured will be written to MongoDB.
740+
This can happen in cases such as MongoDB being inaccessible to `viam-server` or writes timing out.
741+
- Capturing directly to MongoDB may reduce the maximum frequency that data capture can capture data due to the added latency of writing to MongoDB.
742+
If your use case needs to support very high capture rates, this feature may not be appropriate.
728743

729-
Now that you have captured data, you could [create a dataset](/data-ai/ai/create-dataset/) and use this data to [train your own Machine Learning model](/data-ai/ai/train-tflite/) with the Viam platform.
744+
{{< /alert >}}
745+
746+
### Conditional sync
747+
748+
Although data sync checks for new data at the configured interval, you can define additional conditions that must be met to trigger syncing.
749+
For example:
750+
751+
- Only sync when on WiFi
752+
- Sync when specific events are detected
753+
- Sync during certain time windows
754+
755+
See [Conditional cloud sync](/data-ai/capture-data/conditional-sync/) for how to implement conditional syncs.
756+
757+
### Cloud data retention
758+
759+
Configure how long your synced data remains stored in the cloud:
760+
761+
- **Retain data up to a certain specific amount or for a specific length of time:** Set `retention_policies` at the resource level.
762+
- See the `retention_policy` field in [data capture configuration attributes](/data-ai/capture-data/capture-sync/#click-to-view-data-capture-attributes).
763+
- **Delete data captured by a machine when you delete the machine:** Control whether your cloud data is deleted when a machine or machine part is removed.
764+
- See the `delete_data_on_part_deletion` field in the [data management service configuration attributes](/data-ai/capture-data/capture-sync/#click-to-view-data-management-attributes).
765+
766+
### Sync optimization
767+
768+
**Capture interval considerations:** Performance can vary based on hardware capabilities, so ensure your capture settings are not too aggressive if resources are limited.
769+
770+
**Configurable sync threads:** You can control how many concurrent sync operations occur by adjusting the `maximum_num_sync_threads` setting.
771+
Higher values may improve throughput on more powerful hardware, but raising it too high may introduce instability on resource-constrained devices.
772+
773+
**Wait time before syncing arbitrary files:** If you choose to sync arbitrary files (beyond those captured by the data management service), the `file_last_modified_millis` configuration attribute specifies how long a file must remain unmodified before the data manager considers it for syncing.
774+
The default is 10 seconds.
775+
776+
## Supported resources
777+
778+
The following components and services support data capture and cloud sync:
779+
780+
{{< readfile "/static/include/data/capture-supported.md" >}}

0 commit comments

Comments
 (0)