Separate out memory statistics and system information into two different services

This commit is contained in:
Harshavardhana
2015-07-07 16:59:20 -07:00
parent 8abb96c030
commit 676b9058de
4 changed files with 58 additions and 12 deletions

View File

@@ -114,8 +114,9 @@ func getRPCHandler() http.Handler {
s.RegisterJSONCodec()
s.RegisterService(new(rpc.VersionService), "Version")
s.RegisterService(new(rpc.SysInfoService), "SysInfo")
s.RegisterService(new(rpc.MemStatsService), "MemStats")
s.RegisterService(new(rpc.DiskInfoService), "DiskInfo")
s.RegisterService(new(rpc.DonutService), "Donut")
// Add new services here
// Add new RPC services here
return registerRPC(router.NewRouter(), s)
}

View File

@@ -29,13 +29,20 @@ type SysInfoService struct{}
// SysInfoReply -
type SysInfoReply struct {
Hostname string `json:"hostname"`
SysARCH string `json:"sys.arch"`
SysOS string `json:"sys.os"`
SysCPUS int `json:"sys.ncpus"`
Routines int `json:"goroutines"`
GOVersion string `json:"goversion"`
MemStats runtime.MemStats `json:"memstats"`
Hostname string `json:"hostname"`
SysARCH string `json:"sys.arch"`
SysOS string `json:"sys.os"`
SysCPUS int `json:"sys.ncpus"`
Routines int `json:"goroutines"`
GOVersion string `json:"goversion"`
}
// MemStatsService -
type MemStatsService struct{}
// MemStatsReply -
type MemStatsReply struct {
runtime.MemStats `json:"memstats"`
}
func setSysInfoReply(sis *SysInfoReply) error {
@@ -50,11 +57,13 @@ func setSysInfoReply(sis *SysInfoReply) error {
if err != nil {
return iodine.New(err, nil)
}
return nil
}
func setMemStatsReply(sis *MemStatsReply) error {
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
sis.MemStats = memStats
return nil
}
@@ -62,3 +71,8 @@ func setSysInfoReply(sis *SysInfoReply) error {
func (s *SysInfoService) Get(r *http.Request, args *Args, reply *SysInfoReply) error {
return setSysInfoReply(reply)
}
// Get method
func (s *MemStatsService) Get(r *http.Request, args *Args, reply *MemStatsReply) error {
return setMemStatsReply(reply)
}