@@ -27,6 +27,8 @@ import (
2727 "github.com/flashbots/mev-boost/server/types"
2828 "github.com/google/uuid"
2929 "github.com/gorilla/mux"
30+ "github.com/prometheus/client_golang/prometheus"
31+ "github.com/prometheus/client_golang/prometheus/promhttp"
3032 "github.com/sirupsen/logrus"
3133)
3234
3739 errInvalidPubkey = errors .New ("invalid pubkey" )
3840 errNoSuccessfulRelayResponse = errors .New ("no successful relay response" )
3941 errServerAlreadyRunning = errors .New ("server already running" )
42+ errNilPrometheusRegistry = errors .New ("nil prometheus registry" )
4043)
4144
4245var (
@@ -69,6 +72,8 @@ type BoostServiceOpts struct {
6972 RequestTimeoutGetPayload time.Duration
7073 RequestTimeoutRegVal time.Duration
7174 RequestMaxRetries int
75+ PrometheusListenAddr int
76+ PrometheusRegistry * prometheus.Registry
7277}
7378
7479// BoostService - the mev-boost service
@@ -93,6 +98,9 @@ type BoostService struct {
9398
9499 slotUID * slotUID
95100 slotUIDLock sync.Mutex
101+
102+ prometheusListenAddr int
103+ prometheusRegistry * prometheus.Registry
96104}
97105
98106// NewBoostService created a new BoostService
@@ -130,7 +138,9 @@ func NewBoostService(opts BoostServiceOpts) (*BoostService, error) {
130138 Timeout : opts .RequestTimeoutRegVal ,
131139 CheckRedirect : httpClientDisallowRedirects ,
132140 },
133- requestMaxRetries : opts .RequestMaxRetries ,
141+ requestMaxRetries : opts .RequestMaxRetries ,
142+ prometheusListenAddr : opts .PrometheusListenAddr ,
143+ prometheusRegistry : opts .PrometheusRegistry ,
134144 }, nil
135145}
136146
@@ -194,6 +204,22 @@ func (m *BoostService) StartHTTPServer() error {
194204 return err
195205}
196206
207+ // StartMetricsServer starts the HTTP server for exporting open-metrics
208+ func (m * BoostService ) StartMetricsServer () error {
209+ if m .prometheusRegistry == nil {
210+ return errNilPrometheusRegistry
211+ }
212+ serveMux := http .NewServeMux ()
213+ serveMux .Handle ("/metrics" , promhttp .HandlerFor (m .prometheusRegistry , promhttp.HandlerOpts {
214+ ErrorLog : m .log ,
215+ EnableOpenMetrics : true ,
216+ }))
217+ return http .ListenAndServe (
218+ fmt .Sprintf (":%d" , m .prometheusListenAddr ),
219+ serveMux ,
220+ )
221+ }
222+
197223func (m * BoostService ) startBidCacheCleanupTask () {
198224 for {
199225 time .Sleep (1 * time .Minute )
0 commit comments