Compare commits

...

2 commits

Author SHA1 Message Date
Neil Alexander 685fecb033
Register the collector 2022-10-04 13:37:32 +01:00
Neil Alexander 7c4e01e5c4
Database metrics 2022-10-04 13:31:51 +01:00
9 changed files with 14 additions and 0 deletions

View file

@ -6,6 +6,8 @@ import (
"regexp" "regexp"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -47,5 +49,7 @@ func Open(dbProperties *config.DatabaseOptions, writer Writer) (*sql.DB, error)
db.SetMaxIdleConns(dbProperties.MaxIdleConns()) db.SetMaxIdleConns(dbProperties.MaxIdleConns())
db.SetConnMaxLifetime(dbProperties.ConnMaxLifetime()) db.SetConnMaxLifetime(dbProperties.ConnMaxLifetime())
} }
collector := collectors.NewDBStatsCollector(db, fmt.Sprintf("dendrite_%s", dbProperties.Name))
prometheus.MustRegister(collector)
return db, nil return db, nil
} }

View file

@ -40,6 +40,7 @@ func (c *FederationAPI) Defaults(opts DefaultOpts) {
c.InternalAPI.Listen = "http://localhost:7772" c.InternalAPI.Listen = "http://localhost:7772"
c.InternalAPI.Connect = "http://localhost:7772" c.InternalAPI.Connect = "http://localhost:7772"
c.ExternalAPI.Listen = "http://[::]:8072" c.ExternalAPI.Listen = "http://[::]:8072"
c.Database.Name = "federation_api"
c.Database.Defaults(10) c.Database.Defaults(10)
} }
c.FederationMaxRetries = 16 c.FederationMaxRetries = 16

View file

@ -96,6 +96,7 @@ func (c *Global) Defaults(opts DefaultOpts) {
} }
c.KeyValidityPeriod = time.Hour * 24 * 7 c.KeyValidityPeriod = time.Hour * 24 * 7
if opts.Monolithic { if opts.Monolithic {
c.DatabaseOptions.Name = "global"
c.DatabaseOptions.Defaults(90) c.DatabaseOptions.Defaults(90)
} }
c.JetStream.Defaults(opts) c.JetStream.Defaults(opts)
@ -237,6 +238,8 @@ func (c *Sentry) Verify(configErrs *ConfigErrors, isMonolith bool) {
} }
type DatabaseOptions struct { type DatabaseOptions struct {
// Which database is this? For use in prometheus collectors.
Name string `json:"-"`
// The connection string, file:filename.db or postgres://server.... // The connection string, file:filename.db or postgres://server....
ConnectionString DataSource `yaml:"connection_string"` ConnectionString DataSource `yaml:"connection_string"`
// Maximum open connections to the DB (0 = use default, negative means unlimited) // Maximum open connections to the DB (0 = use default, negative means unlimited)

View file

@ -12,6 +12,7 @@ func (c *KeyServer) Defaults(opts DefaultOpts) {
if !opts.Monolithic { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7779" c.InternalAPI.Listen = "http://localhost:7779"
c.InternalAPI.Connect = "http://localhost:7779" c.InternalAPI.Connect = "http://localhost:7779"
c.Database.Name = "keyserver"
c.Database.Defaults(10) c.Database.Defaults(10)
} }
if opts.Generate { if opts.Generate {

View file

@ -43,6 +43,7 @@ func (c *MediaAPI) Defaults(opts DefaultOpts) {
c.InternalAPI.Listen = "http://localhost:7774" c.InternalAPI.Listen = "http://localhost:7774"
c.InternalAPI.Connect = "http://localhost:7774" c.InternalAPI.Connect = "http://localhost:7774"
c.ExternalAPI.Listen = "http://[::]:8074" c.ExternalAPI.Listen = "http://[::]:8074"
c.Database.Name = "media_api"
c.Database.Defaults(5) c.Database.Defaults(5)
} }
c.MaxFileSizeBytes = DefaultMaxFileSizeBytes c.MaxFileSizeBytes = DefaultMaxFileSizeBytes

View file

@ -15,6 +15,7 @@ type MSCs struct {
func (c *MSCs) Defaults(opts DefaultOpts) { func (c *MSCs) Defaults(opts DefaultOpts) {
if !opts.Monolithic { if !opts.Monolithic {
c.Database.Name = "mscs"
c.Database.Defaults(5) c.Database.Defaults(5)
} }
if opts.Generate { if opts.Generate {

View file

@ -12,6 +12,7 @@ func (c *RoomServer) Defaults(opts DefaultOpts) {
if !opts.Monolithic { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7770" c.InternalAPI.Listen = "http://localhost:7770"
c.InternalAPI.Connect = "http://localhost:7770" c.InternalAPI.Connect = "http://localhost:7770"
c.Database.Name = "roomserver"
c.Database.Defaults(20) c.Database.Defaults(20)
} }
if opts.Generate { if opts.Generate {

View file

@ -18,6 +18,7 @@ func (c *SyncAPI) Defaults(opts DefaultOpts) {
c.InternalAPI.Listen = "http://localhost:7773" c.InternalAPI.Listen = "http://localhost:7773"
c.InternalAPI.Connect = "http://localhost:7773" c.InternalAPI.Connect = "http://localhost:7773"
c.ExternalAPI.Listen = "http://localhost:8073" c.ExternalAPI.Listen = "http://localhost:8073"
c.Database.Name = "sync_api"
c.Database.Defaults(20) c.Database.Defaults(20)
} }
c.Fulltext.Defaults(opts) c.Fulltext.Defaults(opts)

View file

@ -27,6 +27,7 @@ func (c *UserAPI) Defaults(opts DefaultOpts) {
if !opts.Monolithic { if !opts.Monolithic {
c.InternalAPI.Listen = "http://localhost:7781" c.InternalAPI.Listen = "http://localhost:7781"
c.InternalAPI.Connect = "http://localhost:7781" c.InternalAPI.Connect = "http://localhost:7781"
c.AccountDatabase.Name = "user_api"
c.AccountDatabase.Defaults(10) c.AccountDatabase.Defaults(10)
} }
c.BCryptCost = bcrypt.DefaultCost c.BCryptCost = bcrypt.DefaultCost