@@ -18,7 +18,9 @@ package diagnostics
18
18
19
19
import (
20
20
"encoding/json"
21
+ "fmt"
21
22
"net/http"
23
+ "runtime/pprof"
22
24
23
25
diaglib "github.com/ledgerwatch/erigon-lib/diagnostics"
24
26
"github.com/ledgerwatch/erigon-lib/sysutils"
@@ -30,28 +32,37 @@ func SetupSysInfoAccess(metricsMux *http.ServeMux, diag *diaglib.DiagnosticClien
30
32
}
31
33
32
34
metricsMux .HandleFunc ("/hardware-info" , func (w http.ResponseWriter , r * http.Request ) {
33
- w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
34
35
w .Header ().Set ("Content-Type" , "application/json" )
35
36
writeHardwareInfo (w , diag )
36
37
})
37
38
38
39
metricsMux .HandleFunc ("/cpu-usage" , func (w http.ResponseWriter , r * http.Request ) {
39
- w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
40
40
w .Header ().Set ("Content-Type" , "application/json" )
41
41
writeCPUUsage (w )
42
42
})
43
43
44
44
metricsMux .HandleFunc ("/processes-info" , func (w http.ResponseWriter , r * http.Request ) {
45
- w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
46
45
w .Header ().Set ("Content-Type" , "application/json" )
47
46
writeProcessesInfo (w )
48
47
})
49
48
50
49
metricsMux .HandleFunc ("/memory-info" , func (w http.ResponseWriter , r * http.Request ) {
51
- w .Header ().Set ("Access-Control-Allow-Origin" , "*" )
52
50
w .Header ().Set ("Content-Type" , "application/json" )
53
51
writeMemoryInfo (w )
54
52
})
53
+
54
+ metricsMux .HandleFunc ("/heap-profile" , func (w http.ResponseWriter , r * http.Request ) {
55
+ w .Header ().Set ("Content-Type" , "aplication/profile" )
56
+ writeHeapProfile (w )
57
+ })
58
+ }
59
+
60
+ func writeHeapProfile (w http.ResponseWriter ) {
61
+ err := pprof .Lookup ("heap" ).WriteTo (w , 0 )
62
+ if err != nil {
63
+ http .Error (w , fmt .Sprintf ("Failed to write profile: %v" , err ), http .StatusInternalServerError )
64
+ return
65
+ }
55
66
}
56
67
57
68
func writeHardwareInfo (w http.ResponseWriter , diag * diaglib.DiagnosticClient ) {
0 commit comments