diff --git a/server/router.go b/server/router.go index 2a74302..2740a52 100644 --- a/server/router.go +++ b/server/router.go @@ -28,13 +28,28 @@ func NewRedisRouter(server *Identity, redisUrl string, password string, db int, }) r.InvitationTimeout = invitationTimeout 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 } func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) { var from_server meowlib.FromServerMessage + // update messages counter + err := r.Client.Incr("statistics:messages:total").Err() + if err != nil { + panic(err) + } // user message 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 { // serialize the message to store it as byte array into redis out, err := proto.Marshal(usrmsg) @@ -47,6 +62,11 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe } // check for messages 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 { msgcnt, err := r.Client.ZCount(rq.LookupKey, "-inf", "+inf").Result() if err != nil { @@ -75,6 +95,11 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe } // manage Matriochka 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) if err != nil { return nil, err @@ -91,6 +116,11 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe } // Through server invitation process if msg.Invitation != nil { + // update messages counter + err := r.Client.Incr("statistics:messages:invitation").Err() + if err != nil { + panic(err) + } switch msg.Invitation.Step { case 1: // create invitation url, expiry := r.CreateInvitation(msg.Invitation.Payload, int(msg.Invitation.Timeout), msg.Invitation.Password, r.InvitationTimeout, int(msg.Invitation.ShortcodeLen))