Skip to content

Commit

Permalink
Add prometheus monitoring for tiler
Browse files Browse the repository at this point in the history
  • Loading branch information
sadlil committed Apr 13, 2017
1 parent bc8b3bb commit 8c81e73
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
7 changes: 7 additions & 0 deletions cmd/tiller/probes.go
Expand Up @@ -18,6 +18,8 @@ package main

import (
"net/http"

"github.com/prometheus/client_golang/prometheus/promhttp"
)

func readinessProbe(w http.ResponseWriter, r *http.Request) {
Expand All @@ -34,3 +36,8 @@ func newProbesMux() *http.ServeMux {
mux.HandleFunc("/liveness", livenessProbe)
return mux
}

func addPrometheusHandler(mux *http.ServeMux) {
// Register HTTP handler for the global Prometheus registry.
mux.Handle("/metrics", promhttp.Handler())
}
14 changes: 14 additions & 0 deletions cmd/tiller/probes_test.go
Expand Up @@ -42,3 +42,17 @@ func TestProbesServer(t *testing.T) {
t.Fatalf("GET /liveness returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
}
}

func TestPrometheus(t *testing.T) {
mux := http.NewServeMux()
addPrometheusHandler(mux)
srv := httptest.NewServer(mux)
defer srv.Close()
resp, err := http.Get(srv.URL + "/metrics")
if err != nil {
t.Fatalf("GET /metrics returned an error (%s)", err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("GET /metrics returned status code %d, expected %d", resp.StatusCode, http.StatusOK)
}
}
6 changes: 6 additions & 0 deletions cmd/tiller/tiller.go
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"strings"

goprom "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/spf13/cobra"

"google.golang.org/grpc"
Expand Down Expand Up @@ -181,6 +182,11 @@ func start(c *cobra.Command, args []string) {

go func() {
mux := newProbesMux()

// Register gRPC server to prometheus to initialized matrix
goprom.Register(rootServer)
addPrometheusHandler(mux)

if err := http.ListenAndServe(probeAddr, mux); err != nil {
probeErrCh <- err
}
Expand Down
48 changes: 35 additions & 13 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Expand Up @@ -43,6 +43,8 @@ import:
- package: github.com/naoina/go-stringutil
version: ~0.1.0
- package: github.com/chai2010/gettext-go
- package: github.com/prometheus/client_golang
version: v0.8.0
testImports:
- package: github.com/stretchr/testify
version: ^1.1.4
Expand Down
5 changes: 3 additions & 2 deletions pkg/tiller/server.go
Expand Up @@ -21,6 +21,7 @@ import (
"log"
"strings"

goprom "github.com/grpc-ecosystem/go-grpc-prometheus"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -55,7 +56,7 @@ func newUnaryInterceptor() grpc.UnaryServerInterceptor {
return nil, err
}
}
return handler(ctx, req)
return goprom.UnaryServerInterceptor(ctx, req, info, handler)
}
}

Expand All @@ -65,7 +66,7 @@ func newStreamInterceptor() grpc.StreamServerInterceptor {
log.Println(err)
return err
}
return handler(srv, ss)
return goprom.StreamServerInterceptor(srv, ss, info, handler)
}
}

Expand Down

0 comments on commit 8c81e73

Please sign in to comment.