mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 00:04:15 -04:00
Add coredns_build_info metric (#1418)
In order to track the rollout status of CoreDNS versions, add the common build_info metric.
This commit is contained in:
committed by
Miek Gieben
parent
f9c03c2ead
commit
b707438534
2
Makefile
2
Makefile
@@ -9,7 +9,7 @@ all: coredns
|
||||
|
||||
.PHONY: coredns
|
||||
coredns: $(CHECKS)
|
||||
CGO_ENABLED=0 $(SYSTEM) go build $(VERBOSE) -ldflags="-s -w -X github.com/coredns/coredns/coremain.gitCommit=$(GITCOMMIT)" -o $(BINARY)
|
||||
CGO_ENABLED=0 $(SYSTEM) go build $(VERBOSE) -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=$(GITCOMMIT)" -o $(BINARY)
|
||||
|
||||
.PHONY: check
|
||||
check: linter core/zplugin.go core/dnsserver/zdirectives.go godeps
|
||||
|
||||
@@ -53,7 +53,7 @@ endif
|
||||
|
||||
DOCKER:=
|
||||
NAME:=coredns
|
||||
VERSION:=$(shell grep 'coreVersion' coremain/version.go | awk '{ print $$3 }' | tr -d '"')
|
||||
VERSION:=$(shell grep 'CoreVersion' coremain/version.go | awk '{ print $$3 }' | tr -d '"')
|
||||
GITHUB:=coredns
|
||||
DOCKER_IMAGE_NAME:=$(DOCKER)/$(NAME)
|
||||
GITCOMMIT:=$(shell git describe --dirty --always)
|
||||
|
||||
@@ -49,7 +49,7 @@ func init() {
|
||||
caddy.SetDefaultCaddyfileLoader("default", caddy.LoaderFunc(defaultLoader))
|
||||
|
||||
caddy.AppName = coreName
|
||||
caddy.AppVersion = coreVersion
|
||||
caddy.AppVersion = CoreVersion
|
||||
}
|
||||
|
||||
// Run is CoreDNS's main() function.
|
||||
@@ -180,7 +180,7 @@ func versionString() string {
|
||||
// e.g.,
|
||||
// linux/amd64, go1.8.3, a6d2d7b5
|
||||
func releaseString() string {
|
||||
return fmt.Sprintf("%s/%s, %s, %s\n", runtime.GOOS, runtime.GOARCH, runtime.Version(), gitCommit)
|
||||
return fmt.Sprintf("%s/%s, %s, %s\n", runtime.GOOS, runtime.GOARCH, runtime.Version(), GitCommit)
|
||||
}
|
||||
|
||||
// setVersion figures out the version information
|
||||
@@ -193,7 +193,7 @@ func setVersion() {
|
||||
if gitNearestTag != "" || gitTag != "" {
|
||||
if devBuild && gitNearestTag != "" {
|
||||
appVersion = fmt.Sprintf("%s (+%s %s)",
|
||||
strings.TrimPrefix(gitNearestTag, "v"), gitCommit, buildDate)
|
||||
strings.TrimPrefix(gitNearestTag, "v"), GitCommit, buildDate)
|
||||
} else if gitTag != "" {
|
||||
appVersion = strings.TrimPrefix(gitTag, "v")
|
||||
}
|
||||
@@ -252,7 +252,7 @@ var (
|
||||
buildDate string // date -u
|
||||
gitTag string // git describe --exact-match HEAD 2> /dev/null
|
||||
gitNearestTag string // git describe --abbrev=0 --tags HEAD
|
||||
gitCommit string // git rev-parse HEAD
|
||||
GitCommit string // git rev-parse HEAD
|
||||
gitShortStat string // git diff-index --shortstat
|
||||
gitFilesModified string // git diff-index --name-only HEAD
|
||||
)
|
||||
|
||||
@@ -2,7 +2,8 @@ package coremain
|
||||
|
||||
const (
|
||||
coreName = "CoreDNS"
|
||||
coreVersion = "1.0.4"
|
||||
// CoreVersion is the current version of CoreDNS.
|
||||
CoreVersion = "1.0.4"
|
||||
|
||||
serverType = "dns"
|
||||
)
|
||||
|
||||
@@ -10,6 +10,7 @@ With *prometheus* you export metrics from CoreDNS and any plugin that has them.
|
||||
The default location for the metrics is `localhost:9153`. The metrics path is fixed to `/metrics`.
|
||||
The following metrics are exported:
|
||||
|
||||
* `coredns_build_info{version, revision, goversion}` - info about CoreDNS itself.
|
||||
* `coredns_dns_request_count_total{zone, proto, family}` - total query count.
|
||||
* `coredns_dns_request_duration_seconds{zone}` - duration to process each query.
|
||||
* `coredns_dns_request_size_bytes{zone, proto}` - size of the request in bytes.
|
||||
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/coremain"
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metrics/vars"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -39,6 +41,7 @@ func New(addr string) *Metrics {
|
||||
met.MustRegister(prometheus.NewProcessCollector(os.Getpid(), ""))
|
||||
|
||||
// Add all of our collectors
|
||||
met.MustRegister(buildInfo)
|
||||
met.MustRegister(vars.RequestCount)
|
||||
met.MustRegister(vars.RequestDuration)
|
||||
met.MustRegister(vars.RequestSize)
|
||||
@@ -46,6 +49,10 @@ func New(addr string) *Metrics {
|
||||
met.MustRegister(vars.RequestType)
|
||||
met.MustRegister(vars.ResponseSize)
|
||||
met.MustRegister(vars.ResponseRcode)
|
||||
|
||||
// Initialize metrics.
|
||||
buildInfo.WithLabelValues(coremain.CoreVersion, coremain.GitCommit, runtime.Version()).Set(1)
|
||||
|
||||
return met
|
||||
}
|
||||
|
||||
@@ -115,3 +122,11 @@ func keys(m map[string]bool) []string {
|
||||
// ListenAddr is assigned the address of the prometheus listener. Its use is mainly in tests where
|
||||
// we listen on "localhost:0" and need to retrieve the actual address.
|
||||
var ListenAddr string
|
||||
|
||||
var (
|
||||
buildInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Name: "build_info",
|
||||
Help: "A metric with a constant '1' value labeled by version, revision, and goversion from which CoreDNS was built.",
|
||||
}, []string{"version", "revision", "goversion"})
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user