trpc.group/trpc-go/trpc-go@v1.0.3/metrics/counter.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package metrics 15 16 // ICounter is the interface that emits counter type metrics. 17 type ICounter interface { 18 // Incr increments the counter by one. 19 Incr() 20 21 // IncrBy increments the counter by delta. 22 IncrBy(delta float64) 23 } 24 25 // counter defines the counter. counter is report to each external Sink-able system. 26 type counter struct { 27 name string 28 } 29 30 // Incr increases counter by one. 31 func (c *counter) Incr() { 32 c.IncrBy(1) 33 } 34 35 // IncrBy increases counter by v and reports for each external Sink-able systems. 36 func (c *counter) IncrBy(v float64) { 37 if len(metricsSinks) == 0 { 38 return 39 } 40 rec := NewSingleDimensionMetrics(c.name, v, PolicySUM) 41 for _, sink := range metricsSinks { 42 sink.Report(rec) 43 } 44 }