Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions cmd/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"crypto/tls"
"flag"
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
Expand All @@ -26,6 +27,9 @@ import (
"strings"
"syscall"

// Listen on VSOCK sockets
"github.com/mdlayher/vsock"

cadvisorhttp "github.com/google/cadvisor/cmd/internal/http"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/manager"
Expand All @@ -48,7 +52,7 @@ import (
)

var argIP = flag.String("listen_ip", "", "IP to listen on, defaults to all IPs")
var argPort = flag.Int("port", 8080, "port to listen")
var argPort = flag.Uint("port", 8080, "port to listen")
var maxProcs = flag.Int("max_procs", 0, "max number of CPUs that can be used simultaneously. Less than 1 for default (number of cores).")

var versionFlag = flag.Bool("version", false, "print cAdvisor version and exit")
Expand Down Expand Up @@ -181,8 +185,33 @@ func main() {
rootMux := http.NewServeMux()
rootMux.Handle(*urlBasePrefix+"/", http.StripPrefix(*urlBasePrefix, mux))

addr := fmt.Sprintf("%s:%d", *argIP, *argPort)
klog.Fatal(http.ListenAndServe(addr, rootMux))
scheme_and_host := strings.SplitN(*argIP, "://", 2)

host := scheme_and_host[len(scheme_and_host) - 1]

scheme := scheme_and_host[0]
if len(scheme_and_host) == 1 || scheme == "http" || scheme == "https" {
scheme = "tcp"
}

var listener net.Listener
if scheme == "vsock" {
port := uint32(*argPort)
vsock_listener, err := vsock.Listen(port, nil)
if err != nil {
klog.Fatalf("Failed listen to VSOCK port %d: %s", port, err)
}
listener = vsock_listener
} else {
address := fmt.Sprintf("%s:%d", host, *argPort)
tcp_listener, err := net.Listen(scheme, address)
if err != nil {
klog.Fatalf("Failed listen to HTTP address '%s': %s", address, err)
}
listener = tcp_listener
}

klog.Fatal(http.Serve(listener, rootMux))
}

func setMaxProcs() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/abbot/go-http-auth v0.4.0
github.com/gomodule/redigo v1.9.2
github.com/influxdb/influxdb v1.7.9
github.com/mdlayher/vsock v1.2.1
github.com/mesos/mesos-go v0.0.11
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.24.1 // indirect
Expand Down Expand Up @@ -94,6 +95,7 @@ require (
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
Expand Down Expand Up @@ -123,6 +125,7 @@ require (
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.25.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250528174236-200df99c418a // indirect
Expand Down
4 changes: 4 additions & 0 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ=
github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE=
github.com/mesos/mesos-go v0.0.11 h1:jMp9+W3zLu46g8EuP2su2Sjj7ipBh4N/g65c0kzGl/8=
github.com/mesos/mesos-go v0.0.11/go.mod h1:kPYCMQ9gsOXVAle1OsoY4I1+9kPu8GHkf88aV59fDr4=
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible h1:aKW/4cBs+yK6gpqU3K/oIwk9Q/XICqd3zOX/UFuvqmk=
Expand Down