arl / statsviz

🚀 Visualise your Go program runtime metrics in real time in the browser
MIT License
3.19k stars 121 forks source link

Nothing more than just JS errors #104

Closed bentcoder closed 1 year ago

bentcoder commented 1 year ago

http://0.0.0.0:8001/debug/statsviz/

Screenshot 2023-02-25 at 12 13 41

http://0.0.0.0:8001/debug/statsviz/ws

Screenshot 2023-02-25 at 12 14 14
arl commented 1 year ago

Can you share the exact Go code you're running, as well as the output of running go env in your terminal, please ?

bentcoder commented 1 year ago
package main

import (
    "net/http"

    "github.com/arl/statsviz"
    "github.com/go-chi/chi/v5"
)

func main() {
    user := user{}

    r := chi.NewMux()
    r.HandleFunc("/user", user.create)
    r.Get("/debug/statsviz/ws", statsviz.Ws)
    r.Handle("/debug/statsviz/", statsviz.Index)

    mux := http.NewServeMux()
    statsviz.Register(mux)

    http.ListenAndServe(":8001", r)
}

type user struct{}

func (u user) create(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte(`hi`))
}
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/me/Library/Caches/go-build"
GOENV="/Users/me/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/me/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/me/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4d/gcwrbh1s0nz1xhvb6mbfsv840000gn/T/go-build1449821208=/tmp/go-build -gno-record-gcc-switches -fno-common"
arl commented 1 year ago

You're registering statsviz on a http.ServeMux but you're binding statsviz http handlers to a chi mux. That can't work. Statsviz handlers must be served by the same mux on which you're registering statsviz.

Have a look at chi example https://github.com/arl/statsviz/blob/main/_example/chi/main.go

Even though it's for an older chi version, the big picture should be very similar.

bentcoder commented 1 year ago

Thank you

bentcoder commented 1 year ago

Just a note. /ws page is still bad request but the graphs page is fine.