|  | @@ -3,6 +3,7 @@ package example
 | 
	
		
			
				|  |  |  import (
 | 
	
		
			
				|  |  |  	"github.com/coredns/coredns/core/dnsserver"
 | 
	
		
			
				|  |  |  	"github.com/coredns/coredns/plugin"
 | 
	
		
			
				|  |  | +	"github.com/coredns/coredns/plugin/metrics"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	"github.com/mholt/caddy"
 | 
	
		
			
				|  |  |  )
 | 
	
	
		
			
				|  | @@ -27,6 +28,14 @@ func setup(c *caddy.Controller) error {
 | 
	
		
			
				|  |  |  		return plugin.Error("example", c.ArgErr())
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	// Add a startup function that will -- after all plugins have been loaded -- check if the
 | 
	
		
			
				|  |  | +	// prometheus plugin has been used - if so we will export metrics. We can only register
 | 
	
		
			
				|  |  | +	// this metric once, hence the "once.Do".
 | 
	
		
			
				|  |  | +	c.OnStartup(func() error {
 | 
	
		
			
				|  |  | +		once.Do(func() { metrics.MustRegister(c, requestCount) })
 | 
	
		
			
				|  |  | +		return nil
 | 
	
		
			
				|  |  | +	})
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	// Add the Plugin to CoreDNS, so Servers can use it in their plugin chain.
 | 
	
		
			
				|  |  |  	dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
 | 
	
		
			
				|  |  |  		return Example{Next: next}
 |