Browse Source

jsonrpc调试输出

master
xyiege 5 months ago
parent
commit
9602c41848
  1. 13
      aufs/core/dtmem.go
  2. 4
      scagent/main.go

13
aufs/core/dtmem.go

@ -13,6 +13,16 @@ type Dtm struct {
Alloc string `json:"alloc"` Alloc string `json:"alloc"`
} }
// for rpc
type Args struct {
FilePath string
}
// 返回的参数
type Reply struct {
FilePath string `json:"file_path"`
}
// 获取内存信息 // 获取内存信息
func Dtmem(w http.ResponseWriter, r *http.Request) { func Dtmem(w http.ResponseWriter, r *http.Request) {
var m runtime.MemStats var m runtime.MemStats
@ -27,7 +37,8 @@ func Dtmem(w http.ResponseWriter, r *http.Request) {
} }
// 调用远程方法 // 调用远程方法
var reply string var reply string
err = client.Call("core.FileRpc.GetFilePath", "/www", &reply) var args = Args{"/www"}
err = client.Call("FileRpcService.GetFilePath", args, &reply)
if err != nil { if err != nil {
fmt.Fprintf(w, "jsonrpc call faild %v", err) fmt.Fprintf(w, "jsonrpc call faild %v", err)
return return

4
scagent/main.go

@ -46,6 +46,9 @@ func main() {
defer logger.Sync() defer logger.Sync()
logger.Info("JSON RPC服务端启动") logger.Info("JSON RPC服务端启动")
// 读取配置文件
util.ReadConfig()
// 检查是否以守护进程方式运行 // 检查是否以守护进程方式运行
if isDaemon() { if isDaemon() {
// 以守护进程方式运行 // 以守护进程方式运行
@ -58,6 +61,7 @@ func main() {
} }
// //
sport := fmt.Sprintf(":%v", config.G.Port) sport := fmt.Sprintf(":%v", config.G.Port)
logger.Info("Listen port", zap.String("port", sport))
tcpAddr, err := net.ResolveTCPAddr("tcp", sport) tcpAddr, err := net.ResolveTCPAddr("tcp", sport)
if err != nil { if err != nil {
logger.Error("ResolveTCPAddr failed", zap.Error(err)) logger.Error("ResolveTCPAddr failed", zap.Error(err))

Loading…
Cancel
Save