-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from jelmersnoeck/add-metrics-server
Add Prometheus Metrics server.
- Loading branch information
Showing
10 changed files
with
507 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package httpsvc | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
// Metrics represents a Metrics server which can be used to expose a prometheus | ||
// metrics. | ||
type Metrics struct { | ||
Server | ||
*prometheus.Registry | ||
} | ||
|
||
// Start starts the Health Server. | ||
func (s *Metrics) Start(stopCh <-chan struct{}) error { | ||
registerMetrics(&s.ServeMux, s.Registry) | ||
registerHealthCheck(&s.ServeMux) | ||
|
||
return s.Server.Start(stopCh) | ||
} | ||
|
||
func registerMetrics(mux *http.ServeMux, reg *prometheus.Registry) { | ||
mux.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{})) | ||
} | ||
|
||
func registerHealthCheck(mux *http.ServeMux) { | ||
mux.HandleFunc("/_healthz", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintln(w, "OK") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.