Skip to content

Commit

Permalink
Export a metrics endpoint for monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pegerto committed Sep 20, 2017
1 parent b6a1988 commit c339ac2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ import:
- package: golang.org/x/net
subpackages:
- websocket
- package: github.com/prometheus/client_golang
subpackages:
- prometheus
21 changes: 21 additions & 0 deletions router/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package router

import (
"github.com/prometheus/client_golang/prometheus"
"net/http"
)

// Pump message send counter
var pumpMsgSend *prometheus.CounterVec

func init() {
pumpMsgSend = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "pump_msg_send",
Help: "Number of message sent",
},
[]string{"container_id"},
)
prometheus.MustRegister(pumpMsgSend)
HttpHandlers.Register(func() http.Handler { return prometheus.Handler() }, "metrics")
}
2 changes: 2 additions & 0 deletions router/pump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/fsouza/go-dockerclient"
"github.com/prometheus/client_golang/prometheus"
)

var allowTTY bool
Expand Down Expand Up @@ -354,6 +355,7 @@ func newContainerPump(container *docker.Container, stdout, stderr io.Reader) *co
}
return
}
pumpMsgSend.With(prometheus.Labels{"container_id": container.ID}).Inc()
cp.send(&Message{
Data: strings.TrimSuffix(line, "\n"),
Container: container,
Expand Down

0 comments on commit c339ac2

Please sign in to comment.