stats.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Copyright 2013 CoreOS Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package store
  14. import (
  15. "encoding/json"
  16. )
  17. type EtcdStats struct {
  18. // Number of get requests
  19. Gets uint64 `json:"gets"`
  20. // Number of sets requests
  21. Sets uint64 `json:"sets"`
  22. // Number of delete requests
  23. Deletes uint64 `json:"deletes"`
  24. // Number of testAndSet requests
  25. TestAndSets uint64 `json:"testAndSets"`
  26. }
  27. // Stats returns the basic statistics information of etcd storage since its recent start
  28. func (s *Store) Stats() []byte {
  29. b, _ := json.Marshal(s.BasicStats)
  30. return b
  31. }
  32. // TotalWrites returns the total write operations
  33. // It helps with snapshot
  34. func (s *Store) TotalWrites() uint64 {
  35. bs := s.BasicStats
  36. return bs.Deletes + bs.Sets + bs.TestAndSets
  37. }