mirror of
https://github.com/minio/minio.git
synced 2025-02-02 17:35:58 -05:00
Separate out memory statistics and system information into two different services
This commit is contained in:
parent
8abb96c030
commit
676b9058de
11
commands.go
11
commands.go
@ -101,7 +101,7 @@ func runController(c *cli.Context) {
|
||||
if err != nil {
|
||||
Fatalf("Unable to determine current user. Reason: %s\n", err)
|
||||
}
|
||||
if len(c.Args()) <= 2 || c.Args().First() == "help" {
|
||||
if len(c.Args()) < 2 || c.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
|
||||
}
|
||||
switch c.Args().First() {
|
||||
@ -117,7 +117,16 @@ func runController(c *cli.Context) {
|
||||
Fatalln(err)
|
||||
}
|
||||
Println(string(memstats))
|
||||
case "sysinfo":
|
||||
sysinfo, err := controller.GetSysInfo(c.Args().Tail().First())
|
||||
if err != nil {
|
||||
Fatalln(err)
|
||||
}
|
||||
Println(string(sysinfo))
|
||||
case "donut":
|
||||
if len(c.Args()) <= 2 || c.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
|
||||
}
|
||||
hostname, _ := os.Hostname()
|
||||
err := controller.SetDonut(c.Args().Tail().First(), hostname, c.Args().Tail().Tail())
|
||||
if err != nil {
|
||||
|
@ -47,8 +47,30 @@ func GetDisks(url string) ([]string, error) {
|
||||
return reply.Disks, nil
|
||||
}
|
||||
|
||||
// GetMemStats get system info of the server at given url
|
||||
// GetMemStats get memory status of the server at given url
|
||||
func GetMemStats(url string) ([]byte, error) {
|
||||
op := RPCOps{
|
||||
Method: "MemStats.Get",
|
||||
Request: rpc.Args{Request: ""},
|
||||
}
|
||||
req, err := NewRequest(url, op, http.DefaultTransport)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
resp, err := req.Do()
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var reply rpc.MemStatsReply
|
||||
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
return json.MarshalIndent(reply, "", "\t")
|
||||
}
|
||||
|
||||
// GetSysInfo get system status of the server at given url
|
||||
func GetSysInfo(url string) ([]byte, error) {
|
||||
op := RPCOps{
|
||||
Method: "SysInfo.Get",
|
||||
Request: rpc.Args{Request: ""},
|
||||
@ -96,4 +118,4 @@ func SetDonut(url, hostname string, disks []string) error {
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
// Add more functions here for many replies
|
||||
// Add more functions here for other RPC messages
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -35,7 +35,14 @@ type SysInfoReply struct {
|
||||
SysCPUS int `json:"sys.ncpus"`
|
||||
Routines int `json:"goroutines"`
|
||||
GOVersion string `json:"goversion"`
|
||||
MemStats runtime.MemStats `json:"memstats"`
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user