File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 7
7
"runtime/debug"
8
8
"strconv"
9
9
10
+ "github.com/arl/statsviz"
11
+ example "github.com/arl/statsviz/_example"
10
12
"github.com/docker/go-units"
11
13
"github.com/gin-gonic/gin"
12
14
)
@@ -22,10 +24,14 @@ func main() {
22
24
}
23
25
24
26
func SetUpRouter (withRoutes bool ) * gin.Engine {
27
+ // Force the GC to work to make the plots "move".
28
+ go example .Work ()
29
+
25
30
r := gin .New ()
26
31
if withRoutes {
27
32
r .GET ("/config" , readConfigHandler )
28
33
r .POST ("/config" , updateConfigHandler )
34
+ r .GET ("/debug/statsviz/*filepath" , statsvizHandler )
29
35
}
30
36
return r
31
37
}
@@ -75,3 +81,11 @@ func updateConfigHandler(c *gin.Context) {
75
81
76
82
c .IndentedJSON (http .StatusOK , req )
77
83
}
84
+
85
+ func statsvizHandler (c * gin.Context ) {
86
+ if c .Param ("filepath" ) == "/ws" {
87
+ statsviz .Ws (c .Writer , c .Request )
88
+ return
89
+ }
90
+ statsviz .IndexAtRoot ("/debug/statsviz" ).ServeHTTP (c .Writer , c .Request )
91
+ }
Original file line number Diff line number Diff line change @@ -132,3 +132,22 @@ func TestUpdateConfigHandler(t *testing.T) {
132
132
t .Errorf ("TestUpdateConfigHandler: want %q, got %q" , test .want , got )
133
133
}
134
134
}
135
+
136
+ func TestStatsvizHandler (t * testing.T ) {
137
+ r := SetUpRouter (false )
138
+ r .GET ("/debug/statsviz/*action" , statsvizHandler )
139
+
140
+ req , _ := http .NewRequest ("GET" , "/debug/statsviz/" , nil )
141
+ w := httptest .NewRecorder ()
142
+
143
+ r .ServeHTTP (w , req )
144
+
145
+ statusOK := w .Code == http .StatusOK
146
+
147
+ p := w .Body .Bytes ()
148
+ pageOK := strings .Index (string (p ), "<title>Statsviz</title>" ) > 0
149
+
150
+ if ! (statusOK && pageOK ) {
151
+ t .Errorf ("TestStatsvizHandler: want %d, got %d" , http .StatusOK , w .Code )
152
+ }
153
+ }
You can’t perform that action at this time.
0 commit comments