Skip to content

Commit 657063b

Browse files
committed
Initial Prometheus metrics support
1 parent 3889705 commit 657063b

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

Gopkg.lock

+51-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+8
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@
2121
[[constraint]]
2222
name = "k8s.io/client-go"
2323
version = "~7.0.0"
24+
25+
[[constraint]]
26+
name = "github.com/prometheus/client_golang"
27+
version = "0.8.0"
28+
29+
[[override]]
30+
name = "github.com/golang/protobuf"
31+
version = "1.1.0"

main.go

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"time"
99

10+
"github.com/prometheus/client_golang/prometheus/promhttp"
1011
log "github.com/sirupsen/logrus"
1112
"gopkg.in/alecthomas/kingpin.v2"
1213

@@ -154,10 +155,21 @@ func main() {
154155
)
155156

156157
if metricsAddress != "" {
158+
http.Handle("/metrics", promhttp.Handler())
157159
http.HandleFunc("/healthz",
158160
func(w http.ResponseWriter, r *http.Request) {
159161
fmt.Fprintln(w, "OK")
160162
})
163+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
164+
w.Write([]byte(`<html>
165+
<head><title>chaoskube</title></head>
166+
<body>
167+
<h1>chaoskube</h1>
168+
<p><a href="/metrics">Metrics</a></p>
169+
<p><a href="/healthz">Health Check</a></p>
170+
</body>
171+
</html>`))
172+
})
161173
go func() {
162174
if err := http.ListenAndServe(metricsAddress, nil); err != nil {
163175
log.WithFields(log.Fields{

0 commit comments

Comments
 (0)