github.com/true-sqn/fabric@v2.1.1+incompatible/core/operations/metrics.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package operations 8 9 import ( 10 "sync" 11 12 "github.com/hyperledger/fabric/common/metrics" 13 "github.com/hyperledger/fabric/common/metrics/prometheus" 14 ) 15 16 var ( 17 fabricVersion = metrics.GaugeOpts{ 18 Name: "fabric_version", 19 Help: "The active version of Fabric.", 20 LabelNames: []string{"version"}, 21 StatsdFormat: "%{#fqname}.%{version}", 22 } 23 24 gaugeLock sync.Mutex 25 promVersionGauge metrics.Gauge 26 ) 27 28 func versionGauge(provider metrics.Provider) metrics.Gauge { 29 switch provider.(type) { 30 case *prometheus.Provider: 31 gaugeLock.Lock() 32 defer gaugeLock.Unlock() 33 if promVersionGauge == nil { 34 promVersionGauge = provider.NewGauge(fabricVersion) 35 } 36 return promVersionGauge 37 38 default: 39 return provider.NewGauge(fabricVersion) 40 } 41 }