Merge pull request #189 from philips/cleanup-stats-further

cleanup the stats json a bit
This commit is contained in:
Xiang Li 2013-09-26 13:00:39 -07:00
commit 21f6b50607
4 changed files with 47 additions and 21 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ src/
pkg/ pkg/
/etcd /etcd
release_version.go release_version.go
/machine*

View File

@ -172,7 +172,8 @@ func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
// add peer stats // add peer stats
if c.Name != r.Name() { if c.Name != r.Name() {
r.peersStats.Peers[c.Name] = &raftPeerStats{MinLatency: 1 << 63} r.peersStats.Peers[c.Name] = &raftPeerStats{}
r.peersStats.Peers[c.Name].Latency.Minimum = 1 << 63
} }
return b, err return b, err

View File

@ -85,43 +85,48 @@ type raftPeersStats struct {
} }
type raftPeerStats struct { type raftPeerStats struct {
Latency float64 `json:"latency"` Latency struct {
AvgLatency float64 `json:"averageLatency"` Current float64 `json:"current"`
avgLatencySquare float64 Average float64 `json:"average"`
SdvLatency float64 `json:"sdvLatency"` averageSquare float64
MinLatency float64 `json:"minLatency"` StandardDeviation float64 `json:"standardDeviation"`
MaxLatency float64 `json:"maxLatency"` Minimum float64 `json:"minimum"`
FailCnt uint64 `json:"failsCount"` Maximum float64 `json:"maximum"`
SuccCnt uint64 `json:"successCount"` } `json:"latency"`
Counts struct {
Fail uint64 `json:"fail"`
Success uint64 `json:"success"`
} `json:"counts"`
} }
// Succ function update the raftPeerStats with a successful send // Succ function update the raftPeerStats with a successful send
func (ps *raftPeerStats) Succ(d time.Duration) { func (ps *raftPeerStats) Succ(d time.Duration) {
total := float64(ps.SuccCnt) * ps.AvgLatency total := float64(ps.Counts.Success) * ps.Latency.Average
totalSquare := float64(ps.SuccCnt) * ps.avgLatencySquare totalSquare := float64(ps.Counts.Success) * ps.Latency.averageSquare
ps.SuccCnt++ ps.Counts.Success++
ps.Latency = float64(d) / (1000000.0) ps.Latency.Current = float64(d) / (1000000.0)
if ps.Latency > ps.MaxLatency { if ps.Latency.Current > ps.Latency.Maximum {
ps.MaxLatency = ps.Latency ps.Latency.Maximum = ps.Latency.Current
} }
if ps.Latency < ps.MinLatency { if ps.Latency.Current < ps.Latency.Minimum {
ps.MinLatency = ps.Latency ps.Latency.Minimum = ps.Latency.Current
} }
ps.AvgLatency = (total + ps.Latency) / float64(ps.SuccCnt) ps.Latency.Average = (total + ps.Latency.Current) / float64(ps.Counts.Success)
ps.avgLatencySquare = (totalSquare + ps.Latency*ps.Latency) / float64(ps.SuccCnt) ps.Latency.averageSquare = (totalSquare + ps.Latency.Current * ps.Latency.Current) / float64(ps.Counts.Success)
// sdv = sqrt(avg(x^2) - avg(x)^2) // sdv = sqrt(avg(x^2) - avg(x)^2)
ps.SdvLatency = math.Sqrt(ps.avgLatencySquare - ps.AvgLatency*ps.AvgLatency) ps.Latency.StandardDeviation = math.Sqrt(ps.Latency.averageSquare - ps.Latency.Average*ps.Latency.Average)
} }
// Fail function update the raftPeerStats with a unsuccessful send // Fail function update the raftPeerStats with a unsuccessful send
func (ps *raftPeerStats) Fail() { func (ps *raftPeerStats) Fail() {
ps.FailCnt++ ps.Counts.Fail++
} }
type statsQueue struct { type statsQueue struct {

19
scripts/test-cluster Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
SESSION=etcd-cluster
tmux new-session -d -s $SESSION
# Setup a window for tailing log files
tmux new-window -t $SESSION:1 -n 'machines'
tmux split-window -h
tmux select-pane -t 0
tmux send-keys "./etcd -s 127.0.0.1:7001 -c 127.0.0.1:4001 -d machine1 -n machine1" C-m
for i in 2 3; do
tmux select-pane -t 0
tmux split-window -v
tmux send-keys "./etcd -cors='*' -s 127.0.0.1:700${i} -c 127.0.0.1:400${i} -C 127.0.0.1:7001 -d machine${i} -n machine${i}" C-m
done
# Attach to session
tmux attach-session -t $SESSION