From 7c4e01e5c4ab736de16639fbfb76ab8b945b4b01 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 4 Oct 2022 13:31:51 +0100 Subject: [PATCH] Database metrics --- internal/sqlutil/sqlutil.go | 2 ++ setup/config/config_federationapi.go | 1 + setup/config/config_global.go | 3 +++ setup/config/config_keyserver.go | 1 + setup/config/config_mediaapi.go | 1 + setup/config/config_mscs.go | 1 + setup/config/config_roomserver.go | 1 + setup/config/config_syncapi.go | 1 + setup/config/config_userapi.go | 1 + 9 files changed, 12 insertions(+) diff --git a/internal/sqlutil/sqlutil.go b/internal/sqlutil/sqlutil.go index 0cdae6d30..ade4d4270 100644 --- a/internal/sqlutil/sqlutil.go +++ b/internal/sqlutil/sqlutil.go @@ -6,6 +6,7 @@ import ( "regexp" "github.com/matrix-org/dendrite/setup/config" + "github.com/prometheus/client_golang/prometheus/collectors" "github.com/sirupsen/logrus" ) @@ -47,5 +48,6 @@ func Open(dbProperties *config.DatabaseOptions, writer Writer) (*sql.DB, error) db.SetMaxIdleConns(dbProperties.MaxIdleConns()) db.SetConnMaxLifetime(dbProperties.ConnMaxLifetime()) } + collectors.NewDBStatsCollector(db, fmt.Sprintf("dendrite_%s", dbProperties.Name)) return db, nil } diff --git a/setup/config/config_federationapi.go b/setup/config/config_federationapi.go index 0f853865f..d232bc792 100644 --- a/setup/config/config_federationapi.go +++ b/setup/config/config_federationapi.go @@ -40,6 +40,7 @@ func (c *FederationAPI) Defaults(opts DefaultOpts) { c.InternalAPI.Listen = "http://localhost:7772" c.InternalAPI.Connect = "http://localhost:7772" c.ExternalAPI.Listen = "http://[::]:8072" + c.Database.Name = "federation_api" c.Database.Defaults(10) } c.FederationMaxRetries = 16 diff --git a/setup/config/config_global.go b/setup/config/config_global.go index acc608dd7..cfdd1c008 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -96,6 +96,7 @@ func (c *Global) Defaults(opts DefaultOpts) { } c.KeyValidityPeriod = time.Hour * 24 * 7 if opts.Monolithic { + c.DatabaseOptions.Name = "global" c.DatabaseOptions.Defaults(90) } c.JetStream.Defaults(opts) @@ -237,6 +238,8 @@ func (c *Sentry) Verify(configErrs *ConfigErrors, isMonolith bool) { } type DatabaseOptions struct { + // Which database is this? For use in prometheus collectors. + Name string `json:"-"` // The connection string, file:filename.db or postgres://server.... ConnectionString DataSource `yaml:"connection_string"` // Maximum open connections to the DB (0 = use default, negative means unlimited) diff --git a/setup/config/config_keyserver.go b/setup/config/config_keyserver.go index dca9ca9f5..03535fee6 100644 --- a/setup/config/config_keyserver.go +++ b/setup/config/config_keyserver.go @@ -12,6 +12,7 @@ func (c *KeyServer) Defaults(opts DefaultOpts) { if !opts.Monolithic { c.InternalAPI.Listen = "http://localhost:7779" c.InternalAPI.Connect = "http://localhost:7779" + c.Database.Name = "keyserver" c.Database.Defaults(10) } if opts.Generate { diff --git a/setup/config/config_mediaapi.go b/setup/config/config_mediaapi.go index 53a8219eb..7660a7b51 100644 --- a/setup/config/config_mediaapi.go +++ b/setup/config/config_mediaapi.go @@ -43,6 +43,7 @@ func (c *MediaAPI) Defaults(opts DefaultOpts) { c.InternalAPI.Listen = "http://localhost:7774" c.InternalAPI.Connect = "http://localhost:7774" c.ExternalAPI.Listen = "http://[::]:8074" + c.Database.Name = "media_api" c.Database.Defaults(5) } c.MaxFileSizeBytes = DefaultMaxFileSizeBytes diff --git a/setup/config/config_mscs.go b/setup/config/config_mscs.go index 6d5ff39a5..a50bd30d1 100644 --- a/setup/config/config_mscs.go +++ b/setup/config/config_mscs.go @@ -15,6 +15,7 @@ type MSCs struct { func (c *MSCs) Defaults(opts DefaultOpts) { if !opts.Monolithic { + c.Database.Name = "mscs" c.Database.Defaults(5) } if opts.Generate { diff --git a/setup/config/config_roomserver.go b/setup/config/config_roomserver.go index 5e3b7f2ec..687371ba4 100644 --- a/setup/config/config_roomserver.go +++ b/setup/config/config_roomserver.go @@ -12,6 +12,7 @@ func (c *RoomServer) Defaults(opts DefaultOpts) { if !opts.Monolithic { c.InternalAPI.Listen = "http://localhost:7770" c.InternalAPI.Connect = "http://localhost:7770" + c.Database.Name = "roomserver" c.Database.Defaults(20) } if opts.Generate { diff --git a/setup/config/config_syncapi.go b/setup/config/config_syncapi.go index a87da3732..2cd0715c9 100644 --- a/setup/config/config_syncapi.go +++ b/setup/config/config_syncapi.go @@ -18,6 +18,7 @@ func (c *SyncAPI) Defaults(opts DefaultOpts) { c.InternalAPI.Listen = "http://localhost:7773" c.InternalAPI.Connect = "http://localhost:7773" c.ExternalAPI.Listen = "http://localhost:8073" + c.Database.Name = "sync_api" c.Database.Defaults(20) } c.Fulltext.Defaults(opts) diff --git a/setup/config/config_userapi.go b/setup/config/config_userapi.go index 97a6d738b..b25c902b1 100644 --- a/setup/config/config_userapi.go +++ b/setup/config/config_userapi.go @@ -27,6 +27,7 @@ func (c *UserAPI) Defaults(opts DefaultOpts) { if !opts.Monolithic { c.InternalAPI.Listen = "http://localhost:7781" c.InternalAPI.Connect = "http://localhost:7781" + c.AccountDatabase.Name = "user_api" c.AccountDatabase.Defaults(10) } c.BCryptCost = bcrypt.DefaultCost