Skip to content

Commit cda581b

Browse files
Use gv$ views over v$ views (#250)
Signed-off-by: Anders Swanson <anders.swanson@oracle.com>
1 parent 92b9e2d commit cda581b

File tree

6 files changed

+105
-56
lines changed

6 files changed

+105
-56
lines changed

‎README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ Currently, we plan to address the following key features:
6666
The following metrics are exposed by default:
6767

6868
```text
69-
# HELP oracledb_activity_execute_count Generic counter metric from v$sysstat view in Oracle.
69+
# HELP oracledb_activity_execute_count Generic counter metric from gv$sysstat view in Oracle.
7070
# TYPE oracledb_activity_execute_count gauge
7171
oracledb_activity_execute_count 64469
72-
# HELP oracledb_activity_parse_count_total Generic counter metric from v$sysstat view in Oracle.
72+
# HELP oracledb_activity_parse_count_total Generic counter metric from gv$sysstat view in Oracle.
7373
# TYPE oracledb_activity_parse_count_total gauge
7474
oracledb_activity_parse_count_total 25883
75-
# HELP oracledb_activity_user_commits Generic counter metric from v$sysstat view in Oracle.
75+
# HELP oracledb_activity_user_commits Generic counter metric from gv$sysstat view in Oracle.
7676
# TYPE oracledb_activity_user_commits gauge
7777
oracledb_activity_user_commits 158
78-
# HELP oracledb_activity_user_rollbacks Generic counter metric from v$sysstat view in Oracle.
78+
# HELP oracledb_activity_user_rollbacks Generic counter metric from gv$sysstat view in Oracle.
7979
# TYPE oracledb_activity_user_rollbacks gauge
8080
oracledb_activity_user_rollbacks 2
8181
# HELP oracledb_db_platform_value Database platform
@@ -104,7 +104,7 @@ oracledb_exporter_scrapes_total 3
104104
# HELP oracledb_process_count Gauge metric with count of processes.
105105
# TYPE oracledb_process_count gauge
106106
oracledb_process_count 79
107-
# HELP oracledb_resource_current_utilization Generic counter metric from v$resource_limit view in Oracle (current value).
107+
# HELP oracledb_resource_current_utilization Generic counter metric from gv$resource_limit view in Oracle (current value).
108108
# TYPE oracledb_resource_current_utilization gauge
109109
oracledb_resource_current_utilization{resource_name="branches"} 0
110110
oracledb_resource_current_utilization{resource_name="cmtcallbk"} 0
@@ -133,7 +133,7 @@ oracledb_resource_current_utilization{resource_name="smartio_sessions"} 0
133133
oracledb_resource_current_utilization{resource_name="sort_segment_locks"} 2
134134
oracledb_resource_current_utilization{resource_name="temporary_table_locks"} 0
135135
oracledb_resource_current_utilization{resource_name="transactions"} 0
136-
# HELP oracledb_resource_limit_value Generic counter metric from v$resource_limit view in Oracle (UNLIMITED: -1).
136+
# HELP oracledb_resource_limit_value Generic counter metric from gv$resource_limit view in Oracle (UNLIMITED: -1).
137137
# TYPE oracledb_resource_limit_value gauge
138138
oracledb_resource_limit_value{resource_name="branches"} -1
139139
oracledb_resource_limit_value{resource_name="cmtcallbk"} -1
@@ -262,18 +262,18 @@ For the built-in default metrics, the database user that the exporter uses to co
262262

263263
- dba_tablespace_usage_metrics
264264
- dba_tablespaces
265-
- v$system_wait_class
266-
- v$asm_diskgroup_stat
267-
- v$datafile
268-
- v$sysstat
269-
- v$process
270-
- v$waitclassmetric
271-
- v$session
272-
- v$resource_limit
273-
- v$parameter
274-
- v$database
275-
- v$sqlstats
276-
- v$sysmetric
265+
- gv$system_wait_class
266+
- gv$asm_diskgroup_stat
267+
- gv$datafile
268+
- gv$sysstat
269+
- gv$process
270+
- gv$waitclassmetric
271+
- gv$session
272+
- gv$resource_limit
273+
- gv$parameter
274+
- gv$database
275+
- gv$sqlstats
276+
- gv$sysmetric
277277
- v$diag_alert_ext (for alert logs only)
278278

279279
## Alert logs
@@ -794,7 +794,7 @@ context = "db_platform"
794794
labels = [ "platform_name" ]
795795
metricsdesc = { value = "Database platform" }
796796
request = '''
797-
SELECT platform_name, 1 as value FROM v$database
797+
SELECT platform_name, 1 as value FROM gv$database
798798
'''
799799
databases = [ "db2", "db3" ]
800800
```

‎collector/default_metrics.toml

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,48 @@
22
context = "sessions"
33
labels = [ "status", "type" ]
44
metricsdesc = { value= "Gauge metric with count of sessions by status and type." }
5-
request = "SELECT status, type, COUNT(*) as value FROM v$session GROUP BY status, type"
5+
request = '''
6+
select status, type, count(*) as value
7+
from gv$session
8+
group by status, type
9+
'''
610

711
[[metric]]
812
context = "resource"
913
labels = [ "resource_name" ]
10-
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)." }
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)." }
1115
request = '''
12-
SELECT resource_name, current_utilization, CASE WHEN TRIM(limit_value) LIKE 'UNLIMITED' THEN '-1' ELSE TRIM(limit_value) END as limit_value
13-
FROM v$resource_limit
16+
select resource_name, current_utilization, case when trim(limit_value) like 'unlimited' then '-1' else trim(limit_value) end as limit_value
17+
from gv$resource_limit
1418
'''
1519
ignorezeroresult = true
1620

1721
[[metric]]
1822
context = "asm_diskgroup"
1923
labels = [ "name" ]
2024
metricsdesc = { total = "Total size of ASM disk group.", free = "Free space available on ASM disk group." }
21-
request = "SELECT name,total_mb*1024*1024 as total,free_mb*1024*1024 as free FROM v$asm_diskgroup_stat where exists (select 1 from v$datafile where name like '+%')"
25+
request = '''
26+
select name, total_mb*1024*1024 as total, free_mb*1024*1024 as free
27+
from gv$asm_diskgroup_stat
28+
where exists (select 1 from gv$datafile where name like '+%')
29+
and inst_id = (select max(inst_id) from gv$instance)
30+
group by name, total_mb, free_mb
31+
'''
2232
ignorezeroresult = true
2333

2434
[[metric]]
2535
context = "activity"
26-
metricsdesc = { value="Generic counter metric from v$sysstat view in Oracle." }
36+
metricsdesc = { value="Generic counter metric from gv$sysstat view in Oracle." }
2737
fieldtoappend = "name"
28-
request = "SELECT name, value FROM v$sysstat WHERE name IN ('parse count (total)', 'execute count', 'user commits', 'user rollbacks')"
38+
request = '''
39+
select name, value from gv$sysstat
40+
where name in ('parse count (total)', 'execute count', 'user commits', 'user rollbacks')
41+
'''
2942

3043
[[metric]]
3144
context = "process"
3245
metricsdesc = { count="Gauge metric with count of processes." }
33-
request = "SELECT COUNT(*) as count FROM v$process"
46+
request = "select count(*) as count from gv$process"
3447

3548
[[metric]]
3649
context = "wait_time"
@@ -43,7 +56,7 @@ select
4356
wait_class,
4457
round(time_waited/100,3) time_waited_sec_total,
4558
con_id
46-
from v$system_wait_class
59+
from gv$system_wait_class
4760
where wait_class <> 'Idle'
4861
'''
4962
ignorezeroresult = true
@@ -62,7 +75,17 @@ SELECT
6275
dtum.used_percent
6376
FROM dba_tablespace_usage_metrics dtum, dba_tablespaces dt
6477
WHERE dtum.tablespace_name = dt.tablespace_name
65-
ORDER by tablespace
78+
and dt.contents != 'TEMPORARY'
79+
union
80+
SELECT
81+
dt.tablespace_name as tablespace,
82+
'TEMPORARY' as type,
83+
dt.tablespace_size - dt.free_space as bytes,
84+
dt.tablespace_size as max_bytes,
85+
dt.free_space as free,
86+
((dt.tablespace_size - dt.free_space) / dt.tablespace_size)
87+
FROM dba_temp_free_space dt
88+
order by tablespace
6689
'''
6790

6891
[[metric]]
@@ -71,7 +94,7 @@ labels = [ "name" ]
7194
metricsdesc = { value = "Database system resources metric" }
7295
request = '''
7396
select name, value
74-
from v$parameter
97+
from gv$parameter
7598
where name in ('cpu_count', 'sga_max_size', 'pga_aggregate_limit')
7699
'''
77100

@@ -80,7 +103,7 @@ context = "db_platform"
80103
labels = [ "platform_name" ]
81104
metricsdesc = { value = "Database platform" }
82105
request = '''
83-
SELECT platform_name, 1 as value FROM v$database
106+
SELECT platform_name, 1 as value FROM gv$database
84107
'''
85108

86109
[[metric]]
@@ -89,20 +112,25 @@ labels = [ "sql_id", "sql_text" ]
89112
metricsdesc = { elapsed = "SQL statement elapsed time running" }
90113
request = '''
91114
select * from (
92-
select sql_id, elapsed_time / 1000000 as elapsed, SUBSTRB(REPLACE(sql_text,'',' '),1,55) as sql_text
93-
from V$SQLSTATS
115+
select sql_id, elapsed_time / 1000000 as elapsed, substrb(replace(sql_text,'',' '),1,55) as sql_text
116+
from gv$sqlstats
94117
order by elapsed_time desc
95-
) where ROWNUM <= 15
118+
) where rownum <= 15
96119
'''
97120
ignorezeroresult = true
121+
# scrapeinterval = "5m"
122+
# The previous line is an example of changing the interval at which this one metric
123+
# will be scraped. You may wish to do this to scrape a metric less often, if the SQL
124+
# statement to collect that metric places more load on your database instance than
125+
# desired when it is run at every scrape.
98126

99127
[[metric]]
100128
context = "cache_hit_ratio"
101129
labels = [ "cache_hit_type" ]
102130
metricsdesc = { value = "Cache Hit Ratio" }
103131
request = '''
104132
select metric_name cache_hit_type, value
105-
from v$sysmetric
133+
from gv$sysmetric
106134
where group_id=2 and metric_id in (2000,2050,2112,2110)
107135
'''
108-
ignorezeroresult = true
136+
ignorezeroresult = true

‎custom-metrics-example/custom-metrics.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
[[metric]]
22
context = "slow_queries"
33
metricsdesc = { p95_time_usecs= "Gauge metric with percentile 95 of elapsed time.", p99_time_usecs= "Gauge metric with percentile 99 of elapsed time." }
4-
request = "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 from v$sql where last_active_time >= sysdate - 5/(24*60)"
4+
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+
from gv$sql
7+
where last_active_time >= sysdate - 5/(24*60)
8+
'''
59

610
[[metric]]
711
context = "big_queries"
812
metricsdesc = { p95_rows= "Gauge metric with percentile 95 of returned rows.", p99_rows= "Gauge metric with percentile 99 of returned rows." }
9-
request = "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 from v$sql where last_active_time >= sysdate - 5/(24*60)"
13+
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
15+
from gv$sql
16+
where last_active_time >= sysdate - 5/(24*60)
17+
'''
1018

1119
[[metric]]
1220
context = "size_user_segments_top100"

‎custom-metrics-example/txeventq-metrics.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WHERE
1313
[[metric]]
1414
context = "teq"
1515
metricsdesc = { curr_inst_id = "ID of current instance" }
16-
request = "SELECT instance_number AS curr_inst_id FROM v$instance"
16+
request = "SELECT instance_number AS curr_inst_id FROM gv$instance"
1717

1818
[[metric]]
1919
context = "teq"

‎default-metrics.toml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,48 @@
22
context = "sessions"
33
labels = [ "status", "type" ]
44
metricsdesc = { value= "Gauge metric with count of sessions by status and type." }
5-
request = "SELECT status, type, COUNT(*) as value FROM v$session GROUP BY status, type"
5+
request = '''
6+
select status, type, count(*) as value
7+
from gv$session
8+
group by status, type
9+
'''
610

711
[[metric]]
812
context = "resource"
913
labels = [ "resource_name" ]
1014
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)." }
1115
request = '''
12-
SELECT resource_name, current_utilization, CASE WHEN TRIM(limit_value) LIKE 'UNLIMITED' THEN '-1' ELSE TRIM(limit_value) END as limit_value
13-
FROM v$resource_limit
16+
select resource_name, current_utilization, case when trim(limit_value) like 'unlimited' then '-1' else trim(limit_value) end as limit_value
17+
from gv$resource_limit
1418
'''
1519
ignorezeroresult = true
1620

1721
[[metric]]
1822
context = "asm_diskgroup"
1923
labels = [ "name" ]
2024
metricsdesc = { total = "Total size of ASM disk group.", free = "Free space available on ASM disk group." }
21-
request = "SELECT name,total_mb*1024*1024 as total,free_mb*1024*1024 as free FROM v$asm_diskgroup_stat where exists (select 1 from v$datafile where name like '+%')"
25+
request = '''
26+
select name, total_mb*1024*1024 as total, free_mb*1024*1024 as free
27+
from gv$asm_diskgroup_stat
28+
where exists (select 1 from gv$datafile where name like '+%')
29+
and inst_id = (select max(inst_id) from gv$instance)
30+
group by name, total_mb, free_mb
31+
'''
2232
ignorezeroresult = true
2333

2434
[[metric]]
2535
context = "activity"
26-
metricsdesc = { value="Generic counter metric from v$sysstat view in Oracle." }
36+
metricsdesc = { value="Generic counter metric from gv$sysstat view in Oracle." }
2737
fieldtoappend = "name"
28-
request = "SELECT name, value FROM v$sysstat WHERE name IN ('parse count (total)', 'execute count', 'user commits', 'user rollbacks')"
38+
request = '''
39+
select name, value from gv$sysstat
40+
where name in ('parse count (total)', 'execute count', 'user commits', 'user rollbacks')
41+
'''
2942

3043
[[metric]]
3144
context = "process"
3245
metricsdesc = { count="Gauge metric with count of processes." }
33-
request = "SELECT COUNT(*) as count FROM v$process"
46+
request = "select count(*) as count from gv$process"
3447

3548
[[metric]]
3649
context = "wait_time"
@@ -43,7 +56,7 @@ select
4356
wait_class,
4457
round(time_waited/100,3) time_waited_sec_total,
4558
con_id
46-
from v$system_wait_class
59+
from gv$system_wait_class
4760
where wait_class <> 'Idle'
4861
'''
4962
ignorezeroresult = true
@@ -80,8 +93,8 @@ context = "db_system"
8093
labels = [ "name" ]
8194
metricsdesc = { value = "Database system resources metric" }
8295
request = '''
83-
select name, value
84-
from v$parameter
96+
select name, value
97+
from gv$parameter
8598
where name in ('cpu_count', 'sga_max_size', 'pga_aggregate_limit')
8699
'''
87100

@@ -90,7 +103,7 @@ context = "db_platform"
90103
labels = [ "platform_name" ]
91104
metricsdesc = { value = "Database platform" }
92105
request = '''
93-
SELECT platform_name, 1 as value FROM v$database
106+
SELECT platform_name, 1 as value FROM gv$database
94107
'''
95108

96109
[[metric]]
@@ -99,16 +112,16 @@ labels = [ "sql_id", "sql_text" ]
99112
metricsdesc = { elapsed = "SQL statement elapsed time running" }
100113
request = '''
101114
select * from (
102-
select sql_id, elapsed_time / 1000000 as elapsed, SUBSTRB(REPLACE(sql_text,'',' '),1,55) as sql_text
103-
from V$SQLSTATS
115+
select sql_id, elapsed_time / 1000000 as elapsed, substrb(replace(sql_text,'',' '),1,55) as sql_text
116+
from gv$sqlstats
104117
order by elapsed_time desc
105-
) where ROWNUM <= 15
118+
) where rownum <= 15
106119
'''
107120
ignorezeroresult = true
108121
# scrapeinterval = "5m"
109122
# The previous line is an example of changing the interval at which this one metric
110123
# will be scraped. You may wish to do this to scrape a metric less often, if the SQL
111-
# statement to collect that metric places more load on your database instance than
124+
# statement to collect that metric places more load on your database instance than
112125
# desired when it is run at every scrape.
113126

114127
[[metric]]
@@ -117,7 +130,7 @@ labels = [ "cache_hit_type" ]
117130
metricsdesc = { value = "Cache Hit Ratio" }
118131
request = '''
119132
select metric_name cache_hit_type, value
120-
from v$sysmetric
133+
from gv$sysmetric
121134
where group_id=2 and metric_id in (2000,2050,2112,2110)
122135
'''
123136
ignorezeroresult = true

‎docker-compose/exporter/txeventq-metrics.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ scrapeinterval = "30s"
1616
[[metric]]
1717
context = "teq"
1818
metricsdesc = { curr_inst_id = "ID of current instance" }
19-
request = "SELECT instance_number AS curr_inst_id FROM v$instance"
19+
request = "SELECT instance_number AS curr_inst_id FROM gv$instance"
2020
ignorezeroresult = true
2121

2222
[[metric]]

0 commit comments

Comments
 (0)