Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
ch <- e.error
e.scrapeErrors.Collect(ch)
for _, db := range e.databases {
ch <- db.DBTypeMetric(e.constLabels())
ch <- db.UpMetric(e.constLabels())
}
}
Expand Down
38 changes: 4 additions & 34 deletions collector/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ func (d *Database) UpMetric(exporterLabels map[string]string) prometheus.Metric
)
}

func (d *Database) DBTypeMetric(exporterLabels map[string]string) prometheus.Metric {
desc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "dbtype"),
"Type of database the exporter is connected to (0=non-CDB, 1=CDB, >1=PDB).",
nil,
d.constLabels(exporterLabels),
)
return prometheus.MustNewConstMetric(desc,
prometheus.GaugeValue,
d.Type,
)
}

// ping the database. If the database is disconnected, try to reconnect.
// If the database type is unknown, try to reload it.
func (d *Database) ping(logger *slog.Logger) error {
Expand All @@ -61,16 +48,10 @@ func (d *Database) ping(logger *slog.Logger) error {
}
// If database is closed, try to reconnect
if strings.Contains(err.Error(), "sql: database is closed") {
db, dbtype := connect(logger, d.Name, d.Config)
d.Session = db
d.Type = dbtype
d.Session = connect(logger, d.Name, d.Config)
}
return err
}
// if connected but database type is unknown, try to reload it
if d.Type == -1 {
d.Type = getDBtype(ctx, d.Session, logger, d.Name)
}
d.Up = 1
return nil
}
Expand All @@ -86,12 +67,11 @@ func (d *Database) constLabels(labels map[string]string) map[string]string {
}

func NewDatabase(logger *slog.Logger, dbname string, dbconfig DatabaseConfig) *Database {
db, dbtype := connect(logger, dbname, dbconfig)
db := connect(logger, dbname, dbconfig)
return &Database{
Name: dbname,
Up: 0,
Session: db,
Type: dbtype,
Config: dbconfig,
Valid: true,
}
Expand Down Expand Up @@ -158,7 +138,7 @@ func isInvalidCredentialsError(err error) bool {
return oraErr.Code() == ora01017code || oraErr.Code() == ora28000code
}

func connect(logger *slog.Logger, dbname string, dbconfig DatabaseConfig) (*sql.DB, float64) {
func connect(logger *slog.Logger, dbname string, dbconfig DatabaseConfig) *sql.DB {
logger.Debug("Launching connection to "+maskDsn(dbconfig.URL), "database", dbname)

var P godror.ConnectionParams
Expand Down Expand Up @@ -241,15 +221,5 @@ func connect(logger *slog.Logger, dbname string, dbconfig DatabaseConfig) (*sql.
}
logger.Info("Connected as SYSDBA? "+sysdba, "database", dbname)

dbtype := getDBtype(ctx, db, logger, dbname)
return db, dbtype
}

func getDBtype(ctx context.Context, db *sql.DB, logger *slog.Logger, dbname string) float64 {
var dbtype int
if err := db.QueryRowContext(ctx, "select sys_context('USERENV', 'CON_ID') from dual").Scan(&dbtype); err != nil {
logger.Info("dbtype err", "error", err, "database", dbname)
return -1
}
return float64(dbtype)
return db
}
8 changes: 8 additions & 0 deletions collector/default_metrics.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[[metric]]
context = ""
metricsdesc = { dbtype="Type of database the exporter is connected to (0=non-CDB, 1=CDB, >1=PDB)." }
request = '''
select sys_context('USERENV', 'CON_ID') as dbtype
from dual
'''

[[metric]]
context = "sessions"
labels = [ "inst_id", "status", "type" ]
Expand Down
1 change: 0 additions & 1 deletion collector/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Database struct {
Name string
Up float64
Session *sql.DB
Type float64
Config DatabaseConfig
// MetricsCache holds computed metrics for a database, so these metrics are available on each scrape.
// Given a metric's scrape configuration, it may not be computed on the same interval as other metrics.
Expand Down
8 changes: 8 additions & 0 deletions default-metrics.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[[metric]]
context = ""
metricsdesc = { dbtype="Type of database the exporter is connected to (0=non-CDB, 1=CDB, >1=PDB)." }
request = '''
select sys_context('USERENV', 'CON_ID') as dbtype
from dual
'''

[[metric]]
context = "sessions"
labels = [ "inst_id", "status", "type" ]
Expand Down
7 changes: 7 additions & 0 deletions default-metrics.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
metrics:
- context: ""
metricsdesc:
dbtype: "Type of database the exporter is connected to (0=non-CDB, 1=CDB, >1=PDB)."
request: |
select sys_context('USERENV', 'CON_ID') as dbtype
from dual

- context: "sessions"
labels: [ "inst_id", "status", "type" ]
metricsdesc:
Expand Down
5 changes: 5 additions & 0 deletions site/docs/releases/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ List of upcoming and historic changes to the exporter.

Our current priorities to support metrics for advanced database features and use cases, like Exadata, GoldenGate, and views included in the Oracle Diagnostics Pack.

- Move `oracledb_dbtype` metric to the default metrics. You may now disable or override this metric like any other database metric.

Thank you to the following people for their suggestions and contributions:
- [@MansuyDavid](https://github.com/MansuyDavid)

### Version 2.1.0, September 29, 2025

- Updated project dependencies.
Expand Down