mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
A health middleware
Start http handler on port 8080 and return OK. Also add some documentation fixes for the prometheus middleware.
This commit is contained in:
@@ -45,6 +45,7 @@ var directiveOrder = []directive{
|
||||
{"root", setup.Root},
|
||||
{"bind", setup.BindHost},
|
||||
{"tls", https.Setup},
|
||||
{"health", setup.Health},
|
||||
|
||||
// Other directives that don't create HTTP handlers
|
||||
{"startup", setup.Startup},
|
||||
|
||||
33
core/setup/health.go
Normal file
33
core/setup/health.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/coredns/middleware/health"
|
||||
)
|
||||
|
||||
func Health(c *Controller) (middleware.Middleware, error) {
|
||||
addr, err := parseHealth(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
h := health.Health{Addr: addr}
|
||||
c.Startup = append(c.Startup, h.ListenAndServe)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func parseHealth(c *Controller) (string, error) {
|
||||
addr := ""
|
||||
for c.Next() {
|
||||
args := c.RemainingArgs()
|
||||
|
||||
switch len(args) {
|
||||
case 0:
|
||||
case 1:
|
||||
addr = args[0]
|
||||
default:
|
||||
return "", c.ArgErr()
|
||||
}
|
||||
}
|
||||
return addr, nil
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
const (
|
||||
path = "/metrics"
|
||||
addr = "localhost:9135" // 9153 is occopied by bind_exporter
|
||||
addr = "localhost:9135" // 9153 is occupied by bind_exporter
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
Reference in New Issue
Block a user