|
1 | | -// Copyright (c) 2021, 2024, Oracle and/or its affiliates. |
| 1 | +// Copyright (c) 2021, 2025, Oracle and/or its affiliates. |
2 | 2 | // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
3 | 3 | // Portions Copyright (c) 2016 Seth Miller <seth@sethmiller.me> |
4 | 4 |
|
@@ -27,75 +27,6 @@ import ( |
27 | 27 | "github.com/prometheus/client_golang/prometheus" |
28 | 28 | ) |
29 | 29 |
|
30 | | -// Exporter collects Oracle DB metrics. It implements prometheus.Collector. |
31 | | -type Exporter struct { |
32 | | - config *Config |
33 | | - mu *sync.Mutex |
34 | | - metricsToScrape Metrics |
35 | | - scrapeInterval *time.Duration |
36 | | - user string |
37 | | - password string |
38 | | - connectString string |
39 | | - configDir string |
40 | | - externalAuth bool |
41 | | - duration, error prometheus.Gauge |
42 | | - totalScrapes prometheus.Counter |
43 | | - scrapeErrors *prometheus.CounterVec |
44 | | - scrapeResults []prometheus.Metric |
45 | | - up prometheus.Gauge |
46 | | - dbtype int |
47 | | - dbtypeGauge prometheus.Gauge |
48 | | - db *sql.DB |
49 | | - logger log.Logger |
50 | | - lastTick *time.Time |
51 | | -} |
52 | | - |
53 | | -// Config is the configuration of the exporter |
54 | | -type Config struct { |
55 | | - User string |
56 | | - Password string |
57 | | - ConnectString string |
58 | | - DbRole dsn.AdminRole |
59 | | - ConfigDir string |
60 | | - ExternalAuth bool |
61 | | - MaxIdleConns int |
62 | | - MaxOpenConns int |
63 | | - CustomMetrics string |
64 | | - QueryTimeout int |
65 | | - DefaultMetricsFile string |
66 | | -} |
67 | | - |
68 | | -// CreateDefaultConfig returns the default configuration of the Exporter |
69 | | -// it is to be of note that the DNS will be empty when |
70 | | -func CreateDefaultConfig() *Config { |
71 | | - return &Config{ |
72 | | - MaxIdleConns: 0, |
73 | | - MaxOpenConns: 10, |
74 | | - CustomMetrics: "", |
75 | | - QueryTimeout: 5, |
76 | | - DefaultMetricsFile: "", |
77 | | - } |
78 | | -} |
79 | | - |
80 | | -// Metric is an object description |
81 | | -type Metric struct { |
82 | | - Context string |
83 | | - Labels []string |
84 | | - MetricsDesc map[string]string |
85 | | - MetricsType map[string]string |
86 | | - MetricsBuckets map[string]map[string]string |
87 | | - FieldToAppend string |
88 | | - Request string |
89 | | - IgnoreZeroResult bool |
90 | | - QueryTimeout string |
91 | | - ScrapeInterval string |
92 | | -} |
93 | | - |
94 | | -// Metrics is a container structure for prometheus metrics |
95 | | -type Metrics struct { |
96 | | - Metric []Metric |
97 | | -} |
98 | | - |
99 | 30 | var ( |
100 | 31 | additionalMetrics Metrics |
101 | 32 | hashMap = make(map[int][]byte) |
@@ -416,6 +347,21 @@ func (e *Exporter) connect() error { |
416 | 347 | } |
417 | 348 | P.Username, P.Password, P.ConnectString, P.ExternalAuth = e.user, godror.NewPassword(e.password), e.connectString, externalAuth |
418 | 349 |
|
| 350 | + if e.config.PoolIncrement > 0 { |
| 351 | + level.Debug(e.logger).Log("msg", "set pool increment to ", e.config.PoolIncrement) |
| 352 | + P.PoolParams.SessionIncrement = e.config.PoolIncrement |
| 353 | + } |
| 354 | + if e.config.PoolMaxConnections > 0 { |
| 355 | + level.Debug(e.logger).Log("msg", "set pool max connections to ", e.config.PoolMaxConnections) |
| 356 | + P.PoolParams.MaxSessions = e.config.PoolMaxConnections |
| 357 | + } |
| 358 | + if e.config.PoolMinConnections > 0 { |
| 359 | + level.Debug(e.logger).Log("msg", "set pool min connections to ", e.config.PoolMinConnections) |
| 360 | + P.PoolParams.MinSessions = e.config.PoolMinConnections |
| 361 | + } |
| 362 | + |
| 363 | + P.PoolParams.WaitTimeout = time.Second * 5 |
| 364 | + |
419 | 365 | // if TNS_ADMIN env var is set, set ConfigDir to that location |
420 | 366 | P.ConfigDir = e.configDir |
421 | 367 |
|
@@ -443,9 +389,9 @@ func (e *Exporter) connect() error { |
443 | 389 | // note that this just configures the connection, it does not actually connect until later |
444 | 390 | // when we call db.Ping() |
445 | 391 | db := sql.OpenDB(godror.NewConnector(P)) |
446 | | - level.Debug(e.logger).Log("set max idle connections to ", e.config.MaxIdleConns) |
| 392 | + level.Debug(e.logger).Log("msg", "set max idle connections to ", e.config.MaxIdleConns) |
447 | 393 | db.SetMaxIdleConns(e.config.MaxIdleConns) |
448 | | - level.Debug(e.logger).Log("set max open connections to ", e.config.MaxOpenConns) |
| 394 | + level.Debug(e.logger).Log("msg", "set max open connections to ", e.config.MaxOpenConns) |
449 | 395 | db.SetMaxOpenConns(e.config.MaxOpenConns) |
450 | 396 | db.SetConnMaxLifetime(0) |
451 | 397 | level.Debug(e.logger).Log("msg", "Successfully configured connection to "+maskDsn(e.connectString)) |
|
0 commit comments