Skip to content

Commit cfc98a2

Browse files
authored
Merge pull request #224 from intelops/pprof
added liveness and pprof
2 parents f07c97d + 8e5ebdb commit cfc98a2

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

agent/kubviz/k8smetrics_agent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
3030

3131
// _ "k8s.io/client-go/plugin/pkg/client/auth/openstack"
32+
"github.com/intelops/kubviz/agent/server"
3233
"k8s.io/client-go/tools/cache"
3334
"k8s.io/client-go/tools/clientcmd"
3435
)
@@ -104,7 +105,7 @@ func main() {
104105
clientset = getK8sClient(config)
105106
}
106107
go publishMetrics(clientset, js, clusterMetricsChan)
107-
108+
go server.StartServer()
108109
collectAndPublishMetrics := func() {
109110
err := outDatedImages(config, js)
110111
LogErr(err)

agent/server/server.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package server
2+
3+
import (
4+
"log"
5+
"net/http"
6+
_ "net/http/pprof"
7+
8+
"github.com/gin-gonic/gin"
9+
)
10+
11+
func EnableProfile(r *gin.Engine) {
12+
pprofGroup := r.Group("/debug/pprof")
13+
{
14+
pprofGroup.GET("/", gin.WrapH(http.DefaultServeMux))
15+
pprofGroup.GET("/cmdline", gin.WrapH(http.DefaultServeMux))
16+
pprofGroup.GET("/profile", gin.WrapH(http.DefaultServeMux))
17+
pprofGroup.POST("/symbol", gin.WrapH(http.DefaultServeMux))
18+
pprofGroup.GET("/symbol", gin.WrapH(http.DefaultServeMux))
19+
pprofGroup.GET("/trace", gin.WrapH(http.DefaultServeMux))
20+
pprofGroup.GET("/allocs", gin.WrapH(http.DefaultServeMux))
21+
pprofGroup.GET("/block", gin.WrapH(http.DefaultServeMux))
22+
pprofGroup.GET("/goroutine", gin.WrapH(http.DefaultServeMux))
23+
pprofGroup.GET("/heap", gin.WrapH(http.DefaultServeMux))
24+
pprofGroup.GET("/mutex", gin.WrapH(http.DefaultServeMux))
25+
pprofGroup.GET("/threadcreate", gin.WrapH(http.DefaultServeMux))
26+
}
27+
28+
r.GET("/liveness", func(c *gin.Context) {
29+
c.String(http.StatusOK, "Alive")
30+
})
31+
}
32+
33+
func StartServer() {
34+
r := gin.Default()
35+
EnableProfile(r)
36+
log.Fatal(r.Run(":8080"))
37+
}

0 commit comments

Comments
 (0)