|
|
|
@ -1,7 +1,6 @@ |
|
|
|
package core |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/rpc/jsonrpc" |
|
|
|
@ -29,7 +28,7 @@ func Dtmem(w http.ResponseWriter, r *http.Request) { |
|
|
|
runtime.ReadMemStats(&m) |
|
|
|
|
|
|
|
// 测试JSONRPC
|
|
|
|
service := "192.168.66.212:9098" |
|
|
|
service := "192.168.66.16:9098" |
|
|
|
client, err := jsonrpc.Dial("tcp", service) |
|
|
|
if err != nil { |
|
|
|
fmt.Fprintf(w, "jsonrpc dial faild %v", err) |
|
|
|
@ -37,14 +36,14 @@ func Dtmem(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
// 调用远程方法
|
|
|
|
var reply string |
|
|
|
var args = Args{"D:\\aaa"} |
|
|
|
var args = Args{"/www/xt"} |
|
|
|
err = client.Call("FileRpcService.GetFilePath", args, &reply) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
fmt.Fprintf(w, "jsonrpc call faild %v", err) |
|
|
|
return |
|
|
|
} |
|
|
|
fmt.Printf("reply: %v", reply) |
|
|
|
// fmt.Printf("reply: %v", reply)
|
|
|
|
//replyJson, err := json.Marshal(reply)
|
|
|
|
// if err != nil {
|
|
|
|
// fmt.Fprintf(w, "json marshal faild %v", err)
|
|
|
|
@ -55,15 +54,14 @@ func Dtmem(w http.ResponseWriter, r *http.Request) { |
|
|
|
// fmt.Fprintf(w, "jsonrpc call success, reply: %v", replyJson)
|
|
|
|
|
|
|
|
// 内存动态
|
|
|
|
dtm := Dtm{ |
|
|
|
TotalAlloc: fmt.Sprintf("%d", m.TotalAlloc), |
|
|
|
|
|
|
|
Alloc: fmt.Sprintf("%v MB", m.Alloc/1024), |
|
|
|
} |
|
|
|
// 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) |
|
|
|
|
|
|
|
// json.NewEncoder(w).Encode(dtm)
|
|
|
|
w.Write([]byte(reply)) |
|
|
|
//
|
|
|
|
// jsonobj, err := json.Marshal(m)
|
|
|
|
// if err != nil {
|
|
|
|
|