# Collector settings that make a container's OpenTelemetry collector report its # own health (refused and failed records, exporter queue, memory), imported by # every container collector: the agent forwarder, the service journal # forwarder and the secret store's collector. The two host-side tiers scrape # themselves through their `scrapeTargets` instead. # # One function renders both halves, so the endpoint and the job that reads it # cannot name different ports. The endpoint binds loopback: the collector # scrapes itself, and nothing outside the container has a reason to. # # The job runs in its own pipeline. A container's other metrics pipeline may # carry a `resource` processor that upserts `service.name`, which would # relabel these series away from the `otelcol-contrib` the collector dashboard # selects on. The attributes stamped here tell the container's collectors # apart. # # `readers`, not `metrics.address`: this collector version rejects `address` # at startup. { lib, port, exporter, attributes, }: { service.telemetry.metrics.readers = [ { pull.exporter.prometheus = { host = "127.0.0.1"; inherit port; }; } ]; receivers."prometheus/self".config.scrape_configs = [ { job_name = "collector"; static_configs = [ { targets = [ "127.0.0.1:${toString port}" ]; } ]; } ]; processors."resource/self".attributes = lib.mapAttrsToList (key: value: { inherit key value; action = "upsert"; }) attributes; service.pipelines."metrics/self" = { receivers = [ "prometheus/self" ]; processors = [ "resource/self" ]; exporters = [ exporter ]; }; }