@@ -5,6 +5,10 @@ import (
55 "fmt"
66 "time"
77
8+ "github.com/keep-network/keep-core/pkg/chain"
9+ "github.com/keep-network/keep-core/pkg/metrics"
10+ "github.com/keep-network/keep-core/pkg/net"
11+
812 "github.com/ipfs/go-log"
913
1014 "github.com/keep-network/keep-common/pkg/chain/ethereum/ethutil"
@@ -158,10 +162,13 @@ func Start(c *cli.Context) error {
158162 networkProvider ,
159163 persistence ,
160164 sanctionedApplications ,
165+ & config .Client ,
161166 & config .TSS ,
162167 )
163168 logger .Debugf ("initialized operator with address: [%s]" , ethereumKey .Address .String ())
164169
170+ initializeMetrics (ctx , config , networkProvider , stakeMonitor , ethereumKey .Address .Hex ())
171+
165172 logger .Info ("client started" )
166173
167174 select {
@@ -173,3 +180,52 @@ func Start(c *cli.Context) error {
173180 return fmt .Errorf ("unexpected context cancellation" )
174181 }
175182}
183+
184+ func initializeMetrics (
185+ ctx context.Context ,
186+ config * config.Config ,
187+ netProvider net.Provider ,
188+ stakeMonitor chain.StakeMonitor ,
189+ ethereumAddres string ,
190+ ) {
191+ registry , isConfigured := metrics .Initialize (
192+ config .Metrics .Port ,
193+ )
194+ if ! isConfigured {
195+ logger .Infof ("metrics are not configured" )
196+ return
197+ }
198+
199+ logger .Infof (
200+ "enabled metrics on port [%v]" ,
201+ config .Metrics .Port ,
202+ )
203+
204+ metrics .ObserveConnectedPeersCount (
205+ ctx ,
206+ registry ,
207+ netProvider ,
208+ time .Duration (config .Metrics .NetworkMetricsTick )* time .Second ,
209+ )
210+
211+ metrics .ObserveConnectedBootstrapCount (
212+ ctx ,
213+ registry ,
214+ netProvider ,
215+ config .LibP2P .Peers ,
216+ time .Duration (config .Metrics .NetworkMetricsTick )* time .Second ,
217+ )
218+
219+ metrics .ObserveEthConnectivity (
220+ ctx ,
221+ registry ,
222+ stakeMonitor ,
223+ ethereumAddres ,
224+ time .Duration (config .Metrics .EthereumMetricsTick )* time .Second ,
225+ )
226+
227+ metrics .ExposeLibP2PInfo (
228+ registry ,
229+ netProvider ,
230+ )
231+ }
0 commit comments