Add initial prometheus support to redoctober.

This doesn't add any redoctober-specific metrics yet; it's primarily
intended to be a healthcheck at this point.
This commit is contained in:
Kyle Isom
2016-05-27 14:01:41 -07:00
parent f0590e3df8
commit 79269824ee
+22 -1
View File
@@ -22,6 +22,7 @@ import (
"github.com/cloudflare/redoctober/core"
"github.com/coreos/go-systemd/activation"
"github.com/prometheus/client_golang/prometheus"
)
// List of URLs to register and their related functions
@@ -203,6 +204,21 @@ func (this *indexHandler) handle(w http.ResponseWriter, r *http.Request) {
http.ServeContent(w, r, "index.html", time.Now(), body)
}
// initPrometheus starts a goroutine with a Prometheus listener that
// listens on localhost:metricsPort. If the Prometheus handler can't
// be started, a log.Fatal call is made.
func initPrometheus() {
srv := &http.Server{
Addr: net.JoinHostPort("localhost", metricsPort),
Handler: prometheus.Handler(),
}
log.Printf("metrics.init start: addr=%s", srv.Addr)
go func() {
log.Fatal(srv.ListenAndServe())
}()
}
const usage = `Usage:
redoctober -static <path> -vaultpath <path> -addr <addr> -certs <path1>[,<path2>,...] -keys <path1>[,<path2>,...] [-ca <path>]
@@ -215,6 +231,7 @@ redoctober -vaultpath diskrecord.json -addr localhost:8080 -certs cert1.pem,cert
var (
addr string
metricsPort string
caPath string
certsPath string
hcHost string
@@ -242,6 +259,7 @@ func init() {
flag.StringVar(&hcKey, "hckey", "", "Hipchat API Key")
flag.StringVar(&hcRoom, "hcroom", "", "Hipchat Room Id")
flag.StringVar(&keysPath, "keys", "", "Path(s) of TLS private key in PEM format, comma-separated, must me in the same order as the certs")
flag.StringVar(&metricsPort, "metrics", "8081", "Port to use for metrics.")
flag.StringVar(&roHost, "rohost", "", "RedOctober Url Base (ex: localhost:8080)")
flag.StringVar(&staticPath, "static", "", "Path to override built-in index.html")
flag.BoolVar(&useSystemdSocket, "systemdfds", false, "Use systemd socket activation to listen on a file. Useful for binding privileged sockets.")
@@ -267,9 +285,12 @@ func main() {
log.Fatal(err)
}
initPrometheus()
s, l, err := NewServer(staticPath, addr, caPath, certPaths, keyPaths, useSystemdSocket)
if err != nil {
log.Fatalf("Error starting redoctober server: %s\n", err)
}
s.Serve(l)
log.Printf("http.serve start: addr=%s", addr)
log.Fatal(s.Serve(l))
}