SlideShare a Scribd company logo
Bertrand Drouvot









Oracle DBA since 1999
OCP 9i,10g,11g
Rac certified Expert
Exadata certified implementation specialist
Blogger since 2012
@bertranddrouvot
BasketBall fan








Some examples of R usage with the oracle
database
From a DBA point of view
Retrieve system statistics/wait events with
some AWR queries
Real time Data
Dashboard of the database activity




R installation
R programing
R studio (powerful and productive user
interface for R)




Because R is a powerful tool for statistical
analysis with graphing and plotting packages
built in.
Furthermore, R can connect to Oracle via a
JDBC package which makes importing data
very easy.


http://www.r-project.org/







library(RJDBC)
drv <JDBC("oracle.jdbc.driver.OracleDriver","/ec/pr
od/server/oracle/olrprod1/u000/product/11.
2.0.3/jdbc/lib/ojdbc6.jar")
conn<-dbConnect(drv,conn_string,"sys as
sysasm",sys_pwd)
Data_frame<-dbGetQuery(conn,myquery)
select s.begin_interval_time,sta.stat_name,sta.VALUE,
round(((sta.VALUE)/
(
(extract(day from s.END_INTERVAL_TIME)-extract(day from s.BEGIN_INTERVAL_TIME))*86400 +
(extract(hour from s.END_INTERVAL_TIME)-extract(hour from s.BEGIN_INTERVAL_TIME))*3600 +
(extract(minute from s.END_INTERVAL_TIME)-extract(minute from s.BEGIN_INTERVAL_TIME))*60 +
(extract(second from s.END_INTERVAL_TIME)-extract(second from s.BEGIN_INTERVAL_TIME))
)
),2) VALUE_PER_SEC
from
(
select instance_number,snap_id,stat_name,
value - first_value(value) over (partition by stat_name order by snap_id rows 1 preceding) "VALUE"
from
dba_hist_sysstat
where stat_name like nvl('&stat_name',stat_name)
and instance_number = (select instance_number from v$instance)
) sta, dba_hist_snapshot s
where sta.instance_number=s.instance_number
and sta.snap_id=s.snap_id
and s.BEGIN_INTERVAL_TIME >= trunc(sysdate-&sysdate_nb_day_begin_interval+1)
and s.BEGIN_INTERVAL_TIME <= trunc(sysdate-&sysdate_nb_day_end_interval+1)
order by s.begin_interval_time asc;
Example R usage for oracle DBA UKOUG 2013
Example R usage for oracle DBA UKOUG 2013










# Plot the 4 graphs
par(mfrow =c(4,1))
plot(sqstat[,'DATEEVT'],sqstat[,'VALUE'],type="l",col="blue"
,xaxt="n",main=stat_name,cex.main=2,xlab="",ylab="VAL
UE")
Axis(side=1,at=sqstat$DATEEVT,round(skip),format="%Y/
%m/%d %H:%M")
plot(sqstat[,'DATEEVT'],sqstat[,'VALUE_PER_SEC'],type="l",c
ol="blue",xaxt="n",xlab="",ylab="VALUE_PER_SEC")
Axis(side=1,at=sqstat$DATEEVT,round(skip),format="%Y/
%m/%d %H:%M")
hist(sqstat[,'VALUE'],xlab="VALUE",main=NULL,border="bl
ue")
hist(sqstat[,'VALUE_PER_SEC'],xlab="VALUE_PER_SEC",main
=NULL,border="blue")
select e.WAIT_CLASS,e.event_name,s.begin_interval_time,e.TOTAL_WAITS,e.TIME_WAITED_MS,e.TIME_WAITED_MS /
TOTAL_WAITS "MS_PER_WAIT"
from
(
select instance_number,snap_id,WAIT_CLASS,event_name,
total_waits - first_value(total_waits) over (partition by event_name order by snap_id rows 1 preceding)
"TOTAL_WAITS",
(time_waited_micro - first_value(time_waited_micro) over (partition by event_name order by snap_id rows 1
preceding))/1000 "TIME_WAITED_MS"
from
dba_hist_system_event
where
WAIT_CLASS like nvl('&WAIT_CLASS',WAIT_CLASS)
and event_name like nvl('&event_name',event_name)
and instance_number = (select instance_number from v$instance)
) e, dba_hist_snapshot s
where e.TIME_WAITED_MS > 0
and e.instance_number=s.instance_number
and e.snap_id=s.snap_id
and s.BEGIN_INTERVAL_TIME >= trunc(sysdate-&sysdate_nb_day_begin_interval+1)
and s.BEGIN_INTERVAL_TIME <= trunc(sysdate-&sysdate_nb_day_end_interval+1) order by 1
Example R usage for oracle DBA UKOUG 2013











# Plot the 4 graphs
par(mfrow =c(4,1))
plot(sqevent[,'DATEEVT'],sqevent[,'TIME_WAITED_MS'],type="l",col="blue"
,xaxt="n",main=event,cex.main=2,xlab="",ylab="TIME_WAITED_MS")
Axis(side=1,at=sqevent$DATEEVT,round(skip),format="%Y/%m/%d
%H:%M")
plot(sqevent[,'DATEEVT'],sqevent[,'TOTAL_WAITS'],type="l",col="blue",xa
xt="n",xlab="",ylab="NB_WAITS")
Axis(side=1,at=sqevent$DATEEVT,round(skip),format="%Y/%m/%d
%H:%M")
plot(sqevent[,'DATEEVT'],sqevent[,'MS_PER_WAIT'],type="l",col="blue",xa
xt="n",xlab="",ylab="MS_PER_WAIT")
Axis(side=1,at=sqevent$DATEEVT,round(skip),format="%Y/%m/%d
%H:%M")
hist(sqevent[,'MS_PER_WAIT'],xlab="MS_PER_WAIT",main=NULL,border="
blue")


Query is a little bit complicated (comes from
OEM)
Example R usage for oracle DBA UKOUG 2013
Example R usage for oracle DBA UKOUG 2013
Example R usage for oracle DBA UKOUG 2013




















# compute percentages
pct <- round(dg_space[,'SIZE_GB']/sum(dg_space[,'SIZE_GB'])*100)
# add %
pct <- paste(pct,"%",sep="")
# Add db size to db_name
db_name_size<-paste(dg_space[,'DB_NAME']," (",sep="")
db_name_size<-paste(db_name_size,dg_space[,'SIZE_GB'],sep="")
db_name_size<-paste(db_name_size," GB)",sep="")

# Set the colors
colors<-rainbow(length(dg_space[,'DB_NAME']))
# Plot
pie(dg_space[,'SIZE_GB'], labels = pct, col=colors, main=paste(dg," Disk Group Usage",sep=""))
# Add a legend
legend(x=1.2,y=0.5,legend=db_name_size,fill=colors,cex=0.8)


Basically the script takes a snapshot based on
the v$sysstat view then computes and graphs
the delta with the previous snapshot.
Example R usage for oracle DBA UKOUG 2013
Example R usage for oracle DBA UKOUG 2013
myquery<-"
Select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT, NAME,VALUE,1 VALUE_PER_SEC
from v$sysstat
where name='"
# Keep them
prev_date<<-qoutput[,'DATEEVT']
prev_value<<-qoutput[,'VALUE']
# Launch the loop for the real-time graph
nb_refresh <- as.integer(nb_refresh)
for(i in seq(nb_refresh)) {
# Get the new data
Sys.sleep(refresh_interval)
qoutput<-dbGetQuery(conn,myquery)
# Keep the current value
current_date<-qoutput[,'DATEEVT']
current_value<-qoutput[,'VALUE']
# compute difference between snap for value and value per sec
#qoutput[,'DATEEVT']<-current_date
qoutput[,'VALUE']<-current_value-prev_value


Basically the script takes a snapshot based on
the v$system_event view then computes and
graphs the delta with the previous snapshot.
Example R usage for oracle DBA UKOUG 2013
myquery<-"
Select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as
DATEEVT, EVENT,TOTAL_WAITS,TIME_WAITED_MICRO/1000 as TIME_WAITED_MS,1 MS_PER_WAIT
from v$system_event
where event='"
# Keep them
prev_tw<<-qoutput[,'TIME_WAITED_MS']
prev_twaits<<-qoutput[,'TOTAL_WAITS']
# So we want 4 graphs
par(mfrow =c(4,1))
# Launch the loop for the real-time graph
nb_refresh <- as.integer(nb_refresh)
for(i in seq(nb_refresh)) {
# Get the new data
Sys.sleep(refresh_interval)
qoutput<-dbGetQuery(conn,myquery)
# compute difference between snap for time_waited_ms, total_waits and then compute ms_per_wait
qoutput[,'TIME_WAITED_MS']<-current_tw-prev_tw
qoutput[,'TOTAL_WAITS']<-current_twaits-prev_twaits
myquery<-"
select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT,
wait_class as WAIT_CLASS,
time_waited_micro/1000 as TIME_WAITED_MS,
EVENT as EVENT
from v$system_event where WAIT_CLASS != 'Idle'
union
select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT,
'CPU' as WAIT_CLASS
,sum(value/1000) as TIME_WAITED_MS
,'CPU' as EVENT
from
v$sys_time_model
where
stat_name IN ('background cpu time', 'DB CPU')
"
Example R usage for oracle DBA UKOUG 2013


Sub-graph for the time waited (in ms) per
wait class:


Sub-graph for the wait events distribution
of the wait class having the max time
waited during the last snap:


Sub-graph for the wait class distribution
since the script has been launched:
Example R usage for oracle DBA UKOUG 2013







# Split the screen
no_display<-split.screen( figs = c( 2, 1 ) )
# Split the second screen
no_display<-split.screen( figs = c( 1, 2
), screen=2 )
Much more complicated: source code is
available through my blog.




Retrieve and visualize in real time the output
of my asm_metrics.pl utility.
What is yours ?

More Related Content

PPTX
Oracle: Binding versus caging
PPTX
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
PDF
Chef patterns
PPT
Oracle Open World Thursday 230 ashmasters
PPT
Intro to ASH
PDF
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
PDF
Advanced Apache Cassandra Operations with JMX
PPTX
Data Guard New Features
Oracle: Binding versus caging
Reduce Resource Consumption & Clone in Seconds your Oracle Virtual Environmen...
Chef patterns
Oracle Open World Thursday 230 ashmasters
Intro to ASH
PostgreSQL Performance Tables Partitioning vs. Aggregated Data Tables
Advanced Apache Cassandra Operations with JMX
Data Guard New Features

What's hot (20)

PDF
PostgreSQL Replication Tutorial
PPT
Ash masters : advanced ash analytics on Oracle
PDF
Advanced Postgres Monitoring
DOCX
Xtrabackup工具使用简介 - 20110427
PDF
Exadata X3 in action: Measuring Smart Scan efficiency with AWR
PDF
collectd & PostgreSQL
PDF
PostgreSQL High_Performance_Cheatsheet
PDF
Cassandra South Bay Meetup - Backup And Restore For Apache Cassandra
DOCX
Enable archivelod mode in oracle rac12cR1 with asm location
PDF
In Defense Of Core Data
PDF
12c SQL Plan Directives
PDF
VirtaThon 2011 - Mining the AWR
ODP
PostgreSQL Administration for System Administrators
PDF
Oracle NOLOGGING
PPT
Rmoug ashmaster
PDF
How to teach an elephant to rock'n'roll
PDF
Apache Con NA 2013 - Cassandra Internals
PDF
Database decommission process
PDF
Administering and Monitoring SolrCloud Clusters
PDF
Troubleshooting PostgreSQL with pgCenter
PostgreSQL Replication Tutorial
Ash masters : advanced ash analytics on Oracle
Advanced Postgres Monitoring
Xtrabackup工具使用简介 - 20110427
Exadata X3 in action: Measuring Smart Scan efficiency with AWR
collectd & PostgreSQL
PostgreSQL High_Performance_Cheatsheet
Cassandra South Bay Meetup - Backup And Restore For Apache Cassandra
Enable archivelod mode in oracle rac12cR1 with asm location
In Defense Of Core Data
12c SQL Plan Directives
VirtaThon 2011 - Mining the AWR
PostgreSQL Administration for System Administrators
Oracle NOLOGGING
Rmoug ashmaster
How to teach an elephant to rock'n'roll
Apache Con NA 2013 - Cassandra Internals
Database decommission process
Administering and Monitoring SolrCloud Clusters
Troubleshooting PostgreSQL with pgCenter
Ad

Viewers also liked (13)

PPTX
Automatic Storage Management (ASM) metrics are a goldmine: Let's use them!
PDF
Prepare for the Worst: Reliable Data Protection with Oracle RMAN and Oracle D...
PPTX
Visualizing ORACLE performance data with R @ #C16LV
PPTX
Introduction To R
PDF
Big Data Analytics with R
PPTX
Big data analytics using R
KEY
Presentation R basic teaching module
PPTX
Antagonistas adrenergicos
PPTX
Data analysis with R
PPTX
R for data analytics
PPTX
Language R
PPTX
R language tutorial
PDF
Iris data analysis example in R
Automatic Storage Management (ASM) metrics are a goldmine: Let's use them!
Prepare for the Worst: Reliable Data Protection with Oracle RMAN and Oracle D...
Visualizing ORACLE performance data with R @ #C16LV
Introduction To R
Big Data Analytics with R
Big data analytics using R
Presentation R basic teaching module
Antagonistas adrenergicos
Data analysis with R
R for data analytics
Language R
R language tutorial
Iris data analysis example in R
Ad

Similar to Example R usage for oracle DBA UKOUG 2013 (20)

PDF
ROracle
PDF
Overview of running R in the Oracle Database
PDF
Introduction to Data Analtics with Pandas [PyCon Cz]
PPTX
A Workshop on R
PPTX
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
PDF
Introduction to Pandas and Time Series Analysis [PyCon DE]
PPTX
temporal and spatial database.pptx
PPTX
unit 5_Real time Data Analysis vsp.pptx
PPT
tempDB.ppt
PDF
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
PDF
Time Series Analytics with Spark: Spark Summit East talk by Simon Ouellette
PDF
Embedded R Execution using SQL
PDF
PERFORMANCE STUDY OF TIME SERIES DATABASES
PDF
Performance Comparison between Pytorch and Mindspore
PDF
Introduction to Data Mining with R and Data Import/Export in R
PDF
Introduction to Pandas and Time Series Analysis [Budapest BI Forum]
PDF
Distributed Computing for Everyone
PPTX
Power of SPL Breakout Session
PDF
Ebs dba con4696_pdf_4696_0001
PDF
Your Timestamps Deserve Better than a Generic Database
ROracle
Overview of running R in the Oracle Database
Introduction to Data Analtics with Pandas [PyCon Cz]
A Workshop on R
Get up to Speed (Quick Guide to data.table in R and Pentaho PDI)
Introduction to Pandas and Time Series Analysis [PyCon DE]
temporal and spatial database.pptx
unit 5_Real time Data Analysis vsp.pptx
tempDB.ppt
OSA Con 2022 - Specifics of data analysis in Time Series Databases - Roman Kh...
Time Series Analytics with Spark: Spark Summit East talk by Simon Ouellette
Embedded R Execution using SQL
PERFORMANCE STUDY OF TIME SERIES DATABASES
Performance Comparison between Pytorch and Mindspore
Introduction to Data Mining with R and Data Import/Export in R
Introduction to Pandas and Time Series Analysis [Budapest BI Forum]
Distributed Computing for Everyone
Power of SPL Breakout Session
Ebs dba con4696_pdf_4696_0001
Your Timestamps Deserve Better than a Generic Database

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Programs and apps: productivity, graphics, security and other tools
Encapsulation_ Review paper, used for researhc scholars
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf

Example R usage for oracle DBA UKOUG 2013

  • 2.        Oracle DBA since 1999 OCP 9i,10g,11g Rac certified Expert Exadata certified implementation specialist Blogger since 2012 @bertranddrouvot BasketBall fan
  • 3.      Some examples of R usage with the oracle database From a DBA point of view Retrieve system statistics/wait events with some AWR queries Real time Data Dashboard of the database activity
  • 4.    R installation R programing R studio (powerful and productive user interface for R)
  • 5.   Because R is a powerful tool for statistical analysis with graphing and plotting packages built in. Furthermore, R can connect to Oracle via a JDBC package which makes importing data very easy.
  • 8. select s.begin_interval_time,sta.stat_name,sta.VALUE, round(((sta.VALUE)/ ( (extract(day from s.END_INTERVAL_TIME)-extract(day from s.BEGIN_INTERVAL_TIME))*86400 + (extract(hour from s.END_INTERVAL_TIME)-extract(hour from s.BEGIN_INTERVAL_TIME))*3600 + (extract(minute from s.END_INTERVAL_TIME)-extract(minute from s.BEGIN_INTERVAL_TIME))*60 + (extract(second from s.END_INTERVAL_TIME)-extract(second from s.BEGIN_INTERVAL_TIME)) ) ),2) VALUE_PER_SEC from ( select instance_number,snap_id,stat_name, value - first_value(value) over (partition by stat_name order by snap_id rows 1 preceding) "VALUE" from dba_hist_sysstat where stat_name like nvl('&stat_name',stat_name) and instance_number = (select instance_number from v$instance) ) sta, dba_hist_snapshot s where sta.instance_number=s.instance_number and sta.snap_id=s.snap_id and s.BEGIN_INTERVAL_TIME >= trunc(sysdate-&sysdate_nb_day_begin_interval+1) and s.BEGIN_INTERVAL_TIME <= trunc(sysdate-&sysdate_nb_day_end_interval+1) order by s.begin_interval_time asc;
  • 11.         # Plot the 4 graphs par(mfrow =c(4,1)) plot(sqstat[,'DATEEVT'],sqstat[,'VALUE'],type="l",col="blue" ,xaxt="n",main=stat_name,cex.main=2,xlab="",ylab="VAL UE") Axis(side=1,at=sqstat$DATEEVT,round(skip),format="%Y/ %m/%d %H:%M") plot(sqstat[,'DATEEVT'],sqstat[,'VALUE_PER_SEC'],type="l",c ol="blue",xaxt="n",xlab="",ylab="VALUE_PER_SEC") Axis(side=1,at=sqstat$DATEEVT,round(skip),format="%Y/ %m/%d %H:%M") hist(sqstat[,'VALUE'],xlab="VALUE",main=NULL,border="bl ue") hist(sqstat[,'VALUE_PER_SEC'],xlab="VALUE_PER_SEC",main =NULL,border="blue")
  • 12. select e.WAIT_CLASS,e.event_name,s.begin_interval_time,e.TOTAL_WAITS,e.TIME_WAITED_MS,e.TIME_WAITED_MS / TOTAL_WAITS "MS_PER_WAIT" from ( select instance_number,snap_id,WAIT_CLASS,event_name, total_waits - first_value(total_waits) over (partition by event_name order by snap_id rows 1 preceding) "TOTAL_WAITS", (time_waited_micro - first_value(time_waited_micro) over (partition by event_name order by snap_id rows 1 preceding))/1000 "TIME_WAITED_MS" from dba_hist_system_event where WAIT_CLASS like nvl('&WAIT_CLASS',WAIT_CLASS) and event_name like nvl('&event_name',event_name) and instance_number = (select instance_number from v$instance) ) e, dba_hist_snapshot s where e.TIME_WAITED_MS > 0 and e.instance_number=s.instance_number and e.snap_id=s.snap_id and s.BEGIN_INTERVAL_TIME >= trunc(sysdate-&sysdate_nb_day_begin_interval+1) and s.BEGIN_INTERVAL_TIME <= trunc(sysdate-&sysdate_nb_day_end_interval+1) order by 1
  • 14.          # Plot the 4 graphs par(mfrow =c(4,1)) plot(sqevent[,'DATEEVT'],sqevent[,'TIME_WAITED_MS'],type="l",col="blue" ,xaxt="n",main=event,cex.main=2,xlab="",ylab="TIME_WAITED_MS") Axis(side=1,at=sqevent$DATEEVT,round(skip),format="%Y/%m/%d %H:%M") plot(sqevent[,'DATEEVT'],sqevent[,'TOTAL_WAITS'],type="l",col="blue",xa xt="n",xlab="",ylab="NB_WAITS") Axis(side=1,at=sqevent$DATEEVT,round(skip),format="%Y/%m/%d %H:%M") plot(sqevent[,'DATEEVT'],sqevent[,'MS_PER_WAIT'],type="l",col="blue",xa xt="n",xlab="",ylab="MS_PER_WAIT") Axis(side=1,at=sqevent$DATEEVT,round(skip),format="%Y/%m/%d %H:%M") hist(sqevent[,'MS_PER_WAIT'],xlab="MS_PER_WAIT",main=NULL,border=" blue")
  • 15.  Query is a little bit complicated (comes from OEM)
  • 19.               # compute percentages pct <- round(dg_space[,'SIZE_GB']/sum(dg_space[,'SIZE_GB'])*100) # add % pct <- paste(pct,"%",sep="") # Add db size to db_name db_name_size<-paste(dg_space[,'DB_NAME']," (",sep="") db_name_size<-paste(db_name_size,dg_space[,'SIZE_GB'],sep="") db_name_size<-paste(db_name_size," GB)",sep="") # Set the colors colors<-rainbow(length(dg_space[,'DB_NAME'])) # Plot pie(dg_space[,'SIZE_GB'], labels = pct, col=colors, main=paste(dg," Disk Group Usage",sep="")) # Add a legend legend(x=1.2,y=0.5,legend=db_name_size,fill=colors,cex=0.8)
  • 20.  Basically the script takes a snapshot based on the v$sysstat view then computes and graphs the delta with the previous snapshot.
  • 23. myquery<-" Select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT, NAME,VALUE,1 VALUE_PER_SEC from v$sysstat where name='" # Keep them prev_date<<-qoutput[,'DATEEVT'] prev_value<<-qoutput[,'VALUE'] # Launch the loop for the real-time graph nb_refresh <- as.integer(nb_refresh) for(i in seq(nb_refresh)) { # Get the new data Sys.sleep(refresh_interval) qoutput<-dbGetQuery(conn,myquery) # Keep the current value current_date<-qoutput[,'DATEEVT'] current_value<-qoutput[,'VALUE'] # compute difference between snap for value and value per sec #qoutput[,'DATEEVT']<-current_date qoutput[,'VALUE']<-current_value-prev_value
  • 24.  Basically the script takes a snapshot based on the v$system_event view then computes and graphs the delta with the previous snapshot.
  • 26. myquery<-" Select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT, EVENT,TOTAL_WAITS,TIME_WAITED_MICRO/1000 as TIME_WAITED_MS,1 MS_PER_WAIT from v$system_event where event='" # Keep them prev_tw<<-qoutput[,'TIME_WAITED_MS'] prev_twaits<<-qoutput[,'TOTAL_WAITS'] # So we want 4 graphs par(mfrow =c(4,1)) # Launch the loop for the real-time graph nb_refresh <- as.integer(nb_refresh) for(i in seq(nb_refresh)) { # Get the new data Sys.sleep(refresh_interval) qoutput<-dbGetQuery(conn,myquery) # compute difference between snap for time_waited_ms, total_waits and then compute ms_per_wait qoutput[,'TIME_WAITED_MS']<-current_tw-prev_tw qoutput[,'TOTAL_WAITS']<-current_twaits-prev_twaits
  • 27. myquery<-" select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT, wait_class as WAIT_CLASS, time_waited_micro/1000 as TIME_WAITED_MS, EVENT as EVENT from v$system_event where WAIT_CLASS != 'Idle' union select to_char(sysdate,'YYYY/MM/DD HH24:MI:SS') as DATEEVT, 'CPU' as WAIT_CLASS ,sum(value/1000) as TIME_WAITED_MS ,'CPU' as EVENT from v$sys_time_model where stat_name IN ('background cpu time', 'DB CPU') "
  • 29.  Sub-graph for the time waited (in ms) per wait class:
  • 30.  Sub-graph for the wait events distribution of the wait class having the max time waited during the last snap:
  • 31.  Sub-graph for the wait class distribution since the script has been launched:
  • 33.      # Split the screen no_display<-split.screen( figs = c( 2, 1 ) ) # Split the second screen no_display<-split.screen( figs = c( 1, 2 ), screen=2 ) Much more complicated: source code is available through my blog.
  • 34.   Retrieve and visualize in real time the output of my asm_metrics.pl utility. What is yours ?