Skip to content

Commit

Permalink
server/metrics: remove redundant metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
huachaohuang committed Nov 22, 2016
1 parent e3b0759 commit e3328b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 48 deletions.
27 changes: 3 additions & 24 deletions server/balancer_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (bw *balancerWorker) addBalanceOperator(regionID uint64, op *balanceOperato

// TODO: should we check allowBalance again here?

collectBalancerCounterMetrics(op)
collectOperatorCounterMetrics(op)

bw.balanceOperators[regionID] = op
bw.historyOperators.add(regionID, op)
Expand Down Expand Up @@ -203,8 +203,6 @@ func (bw *balancerWorker) allowBalance() bool {
}

func (bw *balancerWorker) doBalance() error {
collectBalancerGaugeMetrics(bw.getBalanceOperators())

balanceCount := uint64(0)
for i := uint64(0); i < bw.cfg.MaxBalanceRetryPerLoop; i++ {
if balanceCount >= bw.cfg.MaxBalanceCountPerLoop {
Expand Down Expand Up @@ -256,7 +254,7 @@ func (bw *balancerWorker) checkReplicas(region *regionInfo) error {
return nil
}

func collectOperatorMetrics(bop *balanceOperator) map[string]uint64 {
func collectOperatorCounterMetrics(bop *balanceOperator) {
metrics := make(map[string]uint64)
prefix := ""
switch bop.Type {
Expand All @@ -278,27 +276,8 @@ func collectOperatorMetrics(bop *balanceOperator) map[string]uint64 {
metrics[prefix+o.Name]++
}
}
return metrics
}

func collectBalancerCounterMetrics(bop *balanceOperator) {
metrics := collectOperatorMetrics(bop)
for label, value := range metrics {
balancerCounter.WithLabelValues(label).Add(float64(value))
}
}

func collectBalancerGaugeMetrics(ops map[uint64]Operator) {
metrics := make(map[string]uint64)
for _, op := range ops {
if bop, ok := op.(*balanceOperator); ok {
values := collectOperatorMetrics(bop)
for label, value := range values {
metrics[label] += value
}
}
}
for label, value := range metrics {
balancerGauge.WithLabelValues(label).Set(float64(value))
operatorCounter.WithLabelValues(label).Add(float64(value))
}
}
29 changes: 5 additions & 24 deletions server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,14 @@ var (
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
}, []string{"result"})

balancerCounter = prometheus.NewCounterVec(
operatorCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "pd",
Subsystem: "balancer",
Name: "balancers_count",
Help: "Counter of balancers.",
Subsystem: "schedule",
Name: "operators_count",
Help: "Counter of schedule operators.",
}, []string{"type"})

balancerGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Subsystem: "balancer",
Name: "number_of_operators",
Help: "Current number of operators in the balancer.",
}, []string{"type"})

randRegionDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "pd",
Subsystem: "cache",
Name: "random_region_seconds",
Help: "Bucketed histogram of processing time (s) of random regions.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
}, []string{"role"})

clusterStatusGauge = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "pd",
Expand All @@ -118,8 +101,6 @@ func init() {
prometheus.MustRegister(cmdCompletedDuration)
prometheus.MustRegister(txnCounter)
prometheus.MustRegister(txnDuration)
prometheus.MustRegister(balancerCounter)
prometheus.MustRegister(balancerGauge)
prometheus.MustRegister(randRegionDuration)
prometheus.MustRegister(operatorCounter)
prometheus.MustRegister(clusterStatusGauge)
}

0 comments on commit e3328b6

Please sign in to comment.