github.com/kaituanwang/hyperledger@v2.0.1+incompatible/core/ledger/util/couchdb/metrics.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  SPDX-License-Identifier: Apache-2.0
     4  */
     5  
     6  package couchdb
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/hyperledger/fabric/common/metrics"
    12  )
    13  
    14  var (
    15  	apiProcessingTimeOpts = metrics.HistogramOpts{
    16  		Namespace:    "couchdb",
    17  		Subsystem:    "",
    18  		Name:         "processing_time",
    19  		Help:         "Time taken in seconds for the function to complete request to CouchDB",
    20  		LabelNames:   []string{"database", "function_name", "result"},
    21  		StatsdFormat: "%{#fqname}.%{database}.%{function_name}.%{result}",
    22  	}
    23  )
    24  
    25  type stats struct {
    26  	apiProcessingTime metrics.Histogram
    27  }
    28  
    29  func newStats(metricsProvider metrics.Provider) *stats {
    30  	return &stats{
    31  		apiProcessingTime: metricsProvider.NewHistogram(apiProcessingTimeOpts),
    32  	}
    33  }
    34  
    35  func (s *stats) observeProcessingTime(startTime time.Time, dbName, functionName, result string) {
    36  	s.apiProcessingTime.With(
    37  		"database", dbName,
    38  		"function_name", functionName,
    39  		"result", result,
    40  	).Observe(time.Since(startTime).Seconds())
    41  }