Skip to content

Instantly share code, notes, and snippets.

@proffalken
Last active April 12, 2024 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proffalken/ac9933d92c92432bae6be4bf705a302e to your computer and use it in GitHub Desktop.
Save proffalken/ac9933d92c92432bae6be4bf705a302e to your computer and use it in GitHub Desktop.
Basic config for Grafana Alloy
// Sample config for Alloy that collects metrics, logs, and traces
// and forwards them to Grafana Cloud using the Grafana Cloud OTEL
// endpoint
//
// For a full configuration reference, see https://grafana.com/docs/alloy
logging {
level = "debug"
}
prometheus.exporter.unix "default" {
include_exporter_metrics = true
disable_collectors = ["mdadm"]
}
prometheus.scrape "default" {
targets = concat(
prometheus.exporter.unix.default.targets,
[{
// Self-collect metrics
job = "alloy",
__address__ = "127.0.0.1:12345",
}],
)
forward_to = [
otelcol.receiver.prometheus.prom_local.receiver,
]
}
loki.source.journal "local_logs" {
forward_to = [
otelcol.receiver.loki.loki_local.receiver,
]
}
otelcol.receiver.loki "loki_local" {
output {
logs = [otelcol.processor.batch.local.input]
}
}
otelcol.receiver.prometheus "prom_local" {
output {
metrics = [otelcol.processor.batch.local.input]
}
}
otelcol.receiver.otlp "local" {
grpc {
endpoint = "127.0.0.1:4317"
}
http {
endpoint = "127.0.0.1:4318"
}
output {
metrics = [otelcol.processor.batch.local.input]
logs = [otelcol.processor.batch.local.input]
traces = [otelcol.processor.batch.local.input]
}
}
otelcol.processor.batch "local" {
output {
metrics = [otelcol.exporter.otlphttp.default.input]
logs = [otelcol.exporter.otlphttp.default.input]
traces = [otelcol.exporter.otlphttp.default.input]
}
}
otelcol.auth.basic "oteldemostack" {
username = "<ACCOUNT ID>"
password = "<API TOKEN>"
}
otelcol.exporter.otlphttp "default" {
client {
endpoint = "https://otlp-gateway-prod-eu-west-0.grafana.net/otlp"
auth = otelcol.auth.basic.oteldemostack.handler
}
}
// Sample config for Alloy.
//
// For a full configuration reference, see https://grafana.com/docs/alloy
logging {
level = "debug"
}
prometheus.exporter.unix "default" {
include_exporter_metrics = true
disable_collectors = ["mdadm"]
}
prometheus.scrape "default" {
targets = concat(
prometheus.exporter.unix.default.targets,
[{
// Self-collect metrics
job = "alloy",
__address__ = "127.0.0.1:12345",
}],
)
forward_to = [
otelcol.receiver.prometheus.prom_local.receiver,
]
}
loki.source.journal "local_logs" {
forward_to = [
otelcol.receiver.loki.loki_local.receiver,
]
}
otelcol.receiver.loki "loki_local" {
output {
logs = [otelcol.processor.batch.local.input]
}
}
otelcol.receiver.prometheus "prom_local" {
output {
metrics = [otelcol.processor.batch.local.input]
}
}
otelcol.receiver.otlp "local" {
grpc {
endpoint = "127.0.0.1:4317"
}
http {
endpoint = "127.0.0.1:4318"
}
output {
metrics = [otelcol.processor.batch.local.input]
logs = [otelcol.processor.batch.local.input]
traces = [otelcol.processor.batch.local.input]
}
}
otelcol.processor.batch "local" {
output {
metrics = [otelcol.exporter.otlphttp.default.input]
logs = [otelcol.exporter.otlphttp.default.input]
traces = [otelcol.exporter.otlphttp.default.input]
}
}
// Get the credentials from Vault //
// First we get the Vault token from the file system
local.file "vault_token" {
filename = "/etc/alloy/.vault_token"
is_secret = true
}
// Then we get the secrets
// This is a single secret created by running
// vault kv put grafana/cloud/creds username="<user_id>" password="<token>"
remote.vault "cloudCreds" {
server = "http://127.0.0.1:8200"
path = "grafana/cloud/creds"
auth.token {
token = local.file.vault_token.content
}
}
// Then we setup the auth
otelcol.auth.basic "oteldemostack" {
// We need to "decloak" these values, but the password still won't be
// exposed in the logs or the Alloy UI
username = nonsensitive(remote.vault.cloudCreds.data.username)
password = nonsensitive(remote.vault.cloudCreds.data.password)
}
otelcol.exporter.otlphttp "default" {
client {
endpoint = "https://otlp-gateway-prod-eu-west-0.grafana.net/otlp"
// Use the credentials from Vault to authenticate.
auth = otelcol.auth.basic.oteldemostack.handler
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment