github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/core/ledger/kvledger/txmgmt/statedb/statecouchdb/metrics.go (about) 1 /* 2 Copyright hechain. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package statecouchdb 8 9 import ( 10 "time" 11 12 "github.com/hechain20/hechain/common/metrics" 13 ) 14 15 var 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 type stats struct { 25 apiProcessingTime metrics.Histogram 26 } 27 28 func newStats(metricsProvider metrics.Provider) *stats { 29 return &stats{ 30 apiProcessingTime: metricsProvider.NewHistogram(apiProcessingTimeOpts), 31 } 32 } 33 34 func (s *stats) observeProcessingTime(startTime time.Time, dbName, functionName, result string) { 35 s.apiProcessingTime.With( 36 "database", dbName, 37 "function_name", functionName, 38 "result", result, 39 ).Observe(time.Since(startTime).Seconds()) 40 }