123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- /*
- Copyright 2013 CoreOS Inc.
- 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.
- */
- package store
- import (
- "encoding/json"
- "sync/atomic"
- )
- const (
- SetSuccess = iota
- SetFail
- DeleteSuccess
- DeleteFail
- CreateSuccess
- CreateFail
- UpdateSuccess
- UpdateFail
- CompareAndSwapSuccess
- CompareAndSwapFail
- GetSuccess
- GetFail
- ExpireCount
- CompareAndDeleteSuccess
- CompareAndDeleteFail
- )
- type Stats struct {
- // Number of get requests
- GetSuccess uint64 `json:"getsSuccess"`
- GetFail uint64 `json:"getsFail"`
- // Number of sets requests
- SetSuccess uint64 `json:"setsSuccess"`
- SetFail uint64 `json:"setsFail"`
- // Number of delete requests
- DeleteSuccess uint64 `json:"deleteSuccess"`
- DeleteFail uint64 `json:"deleteFail"`
- // Number of update requests
- UpdateSuccess uint64 `json:"updateSuccess"`
- UpdateFail uint64 `json:"updateFail"`
- // Number of create requests
- CreateSuccess uint64 `json:"createSuccess"`
- CreateFail uint64 `json:"createFail"`
- // Number of testAndSet requests
- CompareAndSwapSuccess uint64 `json:"compareAndSwapSuccess"`
- CompareAndSwapFail uint64 `json:"compareAndSwapFail"`
- // Number of compareAndDelete requests
- CompareAndDeleteSuccess uint64 `json:"compareAndDeleteSuccess"`
- CompareAndDeleteFail uint64 `json:"compareAndDeleteFail"`
- ExpireCount uint64 `json:"expireCount"`
- Watchers uint64 `json:"watchers"`
- }
- func newStats() *Stats {
- s := new(Stats)
- return s
- }
- func (s *Stats) clone() *Stats {
- return &Stats{s.GetSuccess, s.GetFail, s.SetSuccess, s.SetFail,
- s.DeleteSuccess, s.DeleteFail, s.UpdateSuccess, s.UpdateFail, s.CreateSuccess,
- s.CreateFail, s.CompareAndSwapSuccess, s.CompareAndSwapFail,
- s.CompareAndDeleteSuccess, s.CompareAndDeleteFail, s.Watchers, s.ExpireCount}
- }
- // Status() return the statistics info of etcd storage its recent start
- func (s *Stats) toJson() []byte {
- b, _ := json.Marshal(s)
- return b
- }
- func (s *Stats) TotalReads() uint64 {
- return s.GetSuccess + s.GetFail
- }
- func (s *Stats) TotalTranscations() uint64 {
- return s.SetSuccess + s.SetFail +
- s.DeleteSuccess + s.DeleteFail +
- s.CompareAndSwapSuccess + s.CompareAndSwapFail +
- s.CompareAndDeleteSuccess + s.CompareAndDeleteFail +
- s.UpdateSuccess + s.UpdateFail
- }
- func (s *Stats) Inc(field int) {
- switch field {
- case SetSuccess:
- atomic.AddUint64(&s.SetSuccess, 1)
- case SetFail:
- atomic.AddUint64(&s.SetFail, 1)
- case CreateSuccess:
- atomic.AddUint64(&s.CreateSuccess, 1)
- case CreateFail:
- atomic.AddUint64(&s.CreateFail, 1)
- 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)
- case CompareAndDeleteSuccess:
- atomic.AddUint64(&s.CompareAndDeleteSuccess, 1)
- case CompareAndDeleteFail:
- atomic.AddUint64(&s.CompareAndDeleteFail, 1)
- case ExpireCount:
- atomic.AddUint64(&s.ExpireCount, 1)
- }
- }
|