| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | package vars
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"time"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 22:51:47 -08:00
										 |  |  | 	"github.com/coredns/coredns/request"
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"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) {
 | 
					
						
							| 
									
										
										
										
											2016-11-29 11:02:43 +00:00
										 |  |  | 	// Proto and Family.
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 	net := req.Proto()
 | 
					
						
							|  |  |  | 	fam := "1"
 | 
					
						
							|  |  |  | 	if req.Family() == 2 {
 | 
					
						
							|  |  |  | 		fam = "2"
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	typ := req.QType()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	RequestCount.WithLabelValues(zone, net, fam).Inc()
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:34:26 +01:00
										 |  |  | 	RequestDuration.WithLabelValues(zone).Observe(time.Since(start).Seconds())
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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))
 | 
					
						
							| 
									
										
										
										
											2016-11-29 11:02:43 +00:00
										 |  |  | 	RequestSize.WithLabelValues(zone, net).Observe(float64(req.Len()))
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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"
 |