Zum Inhalt springen

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.

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.

config.alloy
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 receiver
loki.source.file "example_log_files" {
targets = {__path__ = "/logs/foo.txt", "color" = "pink"},
// reference the loki write receiver
forward_to = [loki.write.stackit_logs.receiver]
}
  1. Create or edit the Grafana Alloy configuration file usually named config.alloy.
  2. You can provide access token either via environment variable or by creating a file and write the access token value for STACKIT Logs instance.
  3. If access token is in file, add a block local.file with a name e.g. stackit_logs_secret. In the block add file path and mark it as secret.
  4. Add a block of type loki.write and give it a name for example "stackit_logs".
  5. In the loki.write "stackit_logs" under endpoint set the url key with value from STACKIT Logs instance’s Ingest URL.
  6. If access token is in file then under endpoint reference local.file content in bearer_token , e.g. local.file.stackit_logs_secret.content.
  7. If access token is in environment variable then under endpoint reference sys.env() in bearer_token , e.g. sys.env("LOKI_ACCESS_TOKEN").
  8. Enable TLS for the output by setting tls and tls.verify keys with value on.
  9. The Grafana Alloy loki.write is now configured to connect to STACKIT Logs instance.
  10. You can now further configure the loki.write according to your needs. See the configuration of loki.write for more details.