@@ -2,10 +2,13 @@ package keypermetrics
2
2
3
3
import (
4
4
"context"
5
+ "strconv"
5
6
7
+ "github.com/jackc/pgx/v4/pgxpool"
6
8
"github.com/prometheus/client_golang/prometheus"
7
9
"github.com/rs/zerolog/log"
8
10
11
+ "github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/database"
9
12
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/kprconfig"
10
13
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync"
11
14
)
@@ -85,7 +88,17 @@ var MetricsKeyperBatchConfigInfo = prometheus.NewGaugeVec(
85
88
},
86
89
[]string {"batch_config_index" , "keyper_addresses" })
87
90
88
- func InitMetrics (config kprconfig.Config ) {
91
+ var MetricsKeyperDKGstatus = prometheus .NewGaugeVec (
92
+ prometheus.GaugeOpts {
93
+ Namespace : "shutter" ,
94
+ Subsystem : "keyper" ,
95
+ Name : "dkg_status" ,
96
+ Help : "Is DKG successful" ,
97
+ },
98
+ []string {"eon" },
99
+ )
100
+
101
+ func InitMetrics (dbpool * pgxpool.Pool , config kprconfig.Config ) {
89
102
prometheus .MustRegister (MetricsKeyperCurrentBlockL1 )
90
103
prometheus .MustRegister (MetricsKeyperCurrentBlockShuttermint )
91
104
prometheus .MustRegister (MetricsKeyperCurrentEon )
@@ -94,6 +107,36 @@ func InitMetrics(config kprconfig.Config) {
94
107
prometheus .MustRegister (MetricsKeyperCurrentPhase )
95
108
prometheus .MustRegister (MetricsKeyperCurrentBatchConfigIndex )
96
109
prometheus .MustRegister (MetricsKeyperBatchConfigInfo )
110
+ prometheus .MustRegister (MetricsKeyperDKGstatus )
111
+
112
+ queries := database .New (dbpool )
113
+ eons , err := queries .GetAllEons (context .Background ())
114
+ if err != nil {
115
+ log .Error ().Err (err ).Msg ("keypermetrics | Failed to get all eons" )
116
+ return
117
+ }
118
+ keyperIndex , isKeyper , err := queries .GetKeyperIndex (context .Background (), eons [len (eons )- 1 ].KeyperConfigIndex , config .GetAddress ())
119
+ if err != nil {
120
+ log .Error ().Err (err ).Msg ("keypermetrics | Failed to get keyper index" )
121
+ return
122
+ }
123
+ if isKeyper {
124
+ MetricsKeyperIsKeyper .WithLabelValues (strconv .FormatInt (keyperIndex , 10 )).Set (1 )
125
+ } else {
126
+ MetricsKeyperIsKeyper .WithLabelValues (strconv .FormatInt (keyperIndex , 10 )).Set (0 )
127
+ }
128
+
129
+ dkgResult , err := queries .GetDKGResultForKeyperConfigIndex (context .Background (), eons [len (eons )- 1 ].KeyperConfigIndex )
130
+ if err != nil {
131
+ MetricsKeyperDKGstatus .WithLabelValues (strconv .FormatInt (eons [len (eons )- 1 ].Eon , 10 )).Set (0 )
132
+ log .Error ().Err (err ).Msg ("keypermetrics | Failed to get dkg result" )
133
+ return
134
+ }
135
+ if dkgResult .Success {
136
+ MetricsKeyperDKGstatus .WithLabelValues (strconv .FormatInt (eons [len (eons )- 1 ].Eon , 10 )).Set (1 )
137
+ } else {
138
+ MetricsKeyperDKGstatus .WithLabelValues (strconv .FormatInt (eons [len (eons )- 1 ].Eon , 10 )).Set (0 )
139
+ }
97
140
98
141
version , err := chainsync .GetClientVersion (context .Background (), config .Ethereum .EthereumURL )
99
142
if err != nil {
@@ -112,6 +155,8 @@ func InitMetrics(config kprconfig.Config) {
112
155
},
113
156
},
114
157
)
158
+ executionClientVersion .Set (1 )
159
+
115
160
prometheus .MustRegister (executionClientVersion )
116
161
metricsKeyperEthAddress := prometheus .NewGauge (
117
162
prometheus.GaugeOpts {
0 commit comments