自动更新管控端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
860 B

package core
import (
"encoding/json"
"fmt"
"net/http"
"runtime"
)
type Dtm struct {
TotalAlloc string `json:"total_alloc"`
Alloc string `json:"alloc"`
}
// 获取内存信息
func Dtmem(w http.ResponseWriter, r *http.Request) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
dtm := Dtm{
TotalAlloc: fmt.Sprintf("%d", m.TotalAlloc),
Alloc: fmt.Sprintf("%v MB", m.Alloc/1024),
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(dtm)
//
// jsonobj, err := json.Marshal(m)
// if err != nil {
// fmt.Fprintf(w, "json marshal faild %v", err)
// return
// }
// fmt.Fprintf(w, "%s", jsonobj)
// usage:=m.TotalAlloc/1024/1024
// free:=m.Free/1024/1024
// //
// fmt.Fprintf("总分配内存: %v MB\n", m.TotalAlloc/1024/1024)
// fmt.Fprintf("已分配内存: %v MB\n", m.Alloc/1024/1024)
}