Skip to main content

CoreDNS

Monitor CoreDNS — DNS request rates, response codes, cache hit rates, and plugin latencies — using CoreDNS's built-in Prometheus plugin.

Pattern: CoreDNS prometheus plugin → Prometheus scrape → xScaler remote_write


Prerequisites

  • CoreDNS 1.6+
  • xScaler tenant credentials (token + tenant ID)

Enable Metrics

Add the prometheus directive to your Corefile:

. {
prometheus :9153
forward . 8.8.8.8
cache 30
log
}

Verify:

curl -s http://localhost:9153/metrics | grep coredns_dns_requests_total

Option A — Prometheus

scrape_configs:
- job_name: coredns
static_configs:
- targets: ['localhost:9153']

remote_write:
- url: https://euw1-01.m.xscalerlabs.com/api/v1/push
authorization:
credentials: <token>
headers:
X-Scope-OrgID: <tenant-id>

Option B — Grafana Alloy

prometheus.scrape "coredns" {
targets = [{"__address__" = "localhost:9153"}]
forward_to = [prometheus.remote_write.xscaler.receiver]
}

prometheus.remote_write "xscaler" {
endpoint {
url = "https://euw1-01.m.xscalerlabs.com/api/v1/push"
authorization {
type = "Bearer"
credentials = "<token>"
}
headers = { "X-Scope-OrgID" = "<tenant-id>" }
}
}

Option C — OpenTelemetry Collector

receivers:
prometheus:
config:
scrape_configs:
- job_name: coredns
static_configs:
- targets: ['localhost:9153']

processors:
batch:
timeout: 10s

exporters:
otlphttp/xscaler:
endpoint: https://euw1-01.m.xscalerlabs.com
headers:
Authorization: "Bearer <token>"
X-Scope-OrgID: "<tenant-id>"
compression: gzip

service:
pipelines:
metrics:
receivers: [prometheus]
processors: [batch]
exporters: [otlphttp/xscaler]

Logs

Collect CoreDNS query log and error log from the container. Add the following to your Alloy config:

discovery.docker "coredns_containers" {
host = "unix:///var/run/docker.sock"
filter {
name = "name"
values = ["coredns"]
}
}

discovery.relabel "coredns_logs" {
targets = discovery.docker.coredns_containers.targets
rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
rule {
replacement = "integrations/coredns"
target_label = "job"
}
}

loki.source.docker "coredns_logs" {
host = "unix:///var/run/docker.sock"
targets = discovery.relabel.coredns_logs.output
forward_to = [loki.write.xscaler.receiver]
labels = { instance = constants.hostname }
}

loki.write "xscaler" {
endpoint {
url = "https://euw1-01.l.xscalerlabs.com/api/v1/logs/push"

http_client_config {
authorization {
type = "Bearer"
credentials = env("XSCALER_TOKEN")
}
}

headers = { "X-Scope-OrgID" = env("XSCALER_TENANT_ID") }
}
}

Key metrics

MetricDescription
coredns_dns_requests_totalTotal DNS requests by type and zone
coredns_dns_responses_totalTotal responses by rcode
coredns_cache_hits_totalCache hits
coredns_cache_misses_totalCache misses
coredns_dns_request_duration_secondsRequest duration histogram
coredns_forward_requests_totalRequests forwarded upstream
coredns_forward_request_duration_secondsUpstream forward latency