| 
									
										
										
										
											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
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-25 19:04:03 +00:00
										 |  |  | // Report reports the metrics data associated with request. This function is exported because it is also
 | 
					
						
							|  |  |  | // called from core/dnsserver to report requests hitting the server that should not be handled and are thus
 | 
					
						
							|  |  |  | // not sent down the plugin chain.
 | 
					
						
							| 
									
										
										
										
											2022-09-08 14:56:27 -04:00
										 |  |  | func Report(server string, req request.Request, zone, view, rcode, plugin 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"
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if req.Do() {
 | 
					
						
							| 
									
										
										
										
											2022-09-08 14:56:27 -04:00
										 |  |  | 		RequestDo.WithLabelValues(server, zone, view).Inc()
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-28 10:50:23 +02:00
										 |  |  | 	qType := qTypeString(req.QType())
 | 
					
						
							| 
									
										
										
										
											2022-09-08 14:56:27 -04:00
										 |  |  | 	RequestCount.WithLabelValues(server, zone, view, net, fam, qType).Inc()
 | 
					
						
							| 
									
										
										
										
											2021-03-19 12:59:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 14:56:27 -04:00
										 |  |  | 	RequestDuration.WithLabelValues(server, zone, view).Observe(time.Since(start).Seconds())
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 14:56:27 -04:00
										 |  |  | 	ResponseSize.WithLabelValues(server, zone, view, net).Observe(float64(size))
 | 
					
						
							|  |  |  | 	RequestSize.WithLabelValues(server, zone, view, net).Observe(float64(req.Len()))
 | 
					
						
							| 
									
										
										
										
											2016-10-26 10:01:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-08 14:56:27 -04:00
										 |  |  | 	ResponseRcode.WithLabelValues(server, zone, view, rcode, plugin).Inc()
 | 
					
						
							| 
									
										
										
										
											2018-04-18 09:42:20 +01:00
										 |  |  | }
 |