mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Unified Storage: Adds sql metrics (#87651)
* registers sql metrics for unified storage and removes single quotes from postgres connection string format * uses db logger * only register US sql metrics when connecting to another postgres or mysql db * use engine
This commit is contained in:
parent
e34e9f4b12
commit
77686da969
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dlmiddlecote/sqlstats"
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@ -14,6 +15,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@ -69,7 +71,7 @@ func (db *EntityDB) GetEngine() (*xorm.Engine, error) {
|
||||
}
|
||||
|
||||
connectionString := fmt.Sprintf(
|
||||
"user='%s' password='%s' host='%s' port='%s' dbname='%s' sslmode='%s'", // sslcert='%s' sslkey='%s' sslrootcert='%s'",
|
||||
"user=%s password=%s host=%s port=%s dbname=%s sslmode=%s", // sslcert='%s' sslkey='%s' sslrootcert='%s'",
|
||||
dbUser, dbPass, addr.Host, addr.Port, dbName, dbSslMode, // ss.dbCfg.ClientCertPath, ss.dbCfg.ClientKeyPath, ss.dbCfg.CaCertPath
|
||||
)
|
||||
|
||||
@ -112,6 +114,11 @@ func (db *EntityDB) GetEngine() (*xorm.Engine, error) {
|
||||
return nil, fmt.Errorf("invalid db type specified: %s", dbType)
|
||||
}
|
||||
|
||||
// register sql stat metrics
|
||||
if err := prometheus.Register(sqlstats.NewStatsCollector("unified_storage", engine.DB().DB)); err != nil {
|
||||
db.log.Warn("Failed to register unified storage sql stats collector", "error", err)
|
||||
}
|
||||
|
||||
// configure sql logging
|
||||
debugSQL := cfgSection.Key("log_queries").MustBool(false)
|
||||
if !debugSQL {
|
||||
|
Loading…
Reference in New Issue
Block a user