如何利用ash监控会话

ash是非常有效的监控工具之一,1秒抓一次
select max(sample_time)over(),min(sample_time)over() from dba_hist_active_sess_history;  --8天
select max(sample_time)over(),min(sample_time)over() from v$active_session_history;  --当天

首先先了解几个视图:
V$ACTIVE_SESSION_HISTORY: 是ASH的核心,用以记录活动SESSION的历史等待信息,每秒采样一次,这部分内容记录在内存中,期望值是记录一个小时的内容。
WRH#_ACTIVE_SESSION_HISTORY : 是V$ACTIVE_SESSION_HISTORY在AWR的存储地。
V$ACTIVE_SESSION_HISTORY: 中的信息会被定期(每小时一次)的刷新到负载库中,并缺省保留一个星期用于分析。
DBA_HIST_ACTIVE_SESS_HISTORY: 视图是WRH#_ACTIVE_SESSION_HISTORY视图和其他几个视图的联合展现,通常通过这个视图进行历史数据的访问。

------------------------------------
--V$ACTIVE_SESSION_HISTORY的监控:--
------------------------------------

------------session:1-----------------

SQL> @big

       SID
----------
       131

Elapsed: 00:00:00.00
drop table big
           *
ERROR at line 1:
ORA-00942: table or view does not exist

Elapsed: 00:00:00.03
Elapsed: 00:00:00.31
Elapsed: 00:00:00.34
Elapsed: 00:00:00.29
Elapsed: 00:00:00.73
Elapsed: 00:00:01.75
Elapsed: 00:00:10.59
Elapsed: 00:00:24.62
Elapsed: 00:00:00.01

     BIG_M
----------
       522
Elapsed: 00:00:00.36

  COUNT(*)
----------
   4650368
Elapsed: 00:00:26.70

------------session:2-----------------

SQL> @getash_sid
Enter value for sid: 131

SESSION_ID NAME                                                             P_NAME          P_VALUE      SQL_ID    WAIT_TIME CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK#
---------- ---------------------------------------------------------------- --------------- --------------- ------------- ---------- ------------ ------------- ---------
       131 db file sequential read                                          file#           1            d2wbn28rdk8z4     0          547             1           3604
                                                                            block#          53206
                                                                            blocks          1

       131 db file sequential read                                          file#           1            d2wbn28rdk8z4     0           -1             0              0
                                                                            block#          3009
                                                                            blocks          1

       131 db file scattered read                                           file#           4            03b71c07nsc1a     0          134             1           1064
                                                                            block#          4845
                                                                            blocks          8

       131 log buffer space                                                                 0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch completion                                                       0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           6046
                                                                                            0
                                                                                            0

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4           4995
                                                                            block#          4995
                                                                            blocks          5

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           7170
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4           7170
                                                                                            0
                                                                                            0

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4           8578
                                                                            block#          8578
                                                                            blocks          126

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          12802
                                                                            block#          12802
                                                                            blocks          126

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          12930
                                                                                            0
                                                                                            0

       131 db file sequential read                                          file#           1            aq32z6wjx1s4h     0        65921           201           3585
                                                                            block#          2854
                                                                            blocks          1

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          14084
                                                                            block#          14084
                                                                            blocks          124

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          18436
                                                                            block#          18436
                                                                            blocks          128

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          19972
                                                                            block#          19972
                                                                            blocks          128

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          21252
                                                                            block#          21252
                                                                            blocks          124

       131 db file parallel read                                            files           1            aq32z6wjx1s4h     0        76851             4          23424
                                                                            blocks          29
                                                                            requests        29

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          24320
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          24320
                                                                                            0
                                                                                            0

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          25856
                                                                            block#          25856
                                                                            blocks          128

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          27652
                                                                            block#          27652
                                                                            blocks          124

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          29312
                                                                            block#          29312
                                                                            blocks          32

       131 Disk file operations I/O                                         FileOperation   2            aq32z6wjx1s4h     0        76851             4          29952
                                                                            fileno          0
                                                                            filetype        2

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          30724
                                                                            block#          30724
                                                                            blocks          124

       131 db file scattered read                                           file#           4            aq32z6wjx1s4h     0        76851             4          34530
                                                                            block#          34530
                                                                            blocks          14

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          35716
                                                                                            0
                                                                                            0

       131 log file switch (checkpoint incomplete)                                          0            aq32z6wjx1s4h     0        76851             4          35716
                                                                                            0
                                                                                            0

       131 Disk file operations I/O                                         FileOperation   5            aq32z6wjx1s4h     0        76851             4          37632
                                                                            fileno          0
                                                                            filetype        2

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          4999
                                                                            blocks          1

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          10344
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          17409
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          22083
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          28549
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          34733
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          39217
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          45114
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          48836
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0            9             1          86832
                                                                            block#          52391
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4           5196
                                                                            block#          5196
                                                                            blocks          6

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4           8261
                                                                            block#          8261
                                                                            blocks          1

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4          11318
                                                                            block#          11318
                                                                            blocks          1

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          14489
                                                                            block#          14489
                                                                            blocks          56

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          17935
                                                                            block#          17935
                                                                            blocks          50

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          21195
                                                                            block#          21195
                                                                            blocks          20

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          25170
                                                                            block#          25170
                                                                            blocks          2

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          28453
                                                                            block#          28453
                                                                            blocks          34

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4          33067
                                                                            block#          33067
                                                                            blocks          1

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          36991
                                                                            block#          36991
                                                                            blocks          13

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          41616
                                                                            block#          41616
                                                                            blocks          21

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          44055
                                                                            block#          44055
                                                                            blocks          8

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4           2723
                                                                            block#          2723
                                                                            blocks          44

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          50056
                                                                            block#          50056
                                                                            blocks          9

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          53658
                                                                            block#          53658
                                                                            blocks          102

       131 db file scattered read                                           file#           4            fqcxb1n33642x     0        76851             4          56580
                                                                            block#          56580
                                                                            blocks          128

       131 db file sequential read                                          file#           4            fqcxb1n33642x     0        76851             4          60256
                                                                            block#          60256
                                                                            blocks          1

64 rows selected.

Elapsed: 00:00:00.40
SQL> @getsql_sqlid
Enter 1 for curr sql, 2 for hist sql,default 1:

Enter value for sqlid: fqcxb1n33642x

SQL_FULLTEXT
---------------------------------------------------------------------------------------------
select count(*) from big
Elapsed: 00:00:00.00
Elapsed: 00:00:00.00
SQL> @getobj_id
Enter value for dblink:
Enter value for obj_id: 76851

OWNER                OBJECT_NAME                    OBJECT_TYPE         CREATED             STATUS
-------------------- ------------------------------ ------------------- ------------------- -------
SCOTT                BIG                            TABLE               2014-11-20 15:56:23 VALID

1 row selected.

Elapsed: 00:00:00.01
SQL> @getobj_fb
Enter value for file_id: 4
Enter value for block_id: 60256

OWNER           SEGMENT_NAME         SEGMENT_TY
--------------- -------------------- ----------
SCOTT           BIG                  TABLE

1 row selected.

Elapsed: 00:00:00.37

[email protected]脚本--------------------

[email protected] 

@sid
set feedback off
drop table big;
create table big as select * from dba_objects;
insert into big select * from big;
/
/
/
/
/
commit;
select SUM(bytes) / 1024 / 1024  big_M  from dba_segments where segment_name = 'BIG';
select count(*) from big;
set feedback on

[email protected]_sid
col p_name for a15
col p_value for a15
select SESSION_ID,
       NAME,
       P1TEXT||chr(10)||P2TEXT||chr(10)||P3TEXT p_name,
       p1||chr(10)||p2||chr(10)||p3 p_value,
       sql_id,
       WAIT_TIME,
       CURRENT_OBJ#,
       CURRENT_FILE#,
       CURRENT_BLOCK#
  from v$active_session_history ash, v$event_name enm
 where ash.event# = enm.event#
   and SESSION_ID = &sid
 order by sample_time; 

----------------------------------------
--DBA_HIST_ACTIVE_SESS_HISTORY的监控:--
----------------------------------------

--查当前时间
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

--根据时间找到snap_id(8天内,1小时前),因为基表非常大,利用snap_id的索引才能快速查询
select distinct snap_id from dba_hist_snapshot b where to_date('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') between b.begin_interval_time and b.end_interval_time;

--top instance
select /*+parallel(a,8)*/instance_number,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 group by instance_number;

--top event
select /*+parallel(a,8)*/event,count(*) from dba_hist_active_sess_history a
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss')
and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss')
group by event
order by count(*) desc;

--top user
select /*+parallel(a,8)*/user_id,(select username from dba_users b where b.user_id=a.user_id) username,count(*) from dba_hist_active_sess_history a
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss')
and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss')
group by user_id
order by count(*) desc;

--top sql
select /*+parallel(a,8)*/sql_id,count(*) from dba_hist_active_sess_history a
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss')
and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss')
group by sql_id
order by count(*) desc;

--   select SQL_TEXT from dba_hist_sqltext where sql_id='49p4hfj6azw19';

--top program
select /*+parallel(a,8)*/program,count(*) from dba_hist_active_sess_history a
where a.snap_id=67421
and instance_number=2
and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss')
and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss')
group by program
order by count(*) desc;

时间: 2024-10-05 12:04:21

如何利用ash监控会话的相关文章

LR如何利用siteScope监控MySQL性能

本次实验,是在自己的电脑上使用APMServ5.2.6部署Discuz2.X论坛下,对该论坛的数据库MySQL5.1进行性能测试的,下面讲述LoadRunner在设计场景时,如何利用siteScope工具监控MySQL数据库性能: 一.在网上下载siteScope 我在网上搜了很久,发现siteScope软件的下载资源很少,毕竟它是收费的,想找个破解版,不过还是有的,哈哈...但是版本旧了点siteScope7.9.5 下载地址:http://download.csdn.net/detail/y

Nagios利用NSClient++监控Windows主机(4)

在Nagios的libexec下有check_nt这个插件,它就是用来检查windows机器的服务的.其功能类似于check_nrpe.不过还需要搭配另外一个软件NSClient++,它则类似于NRPE.我们需要下载NSClient合适的版本,然后安装在被监控的windows主机上. Overview of NRPE NSClient++的原理如下图: 可以看到NSClient与nrpe最大的区别就是: NRPE: 被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的.当监控主

利用Zabbix监控Web性能和可用性

怎么利用Zabbix监控web性能和可用性呢? 我们这边分为几个步骤:打开网站.登陆.登陆验证.退出,一共4个小step,看实例. 检测流程 1. 打开网站:如果http code为200,并且响应的html中包含Zabbix SIA表示打开成功(zabbix页面有这个标示) 2. 登陆后台:post用户名和密码到index.php,如果响应200,那表示post成功.并且通过正则表达式从响应的html中匹配sid,这个sid也就是一个宏变量,退出可以使用到 3. 验证登陆:打开首页,检索htm

Nagios利用NRPE监控Linux主机(3)

一.利用NRPE监控远程Linux的"本地信息" 上面已经对远程Linux 主机是否存活做了监控,而判断远程机器是否存活,我们可以使用ping 工具对其监测.还有一些远程主机服务,例如ftp.ssh.http,都是对外开放的服务,即使不用Nagios,我们也可以试的出来,随便找一台机器看能不能访问这些服务就行了.但是对于像磁盘容量,cpu负载这样的"本地信息",Nagios只能监测自己所在的主机,而对其他的机器则显得有点无能为力.毕竟没得到被控主机的适当权限是不可能

利用shell监控cpu、磁盘、内存使用率

利用shell监控cpu.磁盘.内存使用率,达到警报阈值发邮件进行通知 并配合任务计划,即可及时获取报警信息 #!/bin/bash ############################################## #Author: Liuzhengwei - [email protected] #QQ:1135960569 #Last modified: 2017-04-19 21:50 #Filename: jiankong.sh #Description:  #########

利用Zabbix监控Lync的实时在线人数

大家都知道windows性能监控一般依靠性能计数器, Lync实时在线人数统计就是SQL数据库实时连接数. 使用windows性能监视器对Lync的实时在线人数进行监控. 这个数值就是lync的实时在线人数 通过zabbix监控 为了方便zabbix监控我们需要找出这个性能参数值 我们将SQL服务器的性能计数参数都导出来 我们需要为SQL服务器新建一个监控项目 键值为: perf_counter[\SQLServer:User Settable(User counter 1)\Query] 再为

angular访问后台服务及监控会话超时的封装

angular访问后台服务及监控会话超时的封装 angular本身自带访问组件http和httpclient,组件本身都是异步模式访问.本文只列举了对http组件的封装同时也一同处理会话超时监控. 获取组件源码请入QQ群706224870,在群文件中下载. 入群验证消息codefc. 实现思路概述: 1.将请求入参和出参统一约定 2.封装方法将请求参数.数据处理方法.数据呈现方法.访问错误处理方法封装在一起,业务调用通过服务调用该封装方法, 同时把请求参数.数据处理方法.数据呈现方法.访问错误处

利用superlance监控supervisor运行状态

此文已由作者张家裕授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 最近开发问到supervisor管理下的进程重启了,有无办法做到主动通知,楼主最先想到的是supervisor自带的eventlistener,于是找到了下面的解决方法. supervisor与superlance简介 supervisor是一款非常实用的进程管理工具,可以方便的通过命令开启.关闭.重启等操作,而且它管理的进程一旦崩溃会自动重启.在KM上面已有多篇文章介绍supervisor的优势以及使用

利用pt-deadlock-logger监控死锁

Percona提供的percona-toolkit提供很多实用功能,这里着重介绍如何监控死锁. pt-deadlock-logger基本用法 Usage: pt-deadlock-logger [OPTIONS] DSN 解释:指定DSN死锁信息,它可以标准输出到屏幕也可以记入到表中或者日志文件,OPTIONS就是要加的参数了. 在这里做个模拟产生死锁的试验,例子如下: session1: mysql> create table lock1 (id int,name char(20),addre