probing_status.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 The etcd Authors
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package rafthttp
  15. import (
  16. "time"
  17. "github.com/xiang90/probing"
  18. )
  19. var (
  20. // proberInterval must be shorter than read timeout.
  21. // Or the connection will time-out.
  22. proberInterval = ConnReadTimeout - time.Second
  23. statusMonitoringInterval = 30 * time.Second
  24. )
  25. func addPeerToProber(p probing.Prober, id string, us []string) {
  26. hus := make([]string, len(us))
  27. for i := range us {
  28. hus[i] = us[i] + ProbingPrefix
  29. }
  30. p.AddHTTP(id, proberInterval, hus)
  31. s, err := p.Status(id)
  32. if err != nil {
  33. plog.Errorf("failed to add peer %s into prober", id)
  34. } else {
  35. go monitorProbingStatus(s, id)
  36. }
  37. }
  38. func monitorProbingStatus(s probing.Status, id string) {
  39. for {
  40. select {
  41. case <-time.After(statusMonitoringInterval):
  42. if !s.Health() {
  43. plog.Warningf("health check for peer %s failed", id)
  44. }
  45. if s.ClockDiff() > time.Second {
  46. plog.Warningf("the clock difference against peer %s is too high [%v > %v]", id, s.ClockDiff(), time.Second)
  47. }
  48. rtts.WithLabelValues(id).Observe(s.SRTT().Seconds())
  49. case <-s.StopNotify():
  50. return
  51. }
  52. }
  53. }