Skip to content

Commit 8327fde

Browse files
Add INST_ID as a metrics label (#329)
Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
1 parent 43f6bb3 commit 8327fde

File tree

5 files changed

+85
-43
lines changed

5 files changed

+85
-43
lines changed

collector/default_metrics.toml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,73 @@
11
[[metric]]
22
context = "sessions"
3-
labels = [ "status", "type" ]
4-
metricsdesc = { value= "Gauge metric with count of sessions by status and type." }
3+
labels = [ "inst_id", "status", "type" ]
4+
metricsdesc = { value= "Gauge metric with count of sessions by inst_id, status and type." }
55
request = '''
6-
select status, type, count(*) as value
6+
select inst_id, status, type, count(*) as value
77
from gv$session
8-
group by status, type
8+
group by inst_id, status, type
99
'''
1010

1111
[[metric]]
1212
context = "resource"
13-
labels = [ "resource_name" ]
13+
labels = [ "inst_id", "resource_name" ]
1414
metricsdesc = { current_utilization= "Generic counter metric from gv$resource_limit view in Oracle (current value).", limit_value="Generic counter metric from v$resource_limit view in Oracle (UNLIMITED: -1)." }
1515
request = '''
16-
select resource_name, current_utilization, case when trim(limit_value) like 'UNLIMITED' then '-1' else trim(limit_value) end as limit_value
16+
select inst_id, resource_name, current_utilization, case when trim(limit_value) like 'UNLIMITED' then '-1' else trim(limit_value) end as limit_value
1717
from gv$resource_limit
18+
group by inst_id, resource_name, current_utilization, limit_value
1819
'''
1920
ignorezeroresult = true
2021

2122
[[metric]]
2223
context = "asm_diskgroup"
23-
labels = [ "name" ]
24+
labels = [ "inst_id", "name" ]
2425
metricsdesc = { total = "Total size of ASM disk group.", free = "Free space available on ASM disk group." }
2526
request = '''
26-
select name, total_mb*1024*1024 as total, free_mb*1024*1024 as free
27+
select inst_id, name, total_mb*1024*1024 as total, free_mb*1024*1024 as free
2728
from gv$asm_diskgroup_stat
2829
where exists (select 1 from gv$datafile where name like '+%')
2930
and inst_id = (select max(inst_id) from gv$instance)
30-
group by name, total_mb, free_mb
31+
group by inst_id, name, total_mb, free_mb
3132
'''
3233
ignorezeroresult = true
3334

3435
[[metric]]
3536
context = "activity"
37+
labels = [ "inst_id" ]
3638
metricsdesc = { value="Generic counter metric from gv$sysstat view in Oracle." }
3739
fieldtoappend = "name"
3840
request = '''
39-
select name, value from gv$sysstat
41+
select inst_id, name, value from gv$sysstat
4042
where name in ('parse count (total)', 'execute count', 'user commits', 'user rollbacks')
43+
group by inst_id, name, value
4144
'''
4245

4346
[[metric]]
4447
context = "process"
48+
labels = [ "inst_id" ]
4549
metricsdesc = { count="Gauge metric with count of processes." }
46-
request = "select count(*) as count from gv$process"
50+
request = '''
51+
select inst_id, count(*) as count
52+
from gv$process
53+
group by inst_id
54+
'''
4755

4856
[[metric]]
4957
context = "wait_time"
50-
labels = ["wait_class","con_id"]
58+
labels = [ "inst_id", "wait_class", "con_id" ]
5159
metricsdesc = { time_waited_sec_total="counter metric from system_wait_class view in Oracle." }
5260
metricstype = { time_waited_sec_total = "counter" }
5361
fieldtoappend= "wait_class"
5462
request = '''
5563
select
64+
inst_id,
5665
wait_class,
5766
round(time_waited/100,3) time_waited_sec_total,
5867
con_id
5968
from gv$system_wait_class
6069
where wait_class <> 'Idle'
70+
group by inst_id, wait_class, con_id, time_waited_sec_total
6171
'''
6272
ignorezeroresult = true
6373

@@ -90,29 +100,32 @@ order by tablespace
90100

91101
[[metric]]
92102
context = "db_system"
93-
labels = [ "name" ]
103+
labels = [ "inst_id", "name" ]
94104
metricsdesc = { value = "Database system resources metric" }
95105
request = '''
96-
select name, value
106+
select inst_id, name, value
97107
from gv$parameter
98108
where name in ('cpu_count', 'sga_max_size', 'pga_aggregate_limit')
109+
group by inst_id, name, value
99110
'''
100111

101112
[[metric]]
102113
context = "db_platform"
103-
labels = [ "platform_name" ]
114+
labels = [ "inst_id", "platform_name" ]
104115
metricsdesc = { value = "Database platform" }
105116
request = '''
106-
SELECT platform_name, 1 as value FROM gv$database
117+
SELECT platform_name, 1 as value
118+
FROM gv$database
119+
GROUP BY inst_id, platform_name
107120
'''
108121

109122
[[metric]]
110123
context = "top_sql"
111-
labels = [ "sql_id", "sql_text" ]
124+
labels = [ "inst_id", "sql_id", "sql_text" ]
112125
metricsdesc = { elapsed = "SQL statement elapsed time running" }
113126
request = '''
114127
select * from (
115-
select sql_id, elapsed_time / 1000000 as elapsed, substrb(replace(sql_text,'',' '),1,55) as sql_text
128+
select inst_id, sql_id, elapsed_time / 1000000 as elapsed, substrb(replace(sql_text,'',' '),1,55) as sql_text
116129
from gv$sqlstats
117130
order by elapsed_time desc
118131
) where rownum <= 15
@@ -126,7 +139,7 @@ ignorezeroresult = true
126139

127140
[[metric]]
128141
context = "cache_hit_ratio"
129-
labels = [ "cache_hit_type" ]
142+
labels = [ "inst_id", "cache_hit_type" ]
130143
metricsdesc = { value = "Cache Hit Ratio" }
131144
request = '''
132145
select metric_name cache_hit_type, value

custom-metrics-example/custom-metrics.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
[[metric]]
22
context = "slow_queries"
3+
labels = [ "inst_id" ]
34
metricsdesc = { p95_time_usecs= "Gauge metric with percentile 95 of elapsed time.", p99_time_usecs= "Gauge metric with percentile 99 of elapsed time." }
45
request = '''
5-
select percentile_disc(0.95) within group (order by elapsed_time) as p95_time_usecs, percentile_disc(0.99) within group (order by elapsed_time) as p99_time_usecs
6+
select inst_id, percentile_disc(0.95) within group (order by elapsed_time) as p95_time_usecs, percentile_disc(0.99) within group (order by elapsed_time) as p99_time_usecs
67
from gv$sql
78
where last_active_time >= sysdate - 5/(24*60)
9+
group by inst_id
810
'''
911

1012
[[metric]]
1113
context = "big_queries"
14+
labels = [ "inst_id" ]
1215
metricsdesc = { p95_rows= "Gauge metric with percentile 95 of returned rows.", p99_rows= "Gauge metric with percentile 99 of returned rows." }
1316
request = '''
14-
select percentile_disc(0.95) within group (order by rownum) as p95_rows, percentile_disc(0.99) within group (order by rownum) as p99_rows
17+
select inst_id, percentile_disc(0.95) within group (order by rownum) as p95_rows, percentile_disc(0.99) within group (order by rownum) as p99_rows
1518
from gv$sql
1619
where last_active_time >= sysdate - 5/(24*60)
20+
group by inst_id
1721
'''
1822

1923
# User segment queries may return zero rows on certain database configurations

default-metrics.toml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,73 @@
11
[[metric]]
22
context = "sessions"
3-
labels = [ "status", "type" ]
4-
metricsdesc = { value= "Gauge metric with count of sessions by status and type." }
3+
labels = [ "inst_id", "status", "type" ]
4+
metricsdesc = { value= "Gauge metric with count of sessions by inst_id, status and type." }
55
request = '''
6-
select status, type, count(*) as value
6+
select inst_id, status, type, count(*) as value
77
from gv$session
8-
group by status, type
8+
group by inst_id, status, type
99
'''
1010

1111
[[metric]]
1212
context = "resource"
13-
labels = [ "resource_name" ]
14-
metricsdesc = { current_utilization= "Generic counter metric from v$resource_limit view in Oracle (current value).", limit_value="Generic counter metric from v$resource_limit view in Oracle (UNLIMITED: -1)." }
13+
labels = [ "inst_id", "resource_name" ]
14+
metricsdesc = { current_utilization= "Generic counter metric from gv$resource_limit view in Oracle (current value).", limit_value="Generic counter metric from v$resource_limit view in Oracle (UNLIMITED: -1)." }
1515
request = '''
16-
select resource_name, current_utilization, case when trim(limit_value) like 'UNLIMITED' then '-1' else trim(limit_value) end as limit_value
16+
select inst_id, resource_name, current_utilization, case when trim(limit_value) like 'UNLIMITED' then '-1' else trim(limit_value) end as limit_value
1717
from gv$resource_limit
18+
group by inst_id, resource_name, current_utilization, limit_value
1819
'''
1920
ignorezeroresult = true
2021

2122
[[metric]]
2223
context = "asm_diskgroup"
23-
labels = [ "name" ]
24+
labels = [ "inst_id", "name" ]
2425
metricsdesc = { total = "Total size of ASM disk group.", free = "Free space available on ASM disk group." }
2526
request = '''
26-
select name, total_mb*1024*1024 as total, free_mb*1024*1024 as free
27+
select inst_id, name, total_mb*1024*1024 as total, free_mb*1024*1024 as free
2728
from gv$asm_diskgroup_stat
2829
where exists (select 1 from gv$datafile where name like '+%')
2930
and inst_id = (select max(inst_id) from gv$instance)
30-
group by name, total_mb, free_mb
31+
group by inst_id, name, total_mb, free_mb
3132
'''
3233
ignorezeroresult = true
3334

3435
[[metric]]
3536
context = "activity"
37+
labels = [ "inst_id" ]
3638
metricsdesc = { value="Generic counter metric from gv$sysstat view in Oracle." }
3739
fieldtoappend = "name"
3840
request = '''
39-
select name, value from gv$sysstat
41+
select inst_id, name, value from gv$sysstat
4042
where name in ('parse count (total)', 'execute count', 'user commits', 'user rollbacks')
43+
group by inst_id, name, value
4144
'''
4245

4346
[[metric]]
4447
context = "process"
48+
labels = [ "inst_id" ]
4549
metricsdesc = { count="Gauge metric with count of processes." }
46-
request = "select count(*) as count from gv$process"
50+
request = '''
51+
select inst_id, count(*) as count
52+
from gv$process
53+
group by inst_id
54+
'''
4755

4856
[[metric]]
4957
context = "wait_time"
50-
labels = ["wait_class","con_id"]
58+
labels = [ "inst_id", "wait_class", "con_id" ]
5159
metricsdesc = { time_waited_sec_total="counter metric from system_wait_class view in Oracle." }
5260
metricstype = { time_waited_sec_total = "counter" }
5361
fieldtoappend= "wait_class"
5462
request = '''
5563
select
64+
inst_id,
5665
wait_class,
5766
round(time_waited/100,3) time_waited_sec_total,
5867
con_id
5968
from gv$system_wait_class
6069
where wait_class <> 'Idle'
70+
group by inst_id, wait_class, con_id, time_waited_sec_total
6171
'''
6272
ignorezeroresult = true
6373

@@ -90,29 +100,32 @@ order by tablespace
90100

91101
[[metric]]
92102
context = "db_system"
93-
labels = [ "name" ]
103+
labels = [ "inst_id", "name" ]
94104
metricsdesc = { value = "Database system resources metric" }
95105
request = '''
96-
select name, value
106+
select inst_id, name, value
97107
from gv$parameter
98108
where name in ('cpu_count', 'sga_max_size', 'pga_aggregate_limit')
109+
group by inst_id, name, value
99110
'''
100111

101112
[[metric]]
102113
context = "db_platform"
103-
labels = [ "platform_name" ]
114+
labels = [ "inst_id", "platform_name" ]
104115
metricsdesc = { value = "Database platform" }
105116
request = '''
106-
SELECT platform_name, 1 as value FROM gv$database
117+
SELECT platform_name, 1 as value
118+
FROM gv$database
119+
GROUP BY inst_id, platform_name
107120
'''
108121

109122
[[metric]]
110123
context = "top_sql"
111-
labels = [ "sql_id", "sql_text" ]
124+
labels = [ "inst_id", "sql_id", "sql_text" ]
112125
metricsdesc = { elapsed = "SQL statement elapsed time running" }
113126
request = '''
114127
select * from (
115-
select sql_id, elapsed_time / 1000000 as elapsed, substrb(replace(sql_text,'',' '),1,55) as sql_text
128+
select inst_id, sql_id, elapsed_time / 1000000 as elapsed, substrb(replace(sql_text,'',' '),1,55) as sql_text
116129
from gv$sqlstats
117130
order by elapsed_time desc
118131
) where rownum <= 15
@@ -126,7 +139,7 @@ ignorezeroresult = true
126139

127140
[[metric]]
128141
context = "cache_hit_ratio"
129-
labels = [ "cache_hit_type" ]
142+
labels = [ "inst_id", "cache_hit_type" ]
130143
metricsdesc = { value = "Cache Hit Ratio" }
131144
request = '''
132145
select metric_name cache_hit_type, value

site/docs/configuration/multiple-databases.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ databases:
118118
# label_name2: label_value2
119119
```
120120

121-
### Only scraping metrics from specific databases
121+
### Scraping specific metrics from specific databases
122122

123123
By default, metrics are scraped from every connected database. To expose only certain metrics on specific databases, configure the `databases` property of a metric. The following metric definition will only be scraped from databases "db2" and "db3":
124124

@@ -133,4 +133,12 @@ SELECT platform_name, 1 as value FROM gv$database
133133
databases = [ "db2", "db3" ]
134134
```
135135

136-
If the `databases` array is empty or not provided for a metric, that metric will be scraped from all connected databases.
136+
If the `databases` array is empty or not provided for a metric, that metric will be scraped from all connected databases.
137+
138+
### Duplicated database configurations
139+
140+
If one or more database configurations are "duplicated", that is, using the same URL and username, a WARN message is logged:
141+
142+
```
143+
msg="duplicated database connections" "database connections"="db1, db2 count=2
144+
```

site/docs/releases/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ List of upcoming and historic changes to the exporter.
1111

1212
Our current priorities are support for Exadata metrics. We expect to address these in an upcoming release.
1313

14+
- Added WARN logging when database configurations are duplicated in the exporter configuration.
15+
- Added INST_ID to `gv$` query metrics as a label.
16+
- Fixed multiple concurrency bugs when the exporter is connected to multiple databases and using a custom scrape interval.
17+
1418
### Version 2.0.3, August 27, 2025
1519

1620
This release includes the following changes:

0 commit comments

Comments
 (0)