forked from carlos-sierra/cscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcs_dg_redo_dest_resp_histogram_chart.sql
More file actions
194 lines (194 loc) · 7.49 KB
/
cs_dg_redo_dest_resp_histogram_chart.sql
File metadata and controls
194 lines (194 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
----------------------------------------------------------------------------------------
--
-- File name: cs_dg_redo_dest_resp_histogram_chart.sql
--
-- Purpose: Data Guard (DG) REDO Transport Duration Chart
--
-- Author: Carlos Sierra
--
-- Version: 2020/12/25
--
-- Usage: Execute connected to CDB.
--
-- Enter Source and Destination Hosts when requested.
--
-- Example: $ sqlplus / as sysdba
-- SQL> @cs_dg_redo_dest_resp_histogram_chart.sql
--
-- Notes: Developed and tested on 12.1.0.2.
--
---------------------------------------------------------------------------------------
--
@@cs_internal/cs_primary.sql
--@@cs_internal/cs_cdb_warn.sql
@@cs_internal/cs_set.sql
@@cs_internal/cs_def.sql
@@cs_internal/cs_file_prefix.sql
--
DEF cs_script_name = 'cs_dg_redo_dest_resp_histogram_chart';
DEF cs_hours_range_default = '8760';
--
ALTER SESSION SET container = CDB$ROOT;
--
COL cs_hours_range_default NEW_V cs_hours_range_default NOPRI;
SELECT TRIM(TO_CHAR(LEAST(TRUNC((SYSDATE - MIN(time)) * 24), TO_NUMBER('&&cs_hours_range_default.')))) AS cs_hours_range_default FROM &&cs_tools_schema..dbc_redo_dest_histogram
/
--
@@cs_internal/cs_sample_time_from_and_to.sql
@@cs_internal/cs_snap_id_from_and_to.sql
--
COL source_host_name FOR A64 TRUNC;
SELECT DISTINCT host_name AS source_host_name
FROM &&cs_tools_schema..dbc_redo_dest_histogram
WHERE time BETWEEN TO_DATE('&&cs_sample_time_from.', '&&cs_datetime_full_format.') AND TO_DATE('&&cs_sample_time_to.', '&&cs_datetime_full_format.')
ORDER BY 1
/
PRO
PRO 3. Source Host Name: (opt)
DEF s_host_name = '&3.';
UNDEF 3;
--
COL dest_host_name FOR A64 TRUNC;
SELECT DISTINCT dest_host_name
FROM &&cs_tools_schema..dbc_redo_dest_histogram
WHERE time BETWEEN TO_DATE('&&cs_sample_time_from.', '&&cs_datetime_full_format.') AND TO_DATE('&&cs_sample_time_to.', '&&cs_datetime_full_format.')
AND host_name = NVL('&&s_host_name.', host_name)
ORDER BY 1
/
PRO
PRO 3. Destination Host Name: (opt)
DEF d_host_name = '&4.';
UNDEF 4;
--
DEF source_dest_host_name = "";
COL source_dest_host_name NEW_V source_dest_host_name NOPRI;
SELECT CASE WHEN '&&s_host_name.' IS NOT NULL THEN 'SRC:&&s_host_name.' END||CASE WHEN '&&s_host_name.&&d_host_name.' IS NOT NULL THEN ' -> ' END||CASE WHEN '&&d_host_name.' IS NOT NULL THEN 'DST:&&d_host_name.' END AS source_dest_host_name FROM DUAL
/
--
COL label1 NEW_V label1 NOPRI;
COL label2 NEW_V label2 NOPRI;
COL label3 NEW_V label3 NOPRI;
COL label4 NEW_V label4 NOPRI;
COL label5 NEW_V label5 NOPRI;
COL label6 NEW_V label6 NOPRI;
WITH
scope AS (
SELECT host_name||' -> '||dest_host_name AS label, SUM(duration_seconds) AS entries, ROW_NUMBER() OVER (ORDER BY SUM(duration_seconds) DESC) AS rn
FROM &&cs_tools_schema..dbc_redo_dest_histogram
WHERE time BETWEEN TO_DATE('&&cs_sample_time_from.', '&&cs_datetime_full_format.') AND TO_DATE('&&cs_sample_time_to.', '&&cs_datetime_full_format.')
AND host_name = NVL('&&s_host_name.', host_name)
AND dest_host_name = NVL('&&d_host_name.', dest_host_name)
GROUP BY host_name||' -> '||dest_host_name
ORDER BY 2 DESC NULLS LAST
FETCH FIRST 6 ROWS ONLY
)
SELECT MAX(CASE rn WHEN 1 THEN label END) AS label1,
MAX(CASE rn WHEN 2 THEN label END) AS label2,
MAX(CASE rn WHEN 3 THEN label END) AS label3,
MAX(CASE rn WHEN 4 THEN label END) AS label4,
MAX(CASE rn WHEN 5 THEN label END) AS label5,
MAX(CASE rn WHEN 6 THEN label END) AS label6
FROM scope
WHERE rn BETWEEN 1 AND 6
/
--
SELECT '&&cs_file_prefix._&&cs_script_name.' cs_file_name FROM DUAL;
--
DEF report_title = "Data Guard (DG) REDO Transport Duration (v$redo_dest_resp_histogram)";
DEF chart_title = "Data Guard (DG) REDO Transport Duration";
DEF xaxis_title = "&&source_dest_host_name.";
DEF vaxis_title = "Duration (Seconds)";
-- DEF hAxis_maxValue = "&&cs_hAxis_maxValue.";
-- DEF cs_trendlines_series = ", 0:{}, 1:{}, 2:{}";
--
-- (isStacked is true and baseline is null) or (not isStacked and baseline >= 0)
--DEF is_stacked = "isStacked: false,";
DEF is_stacked = "isStacked: true,";
--DEF vaxis_baseline = ", baseline:&&cs_num_cpu_cores., baselineColor:'red'";
DEF vaxis_baseline = "";
--DEF chart_foot_note_2 = "<br>2) ";
DEF chart_foot_note_2 = "";
DEF chart_foot_note_3 = "";
DEF chart_foot_note_4 = "";
DEF report_foot_note = 'SQL> @&&cs_script_name..sql "&&cs_sample_time_from." "&&cs_sample_time_to." "&&s_host_name." "&&d_host_name."';
--
@@cs_internal/cs_spool_head_chart.sql
--
PRO ,{label:'&&label1.', id:'1', type:'number'}
PRO ,{label:'&&label2.', id:'2', type:'number'}
PRO ,{label:'&&label3.', id:'3', type:'number'}
PRO ,{label:'&&label4.', id:'4', type:'number'}
PRO ,{label:'&&label5.', id:'5', type:'number'}
PRO ,{label:'&&label6.', id:'6', type:'number'}
PRO ]
--
SET HEA OFF PAGES 0;
/****************************************************************************************/
WITH
FUNCTION num_format (p_number IN NUMBER, p_round IN NUMBER DEFAULT 0)
RETURN VARCHAR2 IS
BEGIN
IF p_number IS NULL OR ROUND(p_number, p_round) <= 0 THEN
RETURN 'null';
ELSE
RETURN TO_CHAR(ROUND(p_number, p_round));
END IF;
END num_format;
/****************************************************************************************/
my_query AS (
SELECT time AS timestamp,
CASE host_name||' -> '||dest_host_name WHEN '&&label1.' THEN duration_seconds END AS seconds1,
CASE host_name||' -> '||dest_host_name WHEN '&&label2.' THEN duration_seconds END AS seconds2,
CASE host_name||' -> '||dest_host_name WHEN '&&label3.' THEN duration_seconds END AS seconds3,
CASE host_name||' -> '||dest_host_name WHEN '&&label4.' THEN duration_seconds END AS seconds4,
CASE host_name||' -> '||dest_host_name WHEN '&&label5.' THEN duration_seconds END AS seconds5,
CASE host_name||' -> '||dest_host_name WHEN '&&label6.' THEN duration_seconds END AS seconds6
FROM &&cs_tools_schema..dbc_redo_dest_histogram
WHERE time BETWEEN TO_DATE('&&cs_sample_time_from.', '&&cs_datetime_full_format.') AND TO_DATE('&&cs_sample_time_to.', '&&cs_datetime_full_format.')
AND host_name = NVL('&&s_host_name.', host_name)
AND dest_host_name = NVL('&&d_host_name.', dest_host_name)
AND host_name||' -> '||dest_host_name IN ('&&label1.', '&&label2.', '&&label3.', '&&label4.', '&&label5.', '&&label6.')
)
SELECT ', [new Date('||
TO_CHAR(q.timestamp, 'YYYY')|| /* year */
','||(TO_NUMBER(TO_CHAR(q.timestamp, 'MM')) - 1)|| /* month - 1 */
','||TO_CHAR(q.timestamp, 'DD')|| /* day */
','||TO_CHAR(q.timestamp, 'HH24')|| /* hour */
','||TO_CHAR(q.timestamp, 'MI')|| /* minute */
','||TO_CHAR(q.timestamp, 'SS')|| /* second */
')'||
','||num_format(q.seconds1)||
','||num_format(q.seconds2)||
','||num_format(q.seconds3)||
','||num_format(q.seconds4)||
','||num_format(q.seconds5)||
','||num_format(q.seconds6)||
']'
FROM my_query q
ORDER BY
q.timestamp
/
/****************************************************************************************/
SET HEA ON PAGES 100;
--
-- [Line|Area|SteppedArea|Scatter]
DEF cs_chart_type = 'Scatter';
-- disable explorer with "//" when using Pie
DEF cs_chart_option_explorer = '';
-- enable pie options with "" when using Pie
DEF cs_chart_option_pie = '//';
-- use oem colors
DEF cs_oem_colors_series = '//';
DEF cs_oem_colors_slices = '//';
-- for line charts
DEF cs_curve_type = '';
--
@@cs_internal/cs_spool_id_chart.sql
@@cs_internal/cs_spool_tail_chart.sql
PRO
PRO &&report_foot_note.
--
ALTER SESSION SET CONTAINER = &&cs_con_name.;
--
@@cs_internal/cs_undef.sql
@@cs_internal/cs_reset.sql