github.com/therealbill/libredis@v0.0.0-20161227004305-7d50abda5ccf/client/latency.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "log" 6 //"reflect" 7 //"strconv" 8 ) 9 10 // LatencyRecord records a laency entry 11 type LatencyRecord struct { 12 Timestamp int64 13 Milliseconds int64 14 } 15 16 // LatencyHistory contains the available LatencyRecords for a given event 17 type LatencyHistory struct { 18 Event string 19 Records []LatencyRecord 20 } 21 22 //SetLatencyThreshold sets the number of milliseconds an event must reach to trigger storage 23 func (r *Redis) SetLatencyThreshold(ms int) error { 24 res := r.ConfigSetInt("latency-monitor-threshold", ms) 25 return res 26 } 27 28 //LatencyResetAll reselts counters for all events 29 func (r *Redis) LatencyResetAll() error { 30 _, err := r.ExecuteCommand("latency", "reset") 31 return err 32 } 33 34 //LatencyResetEvent reselts counters for all the specified event 35 func (r *Redis) LatencyResetEvent(event string) error { 36 _, err := r.ExecuteCommand("latency", "reset", event) 37 return err 38 } 39 40 //LatencyResetEvents reselts counters for all the specified events 41 func (r *Redis) LatencyResetEvents(events []string) error { 42 for _, s := range events { 43 _, _ = r.ExecuteCommand("latency", "reset", s) 44 } 45 return nil 46 } 47 48 //LatencyHistory returns the available LatencyRecords for an event 49 func (r *Redis) LatencyHistory(event string) (history LatencyHistory, err error) { 50 history = LatencyHistory{Event: event} 51 res, err := r.ExecuteCommand("latency", "history", event) 52 if err != nil { 53 log.Print(err) 54 return history, err 55 } 56 for _, val := range res.Multi { 57 var record LatencyRecord 58 for i, entry := range val.Multi { 59 switch i { 60 case 0: 61 record.Timestamp, _ = entry.IntegerValue() 62 case 1: 63 record.Milliseconds, _ = entry.IntegerValue() 64 } 65 } 66 history.Records = append(history.Records, record) 67 } 68 return history, nil 69 } 70 71 // LatencyDoctor returns the outut form the Redis latency doctor command 72 func (r *Redis) LatencyDoctor() (text string, err error) { 73 res, err := r.ExecuteCommand("latency", "doctor") 74 if err != nil { 75 return text, fmt.Errorf("Latency not supported on this instance") 76 } 77 return res.StringValue() 78 }