Skip to main content

Reference: memfaultd Configuration

Useful links:

Basic Usage

Running memfaultd --help prints the following:

Usage: memfaultd [OPTION]...

--config-file <file> : Configuration file
--daemonize : Daemonize process
--enable-data-collection : Enable data collection, will restart the main memfaultd service
--disable-data-collection : Disable data collection, will restart the main memfaultd service
-h, --help : Display this help and exit
-s, --show-settings : Show settings
-v, --version : Show version information

The --config-file path defaults to /etc/memfaultd.conf. The settings you add in /etc/memfaultd.conf extend the built-in configuration file.

tip

As of v1.2.0, we recommend using memfaultctl to enable/disable data collection and view current settings.

--(enable|disable)-data-collection and --show-settings are still present on memfaultd for backwards compatibility but will be removed in a future major version of the SDK.

Usage in a systemd service

tip

The meta-memfault Yocto layer already includes a service file, so you don't need to add one if you're using meta-memfault.

You can use the --daemonize flag for this. See this example, taken from the meta-memfault layer:

[Unit]
Description=memfaultd daemon
After=local-fs.target network.target
Before=swupdate.service collectd.service

[Service]
Type=forking
PIDFile=/run/memfaultd.pid
ExecStart=/usr/bin/memfaultd --daemonize
Restart=on-failure

[Install]
WantedBy=multi-user.target

The Before= parameter is there to ensure memfaultd starts before swupdate.service as well as collectd.service. The configuration files used by these daemons are generated (at least partly) by memfaultd at startup, and need to be present before the respective services start.

If you're not using OTA or Metrics, you may remove the corresponding part of the Before= parameter. You may also wish to opt out of building the plugins with memfaultd.

/etc/memfaultd.conf

A full configuration example can be found in the source directory of memfaultd. Here's a copy:

{
"queue_size_kib": 1024,
"refresh_interval_seconds": 3600,
"enable_data_collection": false,
"enable_dev_mode": false,
"software_version": "<YOUR_SOFTWARE_VERSION>",
"software_type": "<YOUR_SOFTWARE_TYPE>",
"project_key": "<YOUR_PROJECT_KEY>",
"base_url": "https://device.memfault.com",
"data_dir": "/media/memfaultd",
"swupdate_plugin": {
"input_file": "/etc/swupdate.cfg",
"output_file": "/tmp/swupdate.cfg"
},
"reboot_plugin": {
"last_reboot_reason_file": "/media/last_reboot_reason",
"uboot_fw_env_file": "/etc/fw_env.config"
},
"collectd_plugin": {
"footer_include_output_file": "/tmp/collectd-footer-include.conf",
"header_include_output_file": "/tmp/collectd-header-include.conf",
"interval_seconds": 3600,
"non_memfaultd_chain": "",
"write_http_buffer_size_kib": 64
},
"coredump_plugin": {
"coredump_max_size_kib": 96000,
"rate_limit_count": 5,
"rate_limit_duration_seconds": 3600,
"storage_max_usage_kib": 0,
"storage_min_headroom_kib": 10240
},
"fluent-bit": {
"extra_fluentd_attributes": [],
"bind_address": "127.0.0.1:5170",
"max_buffered_lines": 1000,
"max_connections": 4
},
"logs": {
"rotate_size_kib": 10240,
"rotate_after_seconds": 3600,
"tmp_folder": "tmplogs"
}
}

The settings you add in /etc/memfaultd.conf extend the built-in configuration file.

Top-level /etc/memfaultd.conf configuration

FieldDescriptionRecommended value
queue_size_kibSize of $data_dir/queue in kibibytes.1024
refresh_interval_secondsThe frequency (in seconds) with which memfaultd will attempt to flush its queue and post it to Memfault. Note that a recovery system with exponential back-off is in place for network failures.3600
enable_data_collectionWhether memfaultd should collect and post data to Memfault by default. Read more here.false (ask for user consent first)
enable_dev_modeChange memfaultd default settings for development. Read more here.false (only use in development)
base_urlThe base URL to Memfault's device API.https://device.memfault.com
software_versionThe current version of your software. Read more here.Project-specific
software_typeThe current version of your software. Read more here.Project-specific
project_keyA write-only key for your Project. Find yours in Project -> Settings in the app.Project-specific
data_dirA directory where memfaultd can store application data persistently (needs to survive firmware upgrades). Read more here.Project-specific
swupdate_pluginConfiguration values for plugin_swupdate if enabled in memfaultd (default). Read more.See swupdate_plugin
reboot_pluginConfiguration values for plugin_reboot if enabled in memfaultd (default). Read more.See reboot_plugin
collectd_pluginConfiguration values for plugin_collectd if enabled in memfaultd (default). Read more.See reboot_plugin
coredump_pluginConfiguration values for plugin_coredump if enabled in memfaultd (default). Read more.See coredump_plugin

swupdate_plugin

{
"swupdate_plugin": {
"input_file": "/etc/swupdate.cfg",
"output_file": "/tmp/swupdate.cfg"
}
}
FieldDescriptionRecommended value
input_fileWill be used as the base SWUpdate configuration when generating $output_file. May specify a suricatta section (gets merged with generated parameters). If an identify section exists it will get replaced. See upstream SWUpdate docs./etc/swupdate.cfg
output_fileGenerated by memfaultd using $input_file as a base. Needs to be passed to SWUpdate as its config file. See an example here./tmp/swupdate.cfg

reboot_plugin

{
"reboot_plugin": {
"last_reboot_reason_file": "/media/last_reboot_reason",
"uboot_fw_env_file": "/etc/fw_env.config"
}
}
FieldDescriptionRecommended value
last_reboot_reason_fileThe path where memfaultd's reboot reason tracking plugin will attempt to find the device-specific reboot reason. If the file does not exist, memfaultd will interpret this as "no device specific reason known".Project-specific
uboot_fw_env_filePath to a valid fw_env.config file. See the SWUpdate dependency of Reboot Reason Tracking for more information. Read about libubootenv and see an example./etc/fw_env.config

collectd_plugin

{
"collectd_plugin": {
"footer_include_output_file": "/tmp/collectd-footer-include.conf",
"header_include_output_file": "/tmp/collectd-header-include.conf",
"interval_seconds": 3600,
"non_memfaultd_chain": "",
"write_http_buffer_size_kib": 64
}
}
FieldDescriptionRecommended value
footer_include_output_fileGenerated by memfaultd. Needs to be Included in the main collectd.conf as the last statement./tmp/collectd-footer-include.conf
header_include_output_fileGenerated by memfaultd. Needs to be Included in the main collectd.conf as the first statement./tmp/collectd-header-include.conf
non_memfaultd_chainAn optional collectd chain to jump to after the Memfault-generated chain. Read more here.Project-specific
write_http_buffer_size_kibSize of the collectd in-memory write buffer. Read more here.64
interval_secondsGoverns collectd's Interval and the FlushInterval setting of the write_http plugin. Read more here.3600

coredump_plugin

{
"coredump_plugin": {
"compression": "gzip",
"coredump_max_size_kib": 96000,
"rate_limit_count": 5,
"rate_limit_duration_seconds": 3600,
"storage_max_usage_kib": 0,
"storage_min_headroom_kib": 10240
}
}

To configure the location where coredumps are stored during processing, see data_dir.

FieldDescriptionRecommended value
compressionCompression to use when storing on disk and uploading to Memfault (none or gzip).gzip
coredump_max_size_kibThe maximum size of a coredump that can be processed.96000
rate_limit_count*The maximum amount of coredumps to process in a given period of rate_limit_duration_seconds.5*
rate_limit_duration_seconds*A window in which a maximum of rate_limit_count coredumps can be processed.3600*
storage_max_usage_kibA maximum of disk space to use for the purposes of coredump processing.Project-specific
storage_min_headroom_kibA minimum of disk space to leave unused in disk while processing a coredump.Project-specific

* Please consult with the Memfault team if you need to change rate-limiting settings for your integration, as the Memfault Web App will further enforce rate limiting rules.

When a program crashes, the kernel will attempt to produce a coredump for the crashing process. When memfaultd receives the coredump, it will first apply the rate limiting policy, to limit the number of coredumps that can get generated within a period of time. If the rate limit is exceeded, the coredump is dropped.

Next, memfaultd will determine the maximum size that is allowed, based on the coredump_max_size_kib, storage_max_usage_kib and storage_min_headroom_kib configuration values and the amount of available storage space.

Unless there is no available storage, the coredump is written into a temporary holding area inside the data_dir.

Finally, the coredump is added to the upload queue. This queue is serviced periodically (see the top-level refresh_interval_seconds).

fluent-bit

{
"fluent-bit": {
"extra_fluentd_attributes": [],
"bind_address": "127.0.0.1:5170",
"max_buffered_lines": 1000,
"max_connections": 4
}
}
FieldDescriptionRecommended value
extra_fluentd_attributesList of fluentd attributes to save beyond the defaults[]
bind_addressAddress and port to bind the fluent-bit listener to.
Replacing 127.0.0.1 by 0.0.0.0 will open the log collection service to the network (not recommended).
127.0.0.1:5170
max_buffered_linesMaximum number of lines to buffer in memory before applying backpressure to fluent-bit.10000
max_connectionsMaximum number of simultaneous connected sockets with fluent-bit.4

logs

{
"logs": {
"rotate_size_kib": 10240,
"rotate_after_seconds": 3600,
"tmp_folder": "tmplogs"
}
}
FieldDescriptionRecommended value
rotate_after_secondsLog files will be rotated when they reach this number of seconds.3600
rotate_size_kibLog files will be rotated when they reach this size (in kibibytes).10240 (10 MiB)
tmp_folderWhere to store logfiles while they are being written. If this path does not start with a /, it will be relative to the data_dir.tmplogs (so {data_dir}/tmplogs).

mar

{
"mar": {
"storage_max_usage_kib": 102400
}
}
FieldDescriptionRecommended value
storage_max_usage_kibMaximum disk space used by memfaultd for MAR entries.102400 (100 MiB)

memfaultd will transform log files into MAR entries on disk and keep them in the MAR staging area until they are uploaded.

Older entries will be deleted automatically to keep the total size smaller than storage_max_usage_kib.