Add metrics

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2020-01-18 08:39:02 +01:00
parent 272823932f
commit b371eb679d
4 changed files with 27 additions and 1 deletions

View File

@@ -91,6 +91,13 @@ What metrics should we do? If any? Number of clusters? Number of endpoints and h
This plugin report readiness to the ready plugin. This will happen after a gRPC stream has been
established to the control plane.
## Metrics
If monitoring is enabled (via the *prometheus* plugin) then the following metric are exported:
* `coredns_traffic_clusters_tracked{}` the number of tracked clusters.
## Examples
~~~
@@ -123,7 +130,6 @@ is not implemented.
## TODO
* metrics?
* credentials (other than TLS) - how/what?
* is the protocol correctly implemented? Should we not have a 10s tick, but wait for responses from
the control plane?

View File

@@ -9,6 +9,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/parse"
pkgtls "github.com/coredns/coredns/plugin/pkg/tls"
@@ -38,6 +39,7 @@ func setup(c *caddy.Controller) error {
c.OnStartup(func() error {
go t.c.Run()
metrics.MustRegister(c, xds.ClusterGauge)
return nil
})
c.OnShutdown(func() error { return t.c.Stop() })

View File

@@ -191,6 +191,7 @@ func (c *Client) receive(stream adsStream) error {
a.SetClusterLoadAssignment(cluster.GetName(), nil)
}
log.Debugf("Cluster discovery processed with %d resources, version %q and nonce %q", len(resp.GetResources()), c.Version(cdsURL), c.Nonce(cdsURL))
ClusterGauge.WithLabelValues().Set(float64(len(resp.GetResources())))
// set our local administration and ack the reply. Empty version would signal NACK.
c.SetNonce(cdsURL, resp.GetNonce())
c.SetVersion(cdsURL, resp.GetVersionInfo())

View File

@@ -0,0 +1,17 @@
package xds
import (
"github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus"
)
var (
// ClusterGauge is the number of clusters we are currently tracking.
ClusterGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace,
Subsystem: "traffic",
Name: "clusters_tracked",
Help: "Gauge of tracked clusters.",
}, []string{""})
)