mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	* middleware/metrics: add more metrics middleware/cache: Add metrics for number of elements in the cache. Also export the total size. Update README to detail the new metrics. middleware/metrics Move metrics into subpackage called "vars". This breaks the import cycle and is cleaner. This allows vars.Report to be used in the the dnsserver to log refused queries. middleware/metrics: tests Add tests to the metrics framework. The metrics/test subpackage allows scraping of the local server. Do a few test scrape of the metrics that are defined in the metrics middleware. This also allows metrics integration tests to check if the caching and dnssec middleware export their metrics correctly. * update README * typos * fix tests
		
			
				
	
	
		
			63 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package vars
 | |
| 
 | |
| import (
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/miekg/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| // Report reports the metrics data associcated with request.
 | |
| func Report(req request.Request, zone, rcode string, size int, start time.Time) {
 | |
| 	// Proto and Family
 | |
| 	net := req.Proto()
 | |
| 	fam := "1"
 | |
| 	if req.Family() == 2 {
 | |
| 		fam = "2"
 | |
| 	}
 | |
| 
 | |
| 	typ := req.QType()
 | |
| 
 | |
| 	RequestCount.WithLabelValues(zone, net, fam).Inc()
 | |
| 	RequestDuration.WithLabelValues(zone).Observe(float64(time.Since(start) / time.Millisecond))
 | |
| 
 | |
| 	if req.Do() {
 | |
| 		RequestDo.WithLabelValues(zone).Inc()
 | |
| 	}
 | |
| 
 | |
| 	if _, known := monitorType[typ]; known {
 | |
| 		RequestType.WithLabelValues(zone, dns.Type(typ).String()).Inc()
 | |
| 	} else {
 | |
| 		RequestType.WithLabelValues(zone, other).Inc()
 | |
| 	}
 | |
| 
 | |
| 	ResponseSize.WithLabelValues(zone, net).Observe(float64(size))
 | |
| 	RequestSize.WithLabelValues(zone, net).Observe(float64(req.Size()))
 | |
| 
 | |
| 	ResponseRcode.WithLabelValues(zone, rcode).Inc()
 | |
| }
 | |
| 
 | |
| var monitorType = map[uint16]bool{
 | |
| 	dns.TypeAAAA:   true,
 | |
| 	dns.TypeA:      true,
 | |
| 	dns.TypeCNAME:  true,
 | |
| 	dns.TypeDNSKEY: true,
 | |
| 	dns.TypeDS:     true,
 | |
| 	dns.TypeMX:     true,
 | |
| 	dns.TypeNSEC3:  true,
 | |
| 	dns.TypeNSEC:   true,
 | |
| 	dns.TypeNS:     true,
 | |
| 	dns.TypePTR:    true,
 | |
| 	dns.TypeRRSIG:  true,
 | |
| 	dns.TypeSOA:    true,
 | |
| 	dns.TypeSRV:    true,
 | |
| 	dns.TypeTXT:    true,
 | |
| 	// Meta Qtypes
 | |
| 	dns.TypeIXFR: true,
 | |
| 	dns.TypeAXFR: true,
 | |
| 	dns.TypeANY:  true,
 | |
| }
 | |
| 
 | |
| const other = "other"
 |