Skip to content
betterstack-alchemyUnofficial

Collectors

A Collector is the agent you run on a host (docker), a Docker Swarm (swarm) or a Kubernetes cluster (kubernetes). It collects logs, metrics and traces, with eBPF when enabled, and sends them to its own source. You declare the collector here; you install the agent yourself, with the collector’s secret.

A Docker host with host metrics and container logs:

alchemy.run.ts
const collector = yield* BetterStack.Telemetry.Collector("hosts", {
platform: "docker",
note: "Production hosts",
configuration: {
components: { logsDocker: true, metricsHostOs: true, ebpfMetrics: false },
logsSampleRate: 50,
},
});

platform, dataRegion and teamId replace the collector when changed. configuration changes only the components you send.

The secret is what the installer authenticates with. It is Redacted; hand it to your install step as a secret, and follow installationGuideUrl:

alchemy.run.ts
return {
collectorSecret: collector.secret,
installationGuide: collector.installationGuideUrl,
};

A CollectorTarget is something the collector scrapes for metrics: Postgres, PgBouncer, MySQL, Redis, MongoDB, Memcached, Elasticsearch, nginx, Apache, Kafka, Traefik, or a Prometheus endpoint (kind):

alchemy.run.ts
yield* BetterStack.Telemetry.CollectorTarget("orders-db", {
collectorId: collector.id,
kind: "postgres",
host: "orders-db.internal",
port: 5432,
username: "metrics",
password: yield* Config.Redacted("ORDERS_DB_METRICS_PASSWORD"),
sslMode: "require",
});

password and apiKey are never returned, so changes are detected against your previous deploy. A change to a connection setting sets the target’s status back to pending until the collector checks it again.

alchemy.run.ts
yield* BetterStack.Telemetry.CollectorTarget("api-metrics", {
collectorId: collector.id,
kind: "prometheus",
host: "api.internal",
service: "api",
endpoint: "http://api.internal:9090/metrics",
});