github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/flogging/metrics/observer.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package metrics 8 9 import ( 10 "github.com/hyperledger/fabric/common/metrics" 11 "go.uber.org/zap/zapcore" 12 ) 13 14 var ( 15 CheckedCountOpts = metrics.CounterOpts{ 16 Namespace: "logging", 17 Name: "entries_checked", 18 Help: "Number of log entries checked against the active logging level", 19 LabelNames: []string{"level"}, 20 StatsdFormat: "%{#fqname}.%{level}", 21 } 22 23 WriteCountOpts = metrics.CounterOpts{ 24 Namespace: "logging", 25 Name: "entries_written", 26 Help: "Number of log entries that are written", 27 LabelNames: []string{"level"}, 28 StatsdFormat: "%{#fqname}.%{level}", 29 } 30 ) 31 32 type Observer struct { 33 CheckedCounter metrics.Counter 34 WrittenCounter metrics.Counter 35 } 36 37 func NewObserver(provider metrics.Provider) *Observer { 38 return &Observer{ 39 CheckedCounter: provider.NewCounter(CheckedCountOpts), 40 WrittenCounter: provider.NewCounter(WriteCountOpts), 41 } 42 } 43 44 func (m *Observer) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) { 45 m.CheckedCounter.With("level", e.Level.String()).Add(1) 46 } 47 48 func (m *Observer) WriteEntry(e zapcore.Entry, fields []zapcore.Field) { 49 m.WrittenCounter.With("level", e.Level.String()).Add(1) 50 }