etcd/etcdserver/v2store/stats.go

146 lines
3.7 KiB
Go
Raw Normal View History

2016-05-13 06:51:48 +03:00
// Copyright 2015 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2013-10-07 20:44:51 +04:00
package v2store
2013-09-29 03:26:19 +04:00
import (
"encoding/json"
"sync/atomic"
)
const (
2013-10-16 10:18:03 +04:00
SetSuccess = iota
SetFail
DeleteSuccess
DeleteFail
CreateSuccess
CreateFail
UpdateSuccess
UpdateFail
CompareAndSwapSuccess
CompareAndSwapFail
GetSuccess
GetFail
ExpireCount
2013-11-30 21:05:48 +04:00
CompareAndDeleteSuccess
CompareAndDeleteFail
2013-09-29 03:26:19 +04:00
)
type Stats struct {
// Number of get requests
2016-02-21 16:05:03 +03:00
2013-09-29 03:26:19 +04:00
GetSuccess uint64 `json:"getsSuccess"`
GetFail uint64 `json:"getsFail"`
// Number of sets requests
2016-02-21 16:05:03 +03:00
2013-09-29 03:26:19 +04:00
SetSuccess uint64 `json:"setsSuccess"`
SetFail uint64 `json:"setsFail"`
// Number of delete requests
2016-02-21 16:05:03 +03:00
2013-09-29 03:26:19 +04:00
DeleteSuccess uint64 `json:"deleteSuccess"`
DeleteFail uint64 `json:"deleteFail"`
// Number of update requests
2016-02-21 16:05:03 +03:00
2013-09-29 03:26:19 +04:00
UpdateSuccess uint64 `json:"updateSuccess"`
UpdateFail uint64 `json:"updateFail"`
2013-10-16 10:18:03 +04:00
// Number of create requests
2016-02-21 16:05:03 +03:00
2013-10-16 10:18:03 +04:00
CreateSuccess uint64 `json:"createSuccess"`
2013-10-21 23:37:22 +04:00
CreateFail uint64 `json:"createFail"`
2013-10-16 10:18:03 +04:00
2013-09-29 03:26:19 +04:00
// Number of testAndSet requests
2016-02-21 16:05:03 +03:00
CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"`
CompareAndSwapFail uint64 `json:"compareAndSwapFail"`
2013-11-30 21:05:48 +04:00
// Number of compareAndDelete requests
2016-02-21 16:05:03 +03:00
2013-11-30 21:05:48 +04:00
CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"`
CompareAndDeleteFail uint64 `json:"compareAndDeleteFail"`
ExpireCount uint64 `json:"expireCount"`
2013-09-29 03:26:19 +04:00
Watchers uint64 `json:"watchers"`
}
func newStats() *Stats {
s := new(Stats)
return s
}
2013-09-29 03:58:57 +04:00
func (s *Stats) clone() *Stats {
return &Stats{
GetSuccess: s.GetSuccess,
GetFail: s.GetFail,
SetSuccess: s.SetSuccess,
SetFail: s.SetFail,
DeleteSuccess: s.DeleteSuccess,
DeleteFail: s.DeleteFail,
UpdateSuccess: s.UpdateSuccess,
UpdateFail: s.UpdateFail,
CreateSuccess: s.CreateSuccess,
CreateFail: s.CreateFail,
CompareAndSwapSuccess: s.CompareAndSwapSuccess,
CompareAndSwapFail: s.CompareAndSwapFail,
CompareAndDeleteSuccess: s.CompareAndDeleteSuccess,
CompareAndDeleteFail: s.CompareAndDeleteFail,
ExpireCount: s.ExpireCount,
Watchers: s.Watchers,
}
2013-09-29 03:58:57 +04:00
}
2013-09-29 03:26:19 +04:00
func (s *Stats) toJson() []byte {
b, _ := json.Marshal(s)
return b
}
func (s *Stats) Inc(field int) {
switch field {
case SetSuccess:
atomic.AddUint64(&s.SetSuccess, 1)
case SetFail:
atomic.AddUint64(&s.SetFail, 1)
2013-10-16 10:18:03 +04:00
case CreateSuccess:
atomic.AddUint64(&s.CreateSuccess, 1)
case CreateFail:
atomic.AddUint64(&s.CreateFail, 1)
2013-09-29 03:26:19 +04:00
case DeleteSuccess:
atomic.AddUint64(&s.DeleteSuccess, 1)
case DeleteFail:
atomic.AddUint64(&s.DeleteFail, 1)
case GetSuccess:
atomic.AddUint64(&s.GetSuccess, 1)
case GetFail:
atomic.AddUint64(&s.GetFail, 1)
case UpdateSuccess:
atomic.AddUint64(&s.UpdateSuccess, 1)
case UpdateFail:
atomic.AddUint64(&s.UpdateFail, 1)
case CompareAndSwapSuccess:
atomic.AddUint64(&s.CompareAndSwapSuccess, 1)
case CompareAndSwapFail:
atomic.AddUint64(&s.CompareAndSwapFail, 1)
2013-11-30 21:05:48 +04:00
case CompareAndDeleteSuccess:
atomic.AddUint64(&s.CompareAndDeleteSuccess, 1)
case CompareAndDeleteFail:
atomic.AddUint64(&s.CompareAndDeleteFail, 1)
2013-09-30 10:39:40 +04:00
case ExpireCount:
atomic.AddUint64(&s.ExpireCount, 1)
2013-09-29 03:26:19 +04:00
}
}