Skip to content
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
12 changes: 12 additions & 0 deletions app/dispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ func (d *DefaultDispatcher) getLink(ctx context.Context) (*transport.Link, *tran
}
}
}

if p.Stats.UserOnline {
name := "user>>>" + user.Email + ">>>online"
if om, _ := stats.GetOrRegisterOnlineMap(d.stats, name); om != nil {
sessionInbounds := session.InboundFromContext(ctx)
userIP := sessionInbounds.Source.Address.String()
om.AddIP(userIP)
// log Online user with ips
// errors.LogDebug(ctx, "user>>>" + user.Email + ">>>online", om.Count(), om.List())

}
}
}

return inboundLink, outboundLink
Expand Down
1 change: 1 addition & 0 deletions app/policy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (p *Policy) ToCorePolicy() policy.Session {
if p.Stats != nil {
cp.Stats.UserUplink = p.Stats.UserUplink
cp.Stats.UserDownlink = p.Stats.UserDownlink
cp.Stats.UserOnline = p.Stats.UserOnline
}
if p.Buffer != nil {
cp.Buffer.PerConnection = p.Buffer.Connection
Expand Down
192 changes: 150 additions & 42 deletions app/policy/config.pb.go

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

1 change: 1 addition & 0 deletions app/policy/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ message Policy {
message Stats {
bool user_uplink = 1;
bool user_downlink = 2;
bool user_online = 3;
}

message Buffer {
Expand Down
14 changes: 14 additions & 0 deletions app/stats/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*
}, nil
}

func (s *statsServer) GetStatsOnline(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
c := s.stats.GetOnlineMap(request.Name)
if c == nil {
return nil, errors.New(request.Name, " not found.")
}
value := int64(c.Count())
return &GetStatsResponse{
Stat: &Stat{
Name: request.Name,
Value: value,
},
}, nil
}

func (s *statsServer) QueryStats(ctx context.Context, request *QueryStatsRequest) (*QueryStatsResponse, error) {
matcher, err := strmatcher.Substr.New(request.Pattern)
if err != nil {
Expand Down
Loading