@@ -2,6 +2,7 @@ package metrics
22
33import (
44 "fmt"
5+ "math/big"
56 "time"
67
78 "github.com/prometheus/client_golang/prometheus"
@@ -86,6 +87,11 @@ var rateLimitedTransactionsCounter = prometheus.NewCounter(prometheus.CounterOpt
8687 Help : "Total number of rate-limited transactions" ,
8788})
8889
90+ var flowTotalSupply = prometheus .NewGauge (prometheus.GaugeOpts {
91+ Name : prefixedName ("flow_total_supply" ),
92+ Help : "Total supply of FLOW tokens in EVM at a given time (in smallest unit, wei)" ,
93+ })
94+
8995var metrics = []prometheus.Collector {
9096 apiErrors ,
9197 serverPanicsCounters ,
@@ -102,6 +108,7 @@ var metrics = []prometheus.Collector{
102108 requestRateLimitedCounters ,
103109 transactionsDroppedCounter ,
104110 rateLimitedTransactionsCounter ,
111+ flowTotalSupply ,
105112}
106113
107114type Collector interface {
@@ -119,11 +126,14 @@ type Collector interface {
119126 RequestRateLimited (method string )
120127 TransactionsDropped (count int )
121128 TransactionRateLimited ()
129+ FlowTotalSupply (totalSupply * big.Int )
122130}
123131
124132var _ Collector = & DefaultCollector {}
125133
126134type DefaultCollector struct {
135+ logger zerolog.Logger
136+
127137 // TODO: for now we cannot differentiate which api request failed number of times
128138 apiErrorsCounter prometheus.Counter
129139 serverPanicsCounters * prometheus.CounterVec
@@ -140,6 +150,7 @@ type DefaultCollector struct {
140150 requestRateLimitedCounters * prometheus.CounterVec
141151 transactionsDroppedCounter prometheus.Counter
142152 rateLimitedTransactionsCounter prometheus.Counter
153+ flowTotalSupply prometheus.Gauge
143154}
144155
145156func NewCollector (logger zerolog.Logger ) Collector {
@@ -149,6 +160,7 @@ func NewCollector(logger zerolog.Logger) Collector {
149160 }
150161
151162 return & DefaultCollector {
163+ logger : logger ,
152164 apiErrorsCounter : apiErrors ,
153165 serverPanicsCounters : serverPanicsCounters ,
154166 cadenceBlockHeight : cadenceBlockHeight ,
@@ -164,6 +176,7 @@ func NewCollector(logger zerolog.Logger) Collector {
164176 requestRateLimitedCounters : requestRateLimitedCounters ,
165177 transactionsDroppedCounter : transactionsDroppedCounter ,
166178 rateLimitedTransactionsCounter : rateLimitedTransactionsCounter ,
179+ flowTotalSupply : flowTotalSupply ,
167180 }
168181}
169182
@@ -246,6 +259,19 @@ func (c *DefaultCollector) TransactionRateLimited() {
246259 c .rateLimitedTransactionsCounter .Inc ()
247260}
248261
262+ func (c * DefaultCollector ) FlowTotalSupply (totalSupply * big.Int ) {
263+ if totalSupply == nil {
264+ return
265+ }
266+
267+ floatTotalSupply , accuracy := totalSupply .Float64 ()
268+ if accuracy != big .Exact {
269+ c .logger .Warn ().Msg ("precision loss when casting total supply to float" )
270+ }
271+
272+ c .flowTotalSupply .Set (floatTotalSupply )
273+ }
274+
249275func prefixedName (name string ) string {
250276 return fmt .Sprintf ("evm_gateway_%s" , name )
251277}
0 commit comments