Skip to content

Commit

Permalink
internalstorage: change the prefix of the db stats metrics
Browse files Browse the repository at this point in the history
Signed-off-by: scyda <[email protected]>
  • Loading branch information
scydas committed Dec 19, 2024
1 parent f730e26 commit f5c2492
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions pkg/storage/internalstorage/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewGormMetrics(config MetricsConfig) *Prometheus {
}

func (p *Prometheus) Name() string {
return "gorm:prometheus"
return "storage:prometheus"
}

func (p *Prometheus) Initialize(db *gorm.DB) error { // can be called repeatedly
Expand All @@ -78,7 +78,7 @@ func (p *Prometheus) Initialize(db *gorm.DB) error { // can be called repeatedly
func (p *Prometheus) refresh() {
db, err := p.DB.DB()
if err != nil {
p.DB.Logger.Error(context.Background(), "gorm:prometheus failed to collect db status, got error: %v", err)
p.DB.Logger.Error(context.Background(), "storage:prometheus failed to collect db status, got error: %v", err)
return
}
p.DBStats.set(db.Stats())
Expand All @@ -103,47 +103,56 @@ type DBStats struct {
func newStats(labels map[string]string) *DBStats {
stats := &DBStats{
MaxOpenConnections: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_max_open_connections",
Subsystem: "storage",
Name: "dbstats_max_open_connections",
Help: "Maximum number of open connections to the database.",
ConstLabels: labels,
}),
OpenConnections: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_open_connections",
Subsystem: "storage",
Name: "dbstats_open_connections",
Help: "The number of established connections both in use and idle.",
ConstLabels: labels,
}),
InUse: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_in_use",
Subsystem: "storage",
Name: "dbstats_in_use",
Help: "The number of connections currently in use.",
ConstLabels: labels,
}),
Idle: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_idle",
Subsystem: "storage",
Name: "dbstats_idle",
Help: "The number of idle connections.",
ConstLabels: labels,
}),
WaitCount: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_wait_count",
Subsystem: "storage",
Name: "dbstats_wait_count",
Help: "The total number of connections waited for.",
ConstLabels: labels,
}),
WaitDuration: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_wait_duration",
Subsystem: "storage",
Name: "dbstats_wait_duration",
Help: "The total time blocked waiting for a new connection.",
ConstLabels: labels,
}),
MaxIdleClosed: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_max_idle_closed",
Subsystem: "storage",
Name: "dbstats_max_idle_closed",
Help: "The total number of connections closed due to SetMaxIdleConns.",
ConstLabels: labels,
}),
MaxLifetimeClosed: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_max_lifetime_closed",
Subsystem: "storage",
Name: "dbstats_max_lifetime_closed",
Help: "The total number of connections closed due to SetConnMaxLifetime.",
ConstLabels: labels,
}),
MaxIdleTimeClosed: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gorm_dbstats_max_idletime_closed",
Subsystem: "storage",
Name: "dbstats_max_idletime_closed",
Help: "The total number of connections closed due to SetConnMaxIdleTime.",
ConstLabels: labels,
}),
Expand Down

0 comments on commit f5c2492

Please sign in to comment.