コード例 #1
0
ファイル: instrumentation.go プロジェクト: rugby110/glimpse
func dnsMetricsHandler(next dns.Handler) dns.HandlerFunc {
	return func(w dns.ResponseWriter, req *dns.Msg) {
		var (
			prot  = "unknown"
			qtype = "unknown"
			rcode = "unknown"

			buffer = &cachingWriter{ResponseWriter: w}
			start  = time.Now()
		)

		if _, ok := w.RemoteAddr().(*net.UDPAddr); ok {
			prot = "udp"
		} else if _, ok := w.RemoteAddr().(*net.TCPAddr); ok {
			prot = "tcp"
		}

		if len(req.Question) == 1 {
			qtype = dns.TypeToString[req.Question[0].Qtype]
		}

		next.ServeDNS(buffer, req)
		if buffer.last != nil {
			rcode = dns.RcodeToString[buffer.last.Rcode]
		}

		duration := float64(time.Since(start)) / float64(time.Second)
		dnsDurations.WithLabelValues(prot, qtype, rcode).Observe(duration)
	}
}
コード例 #2
0
ファイル: logging.go プロジェクト: rugby110/glimpse
func dnsLoggingHandler(logger *log.Logger, next dns.Handler) dns.HandlerFunc {
	return func(w dns.ResponseWriter, r *dns.Msg) {
		next.ServeDNS(&loggingWriter{
			ResponseWriter: w,
			logger:         logger,
			start:          time.Now(),
		}, r)
	}
}
コード例 #3
0
ファイル: dns.go プロジェクト: leochencipher/glimpse
// TODO(alx): Settle on naming for handlers acting as middleware.
func protocolHandler(maxAnswers int, next dns.Handler) dns.Handler {
	return dns.HandlerFunc(func(w dns.ResponseWriter, r *dns.Msg) {
		next.ServeDNS(&truncatingWriter{w, maxAnswers}, r)
	})
}