Skip to content

Commit

Permalink
Provide cadvisor stats as prometheus metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
discordianfish committed Mar 11, 2015
1 parent 5eeb6fd commit 822d60b
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var httpAuthRealm = flag.String("http_auth_realm", "localhost", "HTTP auth realm
var httpDigestFile = flag.String("http_digest_file", "", "HTTP digest file for the web UI")
var httpDigestRealm = flag.String("http_digest_realm", "localhost", "HTTP digest file for the web UI")

var prometheusEndpoint = flag.String("prometheus_endpoint", "/metrics", "Endpoint to expose Prometheus metrics on")

func main() {
defer glog.Flush()
flag.Parse()
Expand Down Expand Up @@ -72,7 +74,7 @@ func main() {
mux := http.DefaultServeMux

// Register all HTTP handlers.
err = cadvisorHttp.RegisterHandlers(mux, containerManager, *httpAuthFile, *httpAuthRealm, *httpDigestFile, *httpDigestRealm)
err = cadvisorHttp.RegisterHandlers(mux, containerManager, *httpAuthFile, *httpAuthRealm, *httpDigestFile, *httpDigestRealm, *prometheusEndpoint)
if err != nil {
glog.Fatalf("Failed to register HTTP handlers: %v", err)
}
Expand Down
8 changes: 7 additions & 1 deletion http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import (
"github.com/google/cadvisor/healthz"
httpMux "github.com/google/cadvisor/http/mux"
"github.com/google/cadvisor/manager"
"github.com/google/cadvisor/metrics"
"github.com/google/cadvisor/pages"
"github.com/google/cadvisor/pages/static"
"github.com/google/cadvisor/validate"
"github.com/prometheus/client_golang/prometheus"
)

func RegisterHandlers(mux httpMux.Mux, containerManager manager.Manager, httpAuthFile, httpAuthRealm, httpDigestFile, httpDigestRealm string) error {
func RegisterHandlers(mux httpMux.Mux, containerManager manager.Manager, httpAuthFile, httpAuthRealm, httpDigestFile, httpDigestRealm, prometheusEndpoint string) error {
// Basic health handler.
if err := healthz.RegisterHandler(mux); err != nil {
return fmt.Errorf("failed to register healthz handler: %s", err)
Expand Down Expand Up @@ -83,6 +85,10 @@ func RegisterHandlers(mux httpMux.Mux, containerManager manager.Manager, httpAut
}
}

collector := metrics.NewPrometheusCollector(containerManager)
prometheus.MustRegister(collector)
http.Handle(prometheusEndpoint, prometheus.Handler())

return nil
}

Expand Down
Loading

0 comments on commit 822d60b

Please sign in to comment.