8000 add StatsService.GetSysStats by vcptr · Pull Request #1794 · v2ray/v2ray-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add StatsService.GetSysStats #1794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions app/stats/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package command

import (
"context"
"runtime"
"time"

grpc "google.golang.org/grpc"

Expand All @@ -18,11 +20,15 @@ import (

// statsServer is an implementation of StatsService.
type statsServer struct {
stats feature_stats.Manager
stats feature_stats.Manager
startTime time.Time
}

func NewStatsServer(manager feature_stats.Manager) StatsServiceServer {
return &statsServer{stats: manager}
return &statsServer{
stats: manager,
startTime: time.Now(),
}
}

func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
Expand Down Expand Up @@ -76,6 +82,28 @@ func (s *statsServer) QueryStats(ctx context.Context, request *QueryStatsRequest
return response, nil
}

func (s *statsServer) GetSysStats(ctx context.Context, request *SysStatsRequest) (*SysStatsResponse, error) {
var rtm runtime.MemStats
runtime.ReadMemStats(&rtm)

uptime := time.Since(s.startTime)

response := &SysStatsResponse{
Uptime: uint32(uptime.Seconds()),
NumGoroutine: uint32(runtime.NumGoroutine()),
Alloc: rtm.Alloc,
TotalAlloc: rtm.TotalAlloc,
Sys: rtm.Sys,
Mallocs: rtm.Mallocs,
Frees: rtm.Frees,
LiveObjects: rtm.Mallocs - rtm.Frees,
NumGC: rtm.NumGC,
PauseTotalNs: rtm.PauseTotalNs,
}

return response, nil
}

type service struct {
statsManager feature_stats.Manager
}
Expand Down
252 changes: 229 additions & 23 deletions app/stats/command/command.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
0