通过shell脚本监控日志切换频率

简介: 在数据库遇到性能问题的时候,可能从io,cpu等角度能够下手找到性能瓶颈,日志的切换也是影响性能的一个因素,如果日志切换台频繁,等待时间就会在日志相关的事件上,从数据库的角度来说,肯定是io的瓶颈。
在数据库遇到性能问题的时候,可能从io,cpu等角度能够下手找到性能瓶颈,日志的切换也是影响性能的一个因素,如果日志切换台频繁,等待时间就会在日志相关的事件上,从数据库的角度来说,肯定是io的瓶颈。
可以通过如下的shell脚本来得到一个简单的报告。



脚本如下:
sqlplus -s $DB_CONN_STR@$SH_DB_SID<<EOF


set linesize    150
set pages       100
set feedback    off
set verify      off


col dbname      new_value dbname
col time_stamp  new_value time_stamp
col timestamp_np        noprint
col year_np             noprint
col month_np            noprint
col mon                 for a3
col day                 for a2


ttitle off
SELECT name dbname, substr(to_char(sysdate,'YYYY-Mon-DD HH24:MI:SS'),1,20)
       time_stamp
FROM v\$database
/


col bytes format 9,999,999,999,999
col member format a60


select group#,thread#,sequence#,members,bytes/1024/1024 size_MB,archived,status
from v\$log order by 1,2;


ttitle left "Redo Switch times per hour" center "&dbname" right "&time_stamp" 
set term on
col tps00 for 999 head "00"
col tps01 for 999 head "01"
col tps02 for 999 head "02"
col tps03 for 999 head "03"
col tps04 for 999 head "04"
col tps05 for 999 head "05"
col tps06 for 999 head "06"
col tps07 for 999 head "07"
col tps08 for 999 head "08"
col tps09 for 999 head "09"
col tps10 for 999 head "10"
col tps11 for 999 head "11"
col tps12 for 999 head "12"
col tps13 for 999 head "13"
col tps14 for 999 head "14"
col tps15 for 999 head "15"
col tps16 for 999 head "16"
col tps17 for 999 head "17"
col tps18 for 999 head "18"
col tps19 for 999 head "19"
col tps20 for 999 head "20"
col tps21 for 999 head "21"
col tps22 for 999 head "22"
col tps23 for 999 head "23"


SELECT *
FROM
( SELECT substr(year_np,1,8)  timestamp_np,
       substr(year_np,5,2) Mon, substr(year_np,7,2) Day,
       sum(decode(substr(year_np,9,2),'00',cnt,0))   tps00,
       sum(decode(substr(year_np,9,2),'01',cnt,0))   tps01,
       sum(decode(substr(year_np,9,2),'02',cnt,0))   tps02,
       sum(decode(substr(year_np,9,2),'03',cnt,0))   tps03,
       sum(decode(substr(year_np,9,2),'04',cnt,0))   tps04,
       sum(decode(substr(year_np,9,2),'05',cnt,0))   tps05,
       sum(decode(substr(year_np,9,2),'06',cnt,0))   tps06,
       sum(decode(substr(year_np,9,2),'07',cnt,0))   tps07,
       sum(decode(substr(year_np,9,2),'08',cnt,0))   tps08,
       sum(decode(substr(year_np,9,2),'09',cnt,0))   tps09,
       sum(decode(substr(year_np,9,2),'10',cnt,0))   tps10,
       sum(decode(substr(year_np,9,2),'11',cnt,0))   tps11,
       sum(decode(substr(year_np,9,2),'12',cnt,0))   tps12,
       sum(decode(substr(year_np,9,2),'13',cnt,0))   tps13,
       sum(decode(substr(year_np,9,2),'14',cnt,0))   tps14,
       sum(decode(substr(year_np,9,2),'15',cnt,0))   tps15,
       sum(decode(substr(year_np,9,2),'16',cnt,0))   tps16,
       sum(decode(substr(year_np,9,2),'17',cnt,0))   tps17,
       sum(decode(substr(year_np,9,2),'18',cnt,0))   tps18,
       sum(decode(substr(year_np,9,2),'19',cnt,0))   tps19,
       sum(decode(substr(year_np,9,2),'20',cnt,0))   tps20,
       sum(decode(substr(year_np,9,3),'21',cnt,0))   tps21,
       sum(decode(substr(year_np,9,3),'22',cnt,0))   tps22,
       sum(decode(substr(year_np,9,2),'23',cnt,0))   tps23
  FROM (SELECT to_char(first_time,'YYYYMMDDHH24') year_np,count(*) cnt
        FROM v\$log_history where first_time>sysdate -15
        GROUP BY to_char(first_time,'YYYYMMDDHH24')
       )      
  GROUP BY substr(year_np,1,8), substr(year_np,5,2), substr(year_np,7,2)
)
ORDER BY timestamp_np
/
<<EOF
exit;

相关实践学习
通过日志服务实现云资源OSS的安全审计
本实验介绍如何通过日志服务实现云资源OSS的安全审计。
目录
相关文章
|
4月前
|
Prometheus 监控 Cloud Native
基于docker搭建监控系统&日志收集
Prometheus 是一款由 SoundCloud 开发的开源监控报警系统及时序数据库(TSDB),支持多维数据模型和灵活查询语言,适用于大规模集群监控。它通过 HTTP 拉取数据,支持服务发现、多种图表展示(如 Grafana),并可结合 Loki 实现日志聚合。本文介绍其架构、部署及与 Docker 集成的监控方案。
454 122
基于docker搭建监控系统&日志收集
|
4月前
|
Prometheus 监控 Java
日志收集和Spring 微服务监控的最佳实践
在微服务架构中,日志记录与监控对系统稳定性、问题排查和性能优化至关重要。本文介绍了在 Spring 微服务中实现高效日志记录与监控的最佳实践,涵盖日志级别选择、结构化日志、集中记录、服务ID跟踪、上下文信息添加、日志轮转,以及使用 Spring Boot Actuator、Micrometer、Prometheus、Grafana、ELK 堆栈等工具进行监控与可视化。通过这些方法,可提升系统的可观测性与运维效率。
453 1
日志收集和Spring 微服务监控的最佳实践
|
4月前
|
存储 缓存 监控
用 C++ 红黑树给公司电脑监控软件的日志快速排序的方法
本文介绍基于C++红黑树算法实现公司监控电脑软件的日志高效管理,利用其自平衡特性提升日志排序、检索与动态更新效率,并结合实际场景提出优化方向,增强系统性能与稳定性。
157 4
|
9月前
|
监控 测试技术 Go
告别传统Log追踪!GOAT如何用HTTP接口重塑代码监控
本文介绍了GOAT(Golang Application Tracing)工具的使用方法,通过一个Echo问答服务实例,详细展示了代码埋点与追踪技术的应用。内容涵盖初始化配置、自动埋点、手动调整埋点、数据监控及清理埋点等核心功能。GOAT适用于灰度发布、功能验证、性能分析、Bug排查和代码重构等场景,助力Go项目质量保障与平稳发布。工具以轻量高效的特点,为开发团队提供数据支持,优化决策流程。
590 89
|
9月前
|
消息中间件 运维 监控
智能运维,由你定义:SAE自定义日志与监控解决方案
通过引入 Sidecar 容器的技术,SAE 为用户提供了更强大的自定义日志与监控解决方案,帮助用户轻松实现日志采集、监控指标收集等功能。未来,SAE 将会支持 istio 多租场景,帮助用户更高效地部署和管理服务网格。
592 52
|
Java Shell
「sh脚步模版自取」测试线排查的三个脚本:启动、停止、重启、日志保存
「sh脚步模版自取」测试线排查的三个脚本:启动、停止、重启、日志保存
219 1
|
10月前
|
数据采集 运维 监控
数据采集监控与告警:错误重试、日志分析与自动化运维
本文探讨了数据采集技术从“简单采集”到自动化运维的演进。传统方式因反爬策略和网络波动常导致数据丢失,而引入错误重试、日志分析与自动化告警机制可显著提升系统稳定性与时效性。正方强调健全监控体系的重要性,反方则担忧复杂化带来的成本与安全风险。未来,结合AI与大数据技术,数据采集将向智能化、全自动方向发展,实现动态调整与智能识别反爬策略,降低人工干预需求。附带的Python示例展示了如何通过代理IP、重试策略及日志记录实现高效的数据采集程序。
485 7
数据采集监控与告警:错误重试、日志分析与自动化运维
|
10月前
|
存储 监控 算法
基于 PHP 语言的滑动窗口频率统计算法在公司局域网监控电脑日志分析中的应用研究
在当代企业网络架构中,公司局域网监控电脑系统需实时处理海量终端设备产生的连接日志。每台设备平均每分钟生成 3 至 5 条网络请求记录,这对监控系统的数据处理能力提出了极高要求。传统关系型数据库在应对这种高频写入场景时,性能往往难以令人满意。故而,引入特定的内存数据结构与优化算法成为必然选择。
276 3
|
10月前
|
消息中间件 运维 监控
智能运维,由你定义:SAE自定义日志与监控解决方案
SAE(Serverless应用引擎)是阿里云推出的全托管PaaS平台,致力于简化微服务应用开发与管理。为满足用户对可观测性和运维能力的更高需求,SAE引入Sidecar容器技术,实现日志采集、监控指标收集等功能扩展,且无需修改主应用代码。通过共享资源模式和独立资源模式,SAE平衡了资源灵活性与隔离性。同时,提供全链路运维能力,确保应用稳定性。未来,SAE将持续优化,支持更多场景,助力用户高效用云。
|
10月前
|
运维 监控 虚拟化
除了实时性能监控,Hyper-V还支持日志记录和警报功能你知道吗?
Hyper-V不仅支持实时性能监控,还具备强大的日志记录和警报功能。通过事件查看器可访问详细的日志文件,涵盖虚拟机管理、配置及Hypervisor事件,帮助故障排查和性能分析。警报功能支持预定义和自定义规则,可通过多种方式通知管理员,确保及时响应问题,保障虚拟化环境的稳定运行。