Grafana Alloy: Write log data to Logs instance
Zuletzt aktualisiert am
Grafana Alloy is a telemetry collector which supports collecting logs and exporting them to multiple destinations. It has built-in support for Loki as an exporter which can be configured to target STACKIT Logs instance.
Prerequisites
Section titled “Prerequisites”- You have a STACKIT Logs Instance: Create your first STACKIT Logs instance
- You have credentials with write permission for the STACKIT Logs Instance: Retrieve credentials for STACKIT Logs instance
- Ingest URL of the STACKI Logs Instance: Retrieve API URL STACKIT Logs instance
Client Configuration
Section titled “Client Configuration”Grafana Alloy can be configured with the next steps. The conf file output of steps is shown first, you can extend it according to your requirements.
local.file "stackit_logs_secret" { // File containing STACKIT Logs access token filename = "/var/secrets/stackit_logs.token" is_secret = true}
loki.write "stackit_logs" { endpoint { // set here the 'Ingest URL' of your STACKIT Logs instance url = "<ingest-url-of-logs-instance>" // reference the token file bearer_token = local.file.stackit_logs_secret.content // // or access the token if provided via env variable //bearer_token = sys.env("LOKI_ACCESS_TOKEN") }}// Example: read logs from file and forward to loki write's receiverloki.source.file "example_log_files" { targets = {__path__ = "/logs/foo.txt", "color" = "pink"}, // reference the loki write receiver forward_to = [loki.write.stackit_logs.receiver]}- Create or edit the Grafana Alloy configuration file usually named
config.alloy. - You can provide access token either via environment variable or by creating a file and write the access token value for STACKIT Logs instance.
- If access token is in file, add a block
local.filewith a name e.g.stackit_logs_secret. In the block add file path and mark it as secret. - Add a block of type
loki.writeand give it a name for example"stackit_logs". - In the
loki.write "stackit_logs"underendpointset theurlkey with value from STACKIT Logs instance’s Ingest URL. - If access token is in file then under
endpointreferencelocal.filecontent inbearer_token, e.g.local.file.stackit_logs_secret.content. - If access token is in environment variable then under
endpointreferencesys.env()inbearer_token, e.g.sys.env("LOKI_ACCESS_TOKEN"). - Enable TLS for the output by setting
tlsandtls.verifykeys with valueon. - The Grafana Alloy
loki.writeis now configured to connect to STACKIT Logs instance. - You can now further configure the
loki.writeaccording to your needs. See the configuration ofloki.writefor more details.