Some data use cases require advanced configuration beyond the attributes accessible in the UI.
You can use raw JSON to configure additional attributes for both data management and data capture.
You can also configure data capture for remote parts.
Advanced data management service configurations
To configure the data manager in JSON, see the following example configurations:
The following attributes are available for the data management service:
Click to view data management attributes
Name
Type
Required?
Description
viam-micro-server Support
capture_disabled
bool
Optional
Toggle data capture on or off for the entire machine part. Note that even if capture is on for the whole part, but is not on for any individual components (see Step 2), data is not being captured. Default: false
capture_dir
string
Optional
Path to the directory on your machine where you want to store captured data. If you change the directory for data capture, only new data is stored in the new directory. Existing data remains in the directory where it was stored. Default: ~/.viam/capture
tags
array of strings
Optional
Tags to apply to all images or tabular data captured by this machine part. May include alphanumeric characters, underscores, and dashes.
sync_disabled
bool
Optional
Toggle cloud sync on or off for the entire machine part. Default: false
additional_sync_paths
string array
Optional
Paths to any other directories on your machine from which you want to sync data to the cloud. Once data is synced from a directory, it is automatically deleted from your machine. We recommend using absolute paths. For relative paths, see How sync works.
sync_interval_mins
float
Optional
Time interval in minutes between syncing to the cloud. Viam does not impose a minimum or maximum on the frequency of data syncing. However, in practice, your hardware or network speed may impose limits on the frequency of data syncing. Default: 0.1, meaning once every 6 seconds.
delete_data_on_part_deletion
bool
Optional
Whether deleting this machine or machine part should result in deleting all the data captured by that machine part. Default: false
delete_every_nth_when_disk_full
int
Optional
How many files to delete when local storage meets the fullness criteria. The data management service will delete every Nth file that has been captured upon reaching this threshold. Use JSON mode to configure this attribute. Default: 5, meaning that every fifth captured file will be deleted.
maximum_num_sync_threads
int
Optional
Max number of CPU threads to use for syncing data to the Viam Cloud. Default: runtime.NumCPU/2 so half the number of logical CPUs available to viam-server
mongo_capture_config.uri
string
Optional
The MongoDB URI data capture will attempt to write tabular data to after it is enqueued to be written to disk. When non-empty, data capture will capture tabular data to the configured MongoDB database and collection at that URI. See mongo_capture_config.database and mongo_capture_config.collection below for database and collection defaults. See Data capture directly to MongoDB for an example config.
mongo_capture_config.database
string
Optional
When mongo_capture_config.uri is non empty, changes the database data capture will write tabular data to. Default: "sensorData"
mongo_capture_config.collection
string
Optional
When mongo_capture_config.uri is non empty, changes the collection data capture will write tabular data to. Default: "readings"
cache_size_kb
float
Optional
viam-micro-server only. The maximum amount of storage bytes (in kilobytes) allocated to a data collector. Default: 1 KB.
file_last_modified_millis
float
Optional
The amount of time to pass since arbitrary files were last modified until they are synced. Normal .capture files are synced as soon as they are able to be synced. Default: 10000 milliseconds.
You can edit the JSON directly by switching to JSON mode in the UI.
Advanced data capture configurations
Caution
Avoid configuring data capture to higher rates than your hardware can handle, as this leads to performance degradation.
Viam supports data capture from resources on remote parts.
For example, if you use a part that does not have a Linux operating system or does not have enough storage or processing power to run viam-server, you can still process and capture the data from that part’s resources by adding it as a remote part.
Currently, you can only configure data capture from remote resources in your JSON configuration.
To add them to your JSON configuration you must explicitly add the remote resource’s type, model, name, and additional_params to the data_manager service configuration in the remotes configuration:
Key
Description
type
The type tells your machine what the resource is. For example, a board.
model
The model is a colon-delimited-triplet that specifies the namespace, the type of the part, and the part itself.
name
The name specifies the fully qualified name of the part.
additional_params
The additional parameters specify the data sources when you are using a board.
Click to view example JSON configuration for an ESP32 board that will be established as a remote part
The following example shows the configuration of the part that we will establish as a remote, in this case an ESP32 board.
This config is just like that of a non-remote part; the remote connection is established by the main part (in the next expandable example).
Click to view the JSON configuration for capturing data from two analog readers and a pin of the board's GPIO
The following example of a configuration with a remote part captures data from two analog readers that provide a voltage reading and from pin 27 of the GPIO of the board that we configured in the previous example:
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. Options:"days": <int>, "binary_limit_gb": <int>, "tabular_limit_gb": <int>. 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. The retention_policy does not affect logs. For information about logs, see Logging.
recent_data_store
object
Optional
Configure a rolling time frame of recent data to store in a hot data store for faster access. Example: { "stored_hours": 24 }
additional_params
depends
depends
Varies based on the method. For example, ReadImage requires a MIME type.
You can edit the JSON directly by switching to JSON mode in the UI.
Capture to the hot data store
If you want faster access to your most recent sensor readings, you can configure hot data storage.
The hot data store keeps a rolling window of hot data for faster queries.
All historical data remains in your default storage.
To configure the hot data store:
Use the recent_data_store attribute on each capture method in your data manager service.
Configure your queries’ data source to the hot data store by passing the use_recent_data boolean argument to tabularDataByMQL.
Click to view a sample configuration
The following sample configuration captures data from a sensor at 0.5 Hz.
viam-server stores the last 24 hours of data in a shared recent-data database, while continuing to write all data to blob storage:
You can configure direct capture of tabular data to a MongoDB instance alongside disk storage on your edge device.
This can be useful for powering real-time dashboards before data is synced from the edge to the cloud.
The MongoDB instance can be a locally running instance or a cluster in the cloud.
Configure using the mongo_capture_config attributes in your data manager service.
You can configure data sync to a MongoDB instance separately from data sync to the Viam Cloud.
Click to view sample configuration with MongoDB data store.
This sample configuration captures fake sensor readings both to the configured MongoDB URI as well as to the ~/.viam/capture directory on disk.
It does not sync the data to the Viam Cloud.
Click to view sample configuration with MongoDB data store and sync to the Viam Cloud.
This sample configuration captures fake sensor readings both to the configured MongoDB URI as well as to the ~/.viam/capture directory on disk.
It syncs data to the Viam Cloud every 0.1 minutes.
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.
If writes to MongoDB fail for any reason, data capture will log an error for each failed write and continue capturing.
Failing to write to MongoDB doesn’t affect capturing and syncing data to cloud storage other than adding capture latency.
Caution
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).
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.
This can happen in cases such as MongoDB being inaccessible to viam-server or writes timing out.
Capturing directly to MongoDB may reduce the maximum frequency that data capture can capture data due to the added latency of writing to MongoDB.
If your use case needs to support very high capture rates, this feature may not be appropriate.
Cloud data retention
Configure how long your synced data remains stored in the cloud:
Retain data up to a certain size (for example, 100GB) or for a specific length of time (for example, 14 days): Set retention_policies at the resource level.
See the retention_policy field in data capture configuration attributes.
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.
See the delete_data_on_part_deletion field in the data management service configuration attributes.
Sync optimization
Configurable sync threads: You can control how many concurrent sync operations occur by adjusting the maximum_num_sync_threads setting.
Higher values may improve throughput on more powerful hardware, but raising it too high may introduce instability on resource-constrained devices.
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.
The default is 10 seconds.