grpcproxy: add richer metrics for watch

This commit is contained in:
Xiang Li 2016-12-02 10:39:52 -08:00
parent 0326d6fdd3
commit a686c994cd
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Copyright 2016 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.
package grpcproxy
import "github.com/prometheus/client_golang/prometheus"
var (
watchersCoalescing = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "etcd",
Subsystem: "grpc_proxy",
Name: "watchers_coalescing_total",
Help: "Total number of current watchers coalescing",
})
eventsCoalescing = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "grpc_proxy",
Name: "events_coalescing_total",
Help: "Total number of events coalescing",
})
)
func init() {
prometheus.MustRegister(watchersCoalescing)
prometheus.MustRegister(eventsCoalescing)
}

View File

@ -89,6 +89,9 @@ func (wb *watchBroadcast) bcast(wr clientv3.WatchResponse) {
for r := range wb.receivers {
r.send(wr)
}
if wb.size() > 0 {
eventsCoalescing.Add(float64(wb.size() - 1))
}
}
// add puts a watcher into receiving a broadcast if its revision at least
@ -121,6 +124,8 @@ func (wb *watchBroadcast) add(w *watcher) bool {
return false
}
wb.receivers[w] = struct{}{}
watchersCoalescing.Inc()
return true
}
func (wb *watchBroadcast) delete(w *watcher) {
@ -130,6 +135,10 @@ func (wb *watchBroadcast) delete(w *watcher) {
panic("deleting missing watcher from broadcast")
}
delete(wb.receivers, w)
if !wb.empty() {
// do not dec the only left watcher for coalescing.
watchersCoalescing.Dec()
}
}
func (wb *watchBroadcast) size() int {
@ -141,6 +150,11 @@ func (wb *watchBroadcast) size() int {
func (wb *watchBroadcast) empty() bool { return wb.size() == 0 }
func (wb *watchBroadcast) stop() {
if !wb.empty() {
// do not dec the only left watcher for coalescing.
watchersCoalescing.Sub(float64(wb.size() - 1))
}
wb.cancel()
<-wb.donec
}