diff options
author | Cecylia Bocovich <cohosh@torproject.org> | 2021-03-31 17:22:31 -0400 |
---|---|---|
committer | Cecylia Bocovich <cohosh@torproject.org> | 2021-04-26 14:18:50 -0400 |
commit | 2a310682b51b3da514d7e1927aafcdae9b9c8820 (patch) | |
tree | 7f877cf0dc75af64d2f49b735bf4e4cc568afac5 | |
parent | 92bd900bc57f1d56c21c5abf736deb6ce3a83837 (diff) | |
download | snowflake-2a310682b51b3da514d7e1927aafcdae9b9c8820.tar.gz snowflake-2a310682b51b3da514d7e1927aafcdae9b9c8820.zip |
Add new gauge to show currently available proxies
-rw-r--r-- | broker/broker.go | 3 | ||||
-rw-r--r-- | broker/metrics.go | 16 |
2 files changed, 16 insertions, 3 deletions
diff --git a/broker/broker.go b/broker/broker.go index b29ebd4..77c62d8 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -151,6 +151,7 @@ func (ctx *BrokerContext) Broker() { } else { heap.Remove(ctx.restrictedSnowflakes, snowflake.index) } + promMetrics.AvailableProxies.With(prometheus.Labels{"nat": request.natType, "type": request.proxyType}).Dec() delete(ctx.idToSnowflake, snowflake.id) close(request.offerChannel) } @@ -176,6 +177,7 @@ func (ctx *BrokerContext) AddSnowflake(id string, proxyType string, natType stri } else { heap.Push(ctx.restrictedSnowflakes, snowflake) } + promMetrics.AvailableProxies.With(prometheus.Labels{"nat": natType, "type": proxyType}).Inc() ctx.snowflakeLock.Unlock() ctx.idToSnowflake[id] = snowflake return snowflake @@ -319,6 +321,7 @@ func clientOffers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) { } ctx.snowflakeLock.Lock() + promMetrics.AvailableProxies.With(prometheus.Labels{"nat": snowflake.natType, "type": snowflake.proxyType}).Dec() delete(ctx.idToSnowflake, snowflake.id) ctx.snowflakeLock.Unlock() } diff --git a/broker/metrics.go b/broker/metrics.go index 24ff9b0..be8cfd9 100644 --- a/broker/metrics.go +++ b/broker/metrics.go @@ -261,9 +261,10 @@ func binCount(count uint) uint { } type PromMetrics struct { - ProxyTotal *prometheus.CounterVec - ProxyPollTotal *RoundedCounterVec - ClientPollTotal *RoundedCounterVec + ProxyTotal *prometheus.CounterVec + ProxyPollTotal *RoundedCounterVec + ClientPollTotal *RoundedCounterVec + AvailableProxies *prometheus.GaugeVec } //Initialize metrics for prometheus exporter @@ -280,6 +281,15 @@ func initPrometheus() *PromMetrics { []string{"type", "nat", "cc"}, ) + promMetrics.AvailableProxies = promauto.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: prometheusNamespace, + Name: "available_proxies", + Help: "The number of currently available snowflake proxies", + }, + []string{"type", "nat"}, + ) + promMetrics.ProxyPollTotal = NewRoundedCounterVec( prometheus.CounterOpts{ Namespace: prometheusNamespace, |