func (ss *ServerStats) RecvRates() (float64, float64) {
	return ss.recvRateQueue.Rate()
}
RecvRates calculates and returns the rate of received append requests
package stats
import (
	"encoding/json"
	"log"
	"sync"
	"time"
	"github.com/coreos/etcd/raft"
)
type ServerStats struct {
	Name string `json:"name"`
	ID        string         `json:"id"`
	State     raft.StateType `json:"state"`
	StartTime time.Time      `json:"startTime"`
	LeaderInfo struct {
		Name      string    `json:"leader"`
		Uptime    string    `json:"uptime"`
		StartTime time.Time `json:"startTime"`
	} `json:"leaderInfo"`
	RecvAppendRequestCnt uint64  `json:"recvAppendRequestCnt,"`
	RecvingPkgRate       float64 `json:"recvPkgRate,omitempty"`
	RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"`
	SendAppendRequestCnt uint64  `json:"sendAppendRequestCnt"`
	SendingPkgRate       float64 `json:"sendPkgRate,omitempty"`
	SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"`
	sendRateQueue *statsQueue
	recvRateQueue *statsQueue
	sync.Mutex
}
func (ss *ServerStats) JSON() []byte {
	ss.Lock()
	stats := *ss
	ss.Unlock()
	stats.LeaderInfo.Uptime = time.Now().Sub(stats.LeaderInfo.StartTime).String()
	stats.SendingPkgRate, stats.SendingBandwidthRate = stats.SendRates()
	stats.RecvingPkgRate, stats.RecvingBandwidthRate = stats.RecvRates()
	b, err := json.Marshal(stats)
	if err != nil {
		log.Printf("stats: error marshalling server stats: %v", err)
	}
	return b
}
func (ss *ServerStats) Initialize() {
	if ss == nil {
		return
	}
	now := time.Now()
	ss.StartTime = now
	ss.LeaderInfo.StartTime = now
	ss.sendRateQueue = &statsQueue{
		back: -1,
	}
	ss.recvRateQueue = &statsQueue{
		back: -1,
	}
}