add basic server statistics to redis db
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
420b7d0af0
commit
4cd928fdc6
@ -28,13 +28,28 @@ func NewRedisRouter(server *Identity, redisUrl string, password string, db int,
|
|||||||
})
|
})
|
||||||
r.InvitationTimeout = invitationTimeout
|
r.InvitationTimeout = invitationTimeout
|
||||||
r.Context = context.Background()
|
r.Context = context.Background()
|
||||||
|
// set start for uptime
|
||||||
|
err := r.Client.Set("statistics:start", time.Now(), 0).Err()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return &r
|
return &r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
|
func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) {
|
||||||
var from_server meowlib.FromServerMessage
|
var from_server meowlib.FromServerMessage
|
||||||
|
// update messages counter
|
||||||
|
err := r.Client.Incr("statistics:messages:total").Err()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
// user message
|
// user message
|
||||||
if len(msg.Messages) > 0 {
|
if len(msg.Messages) > 0 {
|
||||||
|
// update messages counter
|
||||||
|
err := r.Client.Incr("statistics:messages:usermessages").Err()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
for _, usrmsg := range msg.Messages {
|
for _, usrmsg := range msg.Messages {
|
||||||
// serialize the message to store it as byte array into redis
|
// serialize the message to store it as byte array into redis
|
||||||
out, err := proto.Marshal(usrmsg)
|
out, err := proto.Marshal(usrmsg)
|
||||||
@ -47,6 +62,11 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
|||||||
}
|
}
|
||||||
// check for messages
|
// check for messages
|
||||||
if len(msg.PullRequest) > 0 {
|
if len(msg.PullRequest) > 0 {
|
||||||
|
// update messages counter
|
||||||
|
err := r.Client.Incr("statistics:messages:messagelookups").Err()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
for _, rq := range msg.PullRequest {
|
for _, rq := range msg.PullRequest {
|
||||||
msgcnt, err := r.Client.ZCount(rq.LookupKey, "-inf", "+inf").Result()
|
msgcnt, err := r.Client.ZCount(rq.LookupKey, "-inf", "+inf").Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -75,6 +95,11 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
|||||||
}
|
}
|
||||||
// manage Matriochka
|
// manage Matriochka
|
||||||
if msg.MatriochkaMessage != nil {
|
if msg.MatriochkaMessage != nil {
|
||||||
|
// update messages counter
|
||||||
|
err := r.Client.Incr("statistics:messages:matriochka").Err()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
out, err := proto.Marshal(msg)
|
out, err := proto.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -91,6 +116,11 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
|
|||||||
}
|
}
|
||||||
// Through server invitation process
|
// Through server invitation process
|
||||||
if msg.Invitation != nil {
|
if msg.Invitation != nil {
|
||||||
|
// update messages counter
|
||||||
|
err := r.Client.Incr("statistics:messages:invitation").Err()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
switch msg.Invitation.Step {
|
switch msg.Invitation.Step {
|
||||||
case 1: // create invitation
|
case 1: // create invitation
|
||||||
url, expiry := r.CreateInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))
|
url, expiry := r.CreateInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))
|
||||||
|
Loading…
Reference in New Issue
Block a user