github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/stats/doc.go (about) 1 // Copyright 2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package stats 16 17 /* DefaultRegistry holds all the Mo DevStats. 18 Currently, the stats Family class only contains LogExporter. 19 20 Usage: 21 22 1. Identify the Stats class to be exported. Ensure that, the Stats class uses `stats.Counter` instead of `atomic.Int64` 23 24 type Counter struct { 25 S3 struct { 26 List stats.Counter 27 Head stats.Counter 28 Put stats.Counter 29 Get stats.Counter 30 Delete stats.Counter 31 DeleteMulti stats.Counter 32 } 33 } 34 35 2. Create a new LogExporter class for the identified Stats class. This will be an adapter to export the Stats values in a loggable format. 36 37 type CounterLogExporter struct { 38 counter *Counter 39 } 40 41 func NewCounterLogExporter(counter *Counter) stats.LogExporter { 42 return &CounterLogExporter{ 43 counter: counter, 44 } 45 } 46 47 func (c *CounterLogExporter) Export() []zap.Field { 48 var fields []zap.Field 49 50 reads := c.counter.Cache.Read.Swap() //NOTE: Swap() 51 fields = append(fields, zap.Any("reads", reads)) 52 return fields 53 } 54 55 3. Initialize the LogExporter class where Stats class is initialized. 56 57 counterLogExporter := NewCounterLogExporter(&counter.perfCounter) 58 59 4. Register LogExporter to global stats registry using stats.Register() 60 61 stats.Register("FamilyName", stats.WithLogExporter(counterLogExporter)) 62 */