github.com/true-sqn/fabric@v2.1.1+incompatible/core/ledger/util/couchdb/metrics.go (about)

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