Skip to content

Commit

Permalink
Merge branch 'add_metrix' into add_metrix
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks authored Jun 3, 2024
2 parents 69069e2 + 12a3ccc commit 4202962
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
1 change: 0 additions & 1 deletion codis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.29.0

require (
github.com/BurntSushi/toml v0.3.1
github.com/CodisLabs/codis v0.0.0-20181104082235-de1ad026e329
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/emirpasic/gods v1.18.1
github.com/garyburd/redigo v1.6.4
Expand Down
2 changes: 0 additions & 2 deletions codis/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/CodisLabs/codis v0.0.0-20181104082235-de1ad026e329 h1:KyRmPlfd2xewxb54vIBPNILFyCh2R3zNDwLZURDxT0E=
github.com/CodisLabs/codis v0.0.0-20181104082235-de1ad026e329/go.mod h1:7p/InQNYNEI8sdFDMqA1rZqszJBZMZekIcWYf6N6s2M=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
Expand Down
5 changes: 0 additions & 5 deletions codis/pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,14 +739,9 @@ func (p *Proxy) Stats(flags StatsFlags) *Stats {

stats.Ops.Total = OpTotal()
stats.Ops.Fails = OpFails()
log.Infof("Ops.Fails : %v", stats.Ops.Fails)
stats.Ops.Redis.Errors = OpRedisErrors()
stats.Ops.QPS = OpQPS()
stats.Ops.Cmd = GetOpStatsByInterval(1)
log.Infof("stats.Ops.Cmd : %v", stats.Ops.Cmd)
for idx := range stats.Ops.Cmd {
log.Infof("cmd infos i:%v , cmd :%v", idx, stats.Ops.Cmd[idx])
}
if flags.HasBit(StatsCmds) {
stats.Ops.Cmd = GetOpStatsAll()
}
Expand Down
20 changes: 20 additions & 0 deletions codis/pkg/proxy/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"pika/codis/v2/pkg/models"
"pika/codis/v2/pkg/proxy/redis"
"pika/codis/v2/pkg/utils"
"pika/codis/v2/pkg/utils/errors"
"pika/codis/v2/pkg/utils/log"
"pika/codis/v2/pkg/utils/sync2/atomic2"
Expand Down Expand Up @@ -249,6 +250,7 @@ func (s *Session) loopWriter(tasks *RequestChan) (err error) {
}
if s.config.SlowlogLogSlowerThan >= 0 {
if duration >= s.config.SlowlogLogSlowerThan {
SlowCmdCount.Incr()
// Atomic global variable, increment by 1 when slow log occurs.
//client -> proxy -> server -> porxy -> client
//Record the waiting time from receiving the request from the client to sending it to the backend server
Expand Down Expand Up @@ -306,6 +308,8 @@ func (s *Session) handleRequest(r *Request, d *Router) error {
return s.handleQuit(r)
case "AUTH":
return s.handleAuth(r)
case "CODIS.INFO":
return s.handleCodisInfo(r)
}

if !s.authorized {
Expand Down Expand Up @@ -368,6 +372,22 @@ func (s *Session) handleAuth(r *Request) error {
return nil
}

func (s *Session) handleCodisInfo(r *Request) error {
if len(r.Multi) != 0 {
r.Resp = redis.NewErrorf("ERR wrong number of arguments for 'CODIS.INFO' command")
return nil
}

r.Resp = redis.NewArray([]*redis.Resp{
redis.NewString([]byte(utils.Version)),
redis.NewString([]byte(utils.Compile)),
redis.NewString([]byte(fmt.Sprintf("admin addr: %s", s.proxy.model.AdminAddr))),
redis.NewString([]byte(fmt.Sprintf("start time: %s", s.proxy.model.StartTime))),
})

return nil
}

func (s *Session) handleSelect(r *Request) error {
if len(r.Multi) != 2 {
r.Resp = redis.NewErrorf("ERR wrong number of arguments for 'SELECT' command")
Expand Down
18 changes: 3 additions & 15 deletions codis/pkg/proxy/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package proxy

import (
"encoding/json"
"math"
"sort"
"sync"
Expand All @@ -18,11 +17,11 @@ import (
)

const (
TPFirstGrade = 5 //5ms - 200ms
TPFirstGrade = 5 // 5ms - 200ms
TPFirstGradeSize = 40
TPSecondGrade = 25 //225ms - 700ms
TPSecondGrade = 25 // 225ms - 700ms
TPSecondGradeSize = 20
TPThirdGrade = 250 //950ms - 3200ms
TPThirdGrade = 250 // 950ms - 3200ms
TPThirdGradeSize = 10
TPMaxNum = TPFirstGradeSize + TPSecondGradeSize + TPThirdGradeSize
ClearSlowFlagPeriodRate = 3 // The cleanup cycle for slow commands is three times the duration of the statistics cycle.
Expand Down Expand Up @@ -659,14 +658,3 @@ func GetSysUsage() *SysUsage {
}
return nil
}

func ToJsonString(obj interface{}) string {
if obj == nil {
return ""
}
data, err := json.Marshal(obj)
if err != nil {
return ""
}
return string(data)
}

0 comments on commit 4202962

Please sign in to comment.