prometheus

原始碼

prometheus 啟用 Prometheus 指標。

描述

透過 prometheus,您可以從 CoreDNS 和任何具有指標的外掛程式匯出指標。指標的預設位置是 localhost:9153。指標路徑固定為 /metrics

除了 Prometheus Go 客戶端 匯出的預設 Go 指標之外,還匯出以下指標:

  • coredns_build_info{version, revision, goversion} - 關於 CoreDNS 本身的資訊。
  • coredns_panics_total{} - panic 的總數。
  • coredns_dns_requests_total{server, zone, view, proto, family, type} - 總查詢次數。
  • coredns_dns_request_duration_seconds{server, zone, view, type} - 處理每個查詢的持續時間。
  • coredns_dns_request_size_bytes{server, zone, view, proto} - 以位元組為單位的請求大小。
  • coredns_dns_do_requests_total{server, view, zone} - 設定了 DO 位元的查詢。
  • coredns_dns_response_size_bytes{server, zone, view, proto} - 以位元組為單位的回應大小。
  • coredns_dns_responses_total{server, zone, view, rcode, plugin} - 每個區域、rcode 和外掛程式的回應。
  • coredns_dns_https_responses_total{server, status} - 每個伺服器和 HTTP 狀態碼的回應。
  • coredns_dns_quic_responses_total{server, status} - 每個伺服器和 QUIC 應用程式碼的回應。
  • coredns_plugin_enabled{server, zone, view, name} - 表示是否在每個伺服器、區域和視圖基礎上啟用外掛程式。

幾乎每個計數器都有一個標籤 zone,它是用於請求/回應的區域名稱。

使用的額外標籤有:

  • server 識別負責請求的伺服器。這是一個格式化為伺服器監聽位址的字串:<scheme>://[<bind>]:<port>。例如,對於「正常」的 DNS 伺服器,這是 dns://:53。如果您使用 bind 外掛程式,則會包含 IP 位址,例如:dns://127.0.0.53:53
  • proto,其中包含回應的傳輸方式(“udp” 或 “tcp”)
  • 傳輸的位址系列 (family) (1 = IP (IP 第 4 版),2 = IP6 (IP 第 6 版))。
  • type,其中包含查詢類型。它包含最常見的類型(A、AAAA、MX、SOA、CNAME、PTR、TXT、NS、SRV、DS、DNSKEY、RRSIG、NSEC、NSEC3、HTTPS、IXFR、AXFR 和 ANY)和 “other”,它將所有其他類型歸為一類。
  • status,其中包含 HTTP 狀態碼。可能的值為:
    • 200 - 已處理請求,
    • 404 - 請求在驗證時被拒絕,
    • 400 - 請求轉換為 DNS 訊息失敗,
    • 500 - 處理結束時沒有回應。
  • plugin 標籤包含向用戶端寫入的外掛程式的名稱。如果伺服器執行寫入(例如,發生錯誤時),則該值為空。

如果啟用了監控,則不會進入外掛程式鏈的查詢會以虛假的名稱 “dropped” 匯出(沒有結尾點 - 這永遠不是有效的網域名稱)。

啟用 prometheus 外掛程式時,其他外掛程式可能會匯出其他統計資料。這些統計資料記錄在每個外掛程式的 README 中。

此外掛程式每個伺服器區塊只能使用一次。

語法

prometheus [ADDRESS]

針對您想要查看指標的每個區域。

它可以選擇採用一個綁定位址,用於匯出指標;預設情況下,它會在 localhost:9153 上監聽。指標路徑固定為 /metrics

範例

使用替代的監聽位址

. {
    prometheus localhost:9253
}

或透過環境變數(整個 Corefile 都支援此操作):export PORT=9253,然後

. {
    prometheus localhost:{$PORT}
}

錯誤

重新載入時,Prometheus 處理程式會在新的伺服器執行個體啟動之前停止。如果新的伺服器啟動失敗,則初始伺服器執行個體仍然可用且 DNS 查詢仍然提供服務,但 Prometheus 處理程式仍然關閉。在成功重新載入或完全重新啟動 CoreDNS 之前,Prometheus 不會回覆 HTTP 請求。只有註冊為 Handler 的外掛程式才會顯示在 coredns_plugin_enabled{server, zone, name} 中。截至今天,不會報告外掛程式重新載入和綁定。