CoreDNS篇3-接入prometheus监控

2022-02-26  本文已影响0人  tinychen

本文主要对coredns的prometheus监控进行介绍,以及对grafana中配置coredns的dashboard进行分享。

0、背景

Prometheus插件作为coredns的Plugins,默认情况下是内置在coredns中,如果是自己编译安装的版本,需要注意在编译安装的时候的plugin.cfg文件中添加了prometheus:metrics,这样才能确保编译成功。

# 首先我们检查一下运行的版本
[root@tiny-server coredns]# ./coredns -plugins | grep prometheus
  dns.prometheus

1、简介

prometheus 插件主要用于暴露CoreDNS相关的监控数据,除了coredns本身外,其他支持prometheus的插件(如cache插件)在启用的时候也可以通过prometheus插件暴露出相关的监控信息,默认情况下暴露出的监控数据在localhost:9153,路径为/metrics配置文件中的每个server块只能使用一次prometheus。**下面是一些coredns自身相关的指标:

需要注意的是上面频繁出现的几个标签(label),这里额外做一些解释:

If monitoring is enabled, queries that do not enter the plugin chain are exported under the fake name “dropped” (without a closing dot - this is never a valid domain name).

2、配置

coredns中想要启用prometheus插件,只需要在对应的zone中加上这一行配置即可,默认监听的是本机127.0.0.1的9153端口,当然也可以根据自己的需要更改监听的网卡和端口。

Syntax

prometheus [ADDRESS]

我们直接来看一段配置:

tinychen.com:53 {
    forward tinychen.com 47.107.188.168
    prometheus
}

google.com:53 {
    forward google.com 8.8.8.8 9.9.9.9
    prometheus 192.168.100.100:9253
}

example.org {
    file /home/coredns/conf/example.org
}

prometheus的生效范围是按照zone来划分的,在上面的这个配置中:

如果有多个zone,每个zone都有相同的基础配置,也可以使用import指令,如:

tinychen.com:53 {
    forward tinychen.com 47.107.188.168
    log
    whoami
    errors
    prometheus 192.168.100.100:9253
    bind 192.168.100.100
    cache {
        success 10240 600 60
        denial 5120 60 5
    }
}

google.com:53 {
    forward google.com 8.8.8.8 9.9.9.9
    log
    whoami
    errors
    prometheus 192.168.100.100:9253
    bind 192.168.100.100
    cache {
        success 10240 600 60
        denial 5120 60 5
    }
}

example.org {
    file /home/coredns/conf/example.org
    log
    whoami
    errors
    prometheus 192.168.100.100:9253
    bind 192.168.100.100
    cache {
        success 10240 600 60
        denial 5120 60 5
    }
}

可以简化成这样:

(basesnip) {
    log
    whoami
    errors
    prometheus 192.168.100.100:9253
    bind 192.168.100.100
    cache {
        success 10240 600 60
        denial 5120 60 5
    }
}

tinychen.com:53 {
    forward tinychen.com 47.107.188.168
    import basesnip
}

google.com:53 {
    forward google.com 8.8.8.8 9.9.9.9
    import basesnip
}

example.org {
    file /home/coredns/conf/example.org
    import basesnip
}

3、grafana配置dashboard

coredns原生支持的prometheus指标数量和丰富程度在众多DNS系统中可以说是首屈一指的,此外在grafana的官网上也有着众多现成的dashboard可用,并且由于绝大多数指标都是通用的,多个不同的dashboard之间的panel可以随意复制拖拽组合成新的dashboard并且不用担心兼容性问题。我们可以很容易的根据自己的实际需求配置对应的权威/递归/组合DNS相关的监控项。

如上图我们可以看到能够监控出不同DNS类型的请求数量以及不同的zone各自的请求数量,还有其他的类似请求延迟、请求总数等等各项参数都能完善地监控起来。

如上图我们能看到可以监控到不同的请求的传输层协议状态,缓存的大小状态和命中情况等各种信息。

上一篇 下一篇

猜你喜欢

热点阅读