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