Permalink
Browse files

Added Prometheus support

Removed old metrics / status endpoints and internal counters
  • Loading branch information...
abh committed Apr 27, 2018
1 parent 7d058e4 commit 2c784780136beeb3913688ad54d4e42748926844
Showing with 22,540 additions and 5,327 deletions.
  1. +3 −0 CHANGES.md
  2. +53 −6 Gopkg.lock
  3. +4 −2 Makefile
  4. +1 −4 geodns.go
  5. +3 −156 http.go
  6. +0 −13 http_test.go
  7. +0 −98 monitor/hub.go
  8. +3 −109 monitor/monitor.go
  9. +0 −49 server/metrics.go
  10. +18 −13 server/serve.go
  11. +0 −4 server/serve_test.go
  12. +45 −5 server/server.go
  13. +0 −222 templates.go
  14. +0 −147 templates/status.html
  15. +20 −0 vendor/github.com/beorn7/perks/LICENSE
  16. +316 −0 vendor/github.com/beorn7/perks/quantile/stream.go
  17. +3 −0 vendor/github.com/golang/protobuf/AUTHORS
  18. +3 −0 vendor/github.com/golang/protobuf/CONTRIBUTORS
  19. +31 −0 vendor/github.com/golang/protobuf/LICENSE
  20. +229 −0 vendor/github.com/golang/protobuf/proto/clone.go
  21. +970 −0 vendor/github.com/golang/protobuf/proto/decode.go
  22. +151 −0 vendor/github.com/golang/protobuf/proto/discard.go
  23. +1,362 −0 vendor/github.com/golang/protobuf/proto/encode.go
  24. +300 −0 vendor/github.com/golang/protobuf/proto/equal.go
  25. +587 −0 vendor/github.com/golang/protobuf/proto/extensions.go
  26. +897 −0 vendor/github.com/golang/protobuf/proto/lib.go
  27. +311 −0 vendor/github.com/golang/protobuf/proto/message_set.go
  28. +484 −0 vendor/github.com/golang/protobuf/proto/pointer_reflect.go
  29. +270 −0 vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
  30. +872 −0 vendor/github.com/golang/protobuf/proto/properties.go
  31. +854 −0 vendor/github.com/golang/protobuf/proto/text.go
  32. +895 −0 vendor/github.com/golang/protobuf/proto/text_parser.go
  33. +201 −0 vendor/github.com/matttproud/golang_protobuf_extensions/LICENSE
  34. +1 −0 vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE
  35. +75 −0 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go
  36. +16 −0 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go
  37. +46 −0 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go
  38. +18 −0 vendor/github.com/prometheus/client_golang/AUTHORS.md
  39. +201 −0 vendor/github.com/prometheus/client_golang/LICENSE
  40. +23 −0 vendor/github.com/prometheus/client_golang/NOTICE
  41. +75 −0 vendor/github.com/prometheus/client_golang/prometheus/collector.go
  42. +172 −0 vendor/github.com/prometheus/client_golang/prometheus/counter.go
  43. +205 −0 vendor/github.com/prometheus/client_golang/prometheus/desc.go
  44. +181 −0 vendor/github.com/prometheus/client_golang/prometheus/doc.go
  45. +119 −0 vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go
  46. +29 −0 vendor/github.com/prometheus/client_golang/prometheus/fnv.go
  47. +140 −0 vendor/github.com/prometheus/client_golang/prometheus/gauge.go
  48. +263 −0 vendor/github.com/prometheus/client_golang/prometheus/go_collector.go
  49. +444 −0 vendor/github.com/prometheus/client_golang/prometheus/histogram.go
  50. +490 −0 vendor/github.com/prometheus/client_golang/prometheus/http.go
  51. +166 −0 vendor/github.com/prometheus/client_golang/prometheus/metric.go
  52. +142 −0 vendor/github.com/prometheus/client_golang/prometheus/process_collector.go
  53. +201 −0 vendor/github.com/prometheus/client_golang/prometheus/promhttp/http.go
  54. +806 −0 vendor/github.com/prometheus/client_golang/prometheus/registry.go
  55. +534 −0 vendor/github.com/prometheus/client_golang/prometheus/summary.go
  56. +138 −0 vendor/github.com/prometheus/client_golang/prometheus/untyped.go
  57. +234 −0 vendor/github.com/prometheus/client_golang/prometheus/value.go
  58. +404 −0 vendor/github.com/prometheus/client_golang/prometheus/vec.go
  59. +201 −0 vendor/github.com/prometheus/client_model/LICENSE
  60. +5 −0 vendor/github.com/prometheus/client_model/NOTICE
  61. +364 −0 vendor/github.com/prometheus/client_model/go/metrics.pb.go
  62. +201 −0 vendor/github.com/prometheus/client_model/ruby/LICENSE
  63. +201 −0 vendor/github.com/prometheus/common/LICENSE
  64. +5 −0 vendor/github.com/prometheus/common/NOTICE
  65. +429 −0 vendor/github.com/prometheus/common/expfmt/decode.go
  66. +88 −0 vendor/github.com/prometheus/common/expfmt/encode.go
  67. +38 −0 vendor/github.com/prometheus/common/expfmt/expfmt.go
  68. +36 −0 vendor/github.com/prometheus/common/expfmt/fuzz.go
  69. +303 −0 vendor/github.com/prometheus/common/expfmt/text_create.go
  70. +757 −0 vendor/github.com/prometheus/common/expfmt/text_parse.go
  71. +162 −0 vendor/github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg/autoneg.go
  72. +136 −0 vendor/github.com/prometheus/common/model/alert.go
  73. +105 −0 vendor/github.com/prometheus/common/model/fingerprinting.go
  74. +42 −0 vendor/github.com/prometheus/common/model/fnv.go
  75. +210 −0 vendor/github.com/prometheus/common/model/labels.go
  76. +169 −0 vendor/github.com/prometheus/common/model/labelset.go
  77. +103 −0 vendor/github.com/prometheus/common/model/metric.go
  78. +16 −0 vendor/github.com/prometheus/common/model/model.go
  79. +144 −0 vendor/github.com/prometheus/common/model/signature.go
  80. +106 −0 vendor/github.com/prometheus/common/model/silence.go
  81. +264 −0 vendor/github.com/prometheus/common/model/time.go
  82. +416 −0 vendor/github.com/prometheus/common/model/value.go
  83. +201 −0 vendor/github.com/prometheus/procfs/LICENSE
  84. +7 −0 vendor/github.com/prometheus/procfs/NOTICE
  85. +95 −0 vendor/github.com/prometheus/procfs/buddyinfo.go
  86. +45 −0 vendor/github.com/prometheus/procfs/doc.go
  87. +82 −0 vendor/github.com/prometheus/procfs/fs.go
  88. +46 −0 vendor/github.com/prometheus/procfs/internal/util/parse.go
  89. +259 −0 vendor/github.com/prometheus/procfs/ipvs.go
  90. +151 −0 vendor/github.com/prometheus/procfs/mdstat.go
  91. +569 −0 vendor/github.com/prometheus/procfs/mountstats.go
  92. +216 −0 vendor/github.com/prometheus/procfs/net_dev.go
  93. +263 −0 vendor/github.com/prometheus/procfs/nfs/nfs.go
  94. +317 −0 vendor/github.com/prometheus/procfs/nfs/parse.go
  95. +67 −0 vendor/github.com/prometheus/procfs/nfs/parse_nfs.go
  96. +89 −0 vendor/github.com/prometheus/procfs/nfs/parse_nfsd.go
  97. +238 −0 vendor/github.com/prometheus/procfs/proc.go
  98. +65 −0 vendor/github.com/prometheus/procfs/proc_io.go
  99. +150 −0 vendor/github.com/prometheus/procfs/proc_limits.go
  100. +68 −0 vendor/github.com/prometheus/procfs/proc_ns.go
  101. +188 −0 vendor/github.com/prometheus/procfs/proc_stat.go
  102. +232 −0 vendor/github.com/prometheus/procfs/stat.go
  103. +187 −0 vendor/github.com/prometheus/procfs/xfrm.go
  104. +330 −0 vendor/github.com/prometheus/procfs/xfs/parse.go
  105. +163 −0 vendor/github.com/prometheus/procfs/xfs/xfs.go
  106. +0 −29 vendor/github.com/rcrowley/go-metrics/LICENSE
  107. +0 −112 vendor/github.com/rcrowley/go-metrics/counter.go
  108. +0 −76 vendor/github.com/rcrowley/go-metrics/debug.go
  109. +0 −138 vendor/github.com/rcrowley/go-metrics/ewma.go
  110. +0 −120 vendor/github.com/rcrowley/go-metrics/gauge.go
  111. +0 −125 vendor/github.com/rcrowley/go-metrics/gauge_float64.go
  112. +0 −113 vendor/github.com/rcrowley/go-metrics/graphite.go
  113. +0 −61 vendor/github.com/rcrowley/go-metrics/healthcheck.go
  114. +0 −202 vendor/github.com/rcrowley/go-metrics/histogram.go
  115. +0 −31 vendor/github.com/rcrowley/go-metrics/json.go
  116. +0 −80 vendor/github.com/rcrowley/go-metrics/log.go
  117. +0 −257 vendor/github.com/rcrowley/go-metrics/meter.go
  118. +0 −13 vendor/github.com/rcrowley/go-metrics/metrics.go
  119. +0 −119 vendor/github.com/rcrowley/go-metrics/opentsdb.go
  120. +0 −363 vendor/github.com/rcrowley/go-metrics/registry.go
  121. +0 −212 vendor/github.com/rcrowley/go-metrics/runtime.go
  122. +0 −10 vendor/github.com/rcrowley/go-metrics/runtime_cgo.go
  123. +0 −9 vendor/github.com/rcrowley/go-metrics/runtime_gccpufraction.go
  124. +0 −7 vendor/github.com/rcrowley/go-metrics/runtime_no_cgo.go
  125. +0 −9 vendor/github.com/rcrowley/go-metrics/runtime_no_gccpufraction.go
  126. +0 −616 vendor/github.com/rcrowley/go-metrics/sample.go
  127. +0 −78 vendor/github.com/rcrowley/go-metrics/syslog.go
  128. +0 −329 vendor/github.com/rcrowley/go-metrics/timer.go
  129. +0 −100 vendor/github.com/rcrowley/go-metrics/writer.go
  130. +0 −106 vendor/golang.org/x/net/websocket/client.go
  131. +0 −24 vendor/golang.org/x/net/websocket/dial.go
  132. +0 −583 vendor/golang.org/x/net/websocket/hybi.go
  133. +0 −113 vendor/golang.org/x/net/websocket/server.go
  134. +0 −448 vendor/golang.org/x/net/websocket/websocket.go
  135. +2 −16 zones/zone.go
@@ -4,6 +4,9 @@
(dev branch; still in testing)
* Added Prometheus metrics support
* Removed /monitor websocket interface
* Removed /status and /status.json pages
* Support "closest" matching (instead of geo/asn labels) for A and AAAA records (Alex Bligh)
* Support for GeoIP2 databases (including IPv6 data and ASN databases)
* "Pluggable" targeting data support

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -14,7 +14,7 @@ docker-test: .PHONY
# test that we don't have missing dependencies
docker run --rm -v `pwd`:/go/src/github.com/abh/geodns \
-v /opt/local/share/GeoIP:/opt/local/share/GeoIP \
golang:1.10-alpine3.7 \
golang:1.10.1-alpine3.7 \
go test ./...
devel:
@@ -26,7 +26,9 @@ bench:
TARS=$(wildcard geodns-*-*.tar)
push: $(TARS) tmp-install.sh
rsync -avz tmp-install.sh $(TARS) x3.dev:webtmp/2018/02/
#rsync -avz tmp-install.sh $(TARS) x3.dev:webtmp/2018/04/
rsync tmp-install.sh $(TARS) $(DIST)/$(DISTSUB)/
$(DIST)/push
builds: linux-build linux-build-i386 freebsd-build push
@@ -66,7 +66,7 @@ var (
flagLogFile = flag.String("logfile", "", "log to file")
flagPrivateDebug = flag.Bool("privatedebug", false, "Make debugging queries accepted only on loopback")
flagShowVersion = flag.Bool("version", false, "Show dnsconfig version")
flagShowVersion = flag.Bool("version", false, "Show GeoDNS version")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
memprofile = flag.String("memprofile", "", "write memory profile to this file")
@@ -215,9 +215,6 @@ func main() {
}
}
mon := monitor.NewMonitor(serverInfo)
go mon.Run()
srv := server.NewServer(serverInfo)
if qlc := Config.QueryLog; len(qlc.Path) > 0 {
159 http.go
@@ -1,20 +1,15 @@
package main
import (
"encoding/json"
"fmt"
"html/template"
"io"
"log"
"net/http"
"runtime"
"sort"
"strconv"
"time"
"github.com/abh/geodns/monitor"
"github.com/abh/geodns/zones"
metrics "github.com/rcrowley/go-metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
type httpServer struct {
@@ -44,27 +39,6 @@ func (s ratesByCount) Less(i, j int) bool {
return ic > jc
}
type histogramData struct {
Max int64
Min int64
Mean float64
Pct90 float64
Pct99 float64
Pct999 float64
StdDev float64
}
func setupHistogramData(met metrics.Histogram, dat *histogramData) {
dat.Max = met.Max()
dat.Min = met.Min()
dat.Mean = met.Mean()
dat.StdDev = met.StdDev()
percentiles := met.Percentiles([]float64{0.90, 0.99, 0.999})
dat.Pct90 = percentiles[0]
dat.Pct99 = percentiles[1]
dat.Pct999 = percentiles[2]
}
func topParam(req *http.Request, def int) int {
req.ParseForm()
@@ -83,14 +57,14 @@ func topParam(req *http.Request, def int) int {
}
func NewHTTPServer(mm *zones.MuxManager, serverInfo *monitor.ServerInfo) *httpServer {
hs := &httpServer{
zones: mm,
mux: &http.ServeMux{},
serverInfo: serverInfo,
}
hs.mux.HandleFunc("/status", hs.StatusHandler())
hs.mux.HandleFunc("/status.json", hs.StatusJSONHandler())
hs.mux.HandleFunc("/", hs.mainServer)
hs.mux.Handle("/metrics", promhttp.Handler())
return hs
}
@@ -104,126 +78,6 @@ func (hs *httpServer) Run(listen string) {
log.Fatal(http.ListenAndServe(listen, &basicauth{h: hs.mux}))
}
func (hs *httpServer) StatusJSONHandler() func(http.ResponseWriter, *http.Request) {
info := serverInfo
return func(w http.ResponseWriter, req *http.Request) {
zonemetrics := make(map[string]metrics.Registry)
for name, zone := range hs.zones.Zones() {
zone.Lock()
zonemetrics[name] = zone.Metrics.Registry
zone.Unlock()
}
type statusData struct {
Version string
GoVersion string
Uptime int64
Platform string
Zones map[string]metrics.Registry
Global metrics.Registry
ID string
IP string
UUID string
Groups []string
}
uptime := int64(time.Since(info.Started).Seconds())
status := statusData{
Version: info.Version,
GoVersion: runtime.Version(),
Uptime: uptime,
Platform: runtime.GOARCH + "-" + runtime.GOOS,
Zones: zonemetrics,
Global: metrics.DefaultRegistry,
ID: hs.serverInfo.ID,
IP: hs.serverInfo.IP,
UUID: hs.serverInfo.UUID,
Groups: hs.serverInfo.Groups,
}
b, err := json.Marshal(status)
if err != nil {
http.Error(w, "Error encoding JSON", 500)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(b)
return
}
}
func (hs *httpServer) StatusHandler() func(http.ResponseWriter, *http.Request) {
type statusData struct {
Version string
Zones rates
Uptime DayDuration
Platform string
Global struct {
Queries metrics.Meter
Histogram histogramData
HistogramRecent histogramData
}
TopOption int
}
return func(w http.ResponseWriter, req *http.Request) {
topOption := topParam(req, 10)
rates := make(rates, 0)
for name, zone := range hs.zones.Zones() {
count := zone.Metrics.Queries.Count()
rates = append(rates, &rate{
Name: name,
Count: count,
Metrics: zone.Metrics,
})
}
sort.Sort(ratesByCount{rates})
uptime := DayDuration{time.Since(hs.serverInfo.Started)}
status := statusData{
Version: VERSION,
Zones: rates,
Uptime: uptime,
Platform: runtime.GOARCH + "-" + runtime.GOOS,
TopOption: topOption,
}
status.Global.Queries = metrics.Get("queries").(*metrics.StandardMeter).Snapshot()
setupHistogramData(metrics.Get("queries-histogram").(*metrics.StandardHistogram).Snapshot(), &status.Global.Histogram)
statusTemplate, err := FSString(development, "/templates/status.html")
if err != nil {
log.Println("Could not read template:", err)
w.WriteHeader(500)
return
}
tmpl, err := template.New("status_html").Parse(statusTemplate)
if err != nil {
str := fmt.Sprintf("Could not parse template: %s", err)
io.WriteString(w, str)
return
}
err = tmpl.Execute(w, status)
if err != nil {
log.Println("Status template error", err)
}
}
}
func (hs *httpServer) mainServer(w http.ResponseWriter, req *http.Request) {
if req.RequestURI != "/version" {
http.NotFound(w, req)
@@ -240,13 +94,6 @@ type basicauth struct {
func (b *basicauth) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// don't request passwords for the websocket interface (for now)
// because 'wscat' doesn't support that.
if r.RequestURI == "/monitor" {
b.h.ServeHTTP(w, r)
return
}
cfgMutex.RLock()
user := Config.HTTP.User
password := Config.HTTP.Password
@@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/abh/geodns/server"
"github.com/abh/geodns/targeting"
"github.com/abh/geodns/targeting/geoip2"
"github.com/abh/geodns/zones"
@@ -22,9 +21,6 @@ func TestHTTP(t *testing.T) {
targeting.Setup(geoprovider)
}
// todo: less global metrics ...
server.NewMetrics()
mm, err := zones.NewMuxManager("dns", &zones.NilReg{})
if err != nil {
t.Fatalf("loading zones: %s", err)
@@ -48,13 +44,4 @@ func TestHTTP(t *testing.T) {
t.Fail()
}
res, err = http.Get(baseurl + "/status")
require.Nil(t, err)
page, _ = ioutil.ReadAll(res.Body)
// just check that template basically works
if !bytes.Contains(page, []byte("<html>")) {
t.Log("/status didn't include <html>")
t.Fail()
}
}
Oops, something went wrong.

0 comments on commit 2c78478

Please sign in to comment.