Skip to content

Commit 89a4603

Browse files
add serve monitoring
1 parent 3be426d commit 89a4603

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

cmd/contract-event-processor/main.go

+25
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010

1111
"github.com/DIMO-Network/shared"
1212
"github.com/Shopify/sarama"
13+
"github.com/gofiber/adaptor/v2"
14+
"github.com/gofiber/fiber/v2"
15+
"github.com/prometheus/client_golang/prometheus/promhttp"
1316
"github.com/rs/zerolog"
1417
)
1518

@@ -39,6 +42,8 @@ func main() {
3942
}
4043
}
4144

45+
monApp := serveMonitoring(settings.MonitoringPort, &logger)
46+
4247
kafkaClient, err := services.StartKafkaStream(settings)
4348
if err != nil {
4449
log.Fatal(err)
@@ -57,4 +62,24 @@ func main() {
5762

5863
listener.CompileRegistryMap("config.yaml")
5964
listener.ChainIndexer(blockNum)
65+
66+
monApp.Shutdown()
67+
}
68+
69+
func serveMonitoring(port string, logger *zerolog.Logger) *fiber.App {
70+
monApp := fiber.New(fiber.Config{DisableStartupMessage: true})
71+
72+
// Health check.
73+
monApp.Get("/", func(c *fiber.Ctx) error { return nil })
74+
monApp.Get("/metrics", adaptor.HTTPHandler(promhttp.Handler()))
75+
76+
go func() {
77+
if err := monApp.Listen(":" + port); err != nil {
78+
logger.Fatal().Err(err).Str("port", port).Msg("Failed to start monitoring web server.")
79+
}
80+
}()
81+
82+
logger.Info().Str("port", port).Msg("Started monitoring web server.")
83+
84+
return monApp
6085
}

internal/block_listener.go

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type Settings struct {
4848
PostgresDB string `yaml:"POSTGRES_DB"`
4949
PostgresHOST string `yaml:"POSTGRES_HOST"`
5050
PostgresPort int `yaml:"POSTGRES_PORT"`
51+
52+
MonitoringPort string `yaml:"MONITORING_PORT"`
5153
}
5254

5355
type BlockListener struct {

sample.settings.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
WEB_SOCKET_ADDRESS: wss://polygon-mainnet.g.alchemy.com/v2/
22
API_KEY:
3-
EVENT_STREAM_TOPIC: topic.event.stream
3+
EVENT_STREAM_TOPIC: topic.contract.event
44
PARTITIONS: 1
55
KAFKA_BROKER: localhost:9092
66
POSTGRES_USER: postgres
@@ -9,3 +9,4 @@ POSTGRES_DB: postgres
99
POSTGRES_HOST: localhost
1010
POSTGRES_PORT: 5432
1111
BLOCK_CONFIRMATIONS: 5
12+
MONITORING_PORT: 8888

sqlboiler.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[psql]
2-
schema = "chain_indexer"
2+
schema = "contract_event_processor"
33
dbname = "postgres"
44
blacklist = ["migrations"]
55
host = "localhost"

0 commit comments

Comments
 (0)