Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/docs/sources/flow/reference/components/local.file.md
4096 views
---
title: local.file
---

local.file

local.file exposes the contents of a file on disk to other components. The file will be watched for changes so that its latest content is always exposed.

The most common use of local.file is to load secrets (e.g., API keys) from files.

Multiple local.file components can be specified by giving them different labels.

Usage

local.file "LABEL" { filename = FILE_NAME }

Arguments

The following arguments are supported:

NameTypeDescriptionDefaultRequired
filenamestringPath of the file on disk to watchyes
detectorstringWhich file change detector to use (fsnotify, poll)"fsnotify"no
poll_frequencydurationHow often to poll for file changes"1m"no
is_secretboolMarks the file as containing a [secret][]falseno

[secret]: {{< relref "../../config-language/expressions/types_and_values.md#secrets" >}}

{{< docs/shared lookup="flow/reference/components/local-file-arguments-text.md" source="agent" >}}

Exported fields

The following fields are exported and can be referenced by other components:

NameTypeDescription
contentstring or secretThe contents of the file from the most recent read

The content field will have the secret type only if the is_secret argument was true.

Component health

local.file will be reported as healthy whenever if the watched file was read successfully.

Failing to read the file whenever an update is detected (or after the poll period elapses) will cause the component to be reported as unhealthy. When unhealthy, exported fields will be kept at the last healthy value. The read error will be exposed as a log message and in the debug information for the component.

Debug information

local.file does not expose any component-specific debug information.

Debug metrics

  • agent_local_file_timestamp_last_accessed_unix_seconds (gauge): The timestamp, in Unix seconds, that the file was last successfully accessed.

Example

local.file "secret_key" { filename = "/var/secrets/password.txt" is_secret = true }