sql嵌入html格式显示报表(r6笔记第34天)
在使用监控系统报警的时候,如果显示的报警信息为纯粹的文本,会枯燥很多,而且看起来很不清晰。 比如我们要监控表空间的使用情况,输出列有表空间名,状态,区管理方式,总共的空间,使用的空间,剩余的空间等。 如果显示成下面的形式,尽管在输出中尝试使结果看起来清晰一些,但是还是事与愿违。
showtsps:Tablespace: TEST_INDEX-->Status: OLN-->Ext_MGR: LOCAL-->Total: 301843.875MB-->Free: 30945.25MB-->Used: 270898.625MB-->PFree: 10%--> <br />Tablespace: TEST_DATA-->Status: OLN-->Ext_MGR: LOCAL-->Total: 7960MB-->Free: 422.5MB-->Used: 7537.5MB-->PFree: 5%--> <br />Tablespace: ADVER_INDEX-->Status: OLN-->Ext_MGR: LOCAL-->Total: 550MB-->Free: 55.25MB-->Used: 494.75MB-->PFree: 10%--> <br />Tablespace: showtsps:Tablespace: ACCSTAT_INDEX-->Status: OLN-->Ext_MGR: LOCAL-->Total: 301843.875MB-->Free: 30945.25MB-->Used: 270898.625MB-->PFree: 10%-->
我们来看看改进后的效果,这样可能就更清晰一些了,当然这个只是个改进的方向而已。
Tablespace: TEST_INDEX |
OLN |
LOCAL |
Total: 301843M |
Free: 30937M |
Used: 270906M |
PFree: 10% |
---|
Tablespace: TEST_DATA |
OLN |
LOCAL |
Total: 7960MB |
Free: 422MB |
Used: 7537MB |
PFree: 5% |
---|
Tablespace: TEST_INDEX |
OLN |
LOCAL |
Total: 550MB |
Free: 55MB |
Used: 494MB |
PFree: 10% |
---|
Tablespace: TEST_DATA2 |
OLN |
LOCAL |
Total: 45167MB |
Free: 2302MB |
Used: 42865MB |
PFree: 5% |
---|
Tablespace: TEST_INDEX2 |
OLN |
LOCAL |
Total: 13990MB |
Free: 688MB |
Used: 13301MB |
PFree: 5% |
---|
对于这种情况,大多数情况下就是监控指标能够实现,但是展现出来的效果不明显,这样很可能就会使得这个功能没有什么实用价值。 尽管sqlplus本身提供了 markup html on的选项,但是在orabbix中还是使用受限,所以只能另辟蹊径。 检查表空间的脚本如下,只是一个参考例子。
select
d.tablespace_name,
decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status) status,
d.extent_management,
decode(d.allocation_type,
'USER','',
d.allocation_type) allocation_type,
(case
when initial_extent < 1048576
then lpad(round(initial_extent/1024,0),3)||'K'
else lpad(round(initial_extent/1024/1024,0),3)||'M'
end) Ext_Size,
NVL (a.bytes / 1024 / 1024, 0) MB,
NVL (f.bytes / 1024 / 1024, 0) free,
(NVL (a.bytes / 1024 / 1024, 0) - NVL (f.bytes / 1024 / 1024, 0)) used,
NVL (l.large / 1024 / 1024, 0) largest,
d.MAX_EXTENTS ,
lpad(round((f.bytes/a.bytes)*100,0),3) pfree,
(case when round(f.bytes/a.bytes*100,0) >= 20 then ' ' else '*' end) alrt
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) f,
(SELECT tablespace_name, MAX(bytes) large
FROM dba_free_space
GROUP BY tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND NOT (d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')
UNION ALL
select
d.tablespace_name,
decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status) status,
d.extent_management,
decode(d.allocation_type,
'UNIFORM','U',
'SYSTEM','A',
'USER','',
d.allocation_type) allocation_type,
(case
when initial_extent < 1048576
then lpad(round(initial_extent/1024,0),3)||'K'
else lpad(round(initial_extent/1024/1024,0),3)||'M'
end) Ext_Size,
NVL (a.bytes / 1024 / 1024, 0) MB,
(NVL (a.bytes / 1024 / 1024, 0) - NVL (t.bytes / 1024 / 1024, 0)) free,
NVL (t.bytes / 1024 / 1024, 0) used,
NVL (l.large / 1024 / 1024, 0) largest,
d.MAX_EXTENTS ,
lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3) pfree,
(case when nvl(round(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,0),100) >= 20 then ' ' else '*' end) alrt
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_temp_files
GROUP BY tablespace_name order by tablespace_name) a,
(SELECT tablespace_name, SUM(bytes_used ) bytes
FROM v$temp_extent_pool
GROUP BY tablespace_name) t,
(SELECT tablespace_name, MAX(bytes_cached) large
FROM v$temp_extent_pool
GROUP BY tablespace_name order by tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND d.extent_management LIKE 'LOCAL'
AND d.contents LIKE 'TEMPORARY'
ORDER by 1
可以看到脚本还是相对比较复杂的,这么复杂的功能都能实现,但是展现的效果却打了折扣,导致了功能上的丰富和显示效果不太相符。 这个时候还是得考虑嵌入点html代码,自己也着实温习了一下以前html的东西。 在经过了大量的测试之后,总算做出了一些改进。 最终需要sql查出来的结果需要时下面的格式:
<table border='1' width='90%' align='center' ><tr><td width="40%">Tablespace: TEST_TABLE
SPACE_DATA</td>
<td width="10%">Status: OLN</td> <td width="10%">Ext_MGR: LOCAL</td>
<td width="10%">Total: 29031.875MB</td>
<td width="10%">Free: 5.3125MB</td>
<td width="10%">Used: 29026.5625MB</td>
<td width="10%">PFree: 0%</td></tr></table>
<table border='1' width='90%' align='center' ><tr><td width="40%">Tablespace: TEST_TABLE2
SPACE_INDEX</td>
<td width="10%">Status: OLN</td> <td width="10%">Ext_MGR: LOCAL</td>
<td width="10%">Total: 12876.8125MB</td>
<td width="10%">Free: 10.6875MB</td>
<td width="10%">Used: 12866.125MB</td>
<td width="10%">PFree: 0%</td></tr></table>
实现的sql的代码如下,这个时候已经不是单纯的脚本了,我叫它代码了。:)
select
'<table border='||chr(34)||'1'||chr(34)||' width='||chr(34)||'90%'||chr(34)||' align='||chr(34)||'center'||chr(34)||'<tr>'||
'<td width='||chr(34)||'40%'||chr(34)||'>Tablespace: '||d.tablespace_name||'</td>',
'<td width='||chr(34)||'10%'||chr(34)||'>Status: '||decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status)||'</td>' status,
'<td width='||chr(34)||'10%'||chr(34)||'>Ext_MGR: '||d.extent_management||'</td>',
'<td width='||chr(34)||'10%'||chr(34)||'>Total: '||trunc(NVL (a.bytes / 1024 / 1024, 0))||'MB</td>' MB,
'<td width='||chr(34)||'10%'||chr(34)||'>Free: '||trunc(NVL (f.bytes / 1024 / 1024, 0))||'MB</td>' free,
'<td width='||chr(34)||'10%'||chr(34)||'>Used: '||trunc((NVL (a.bytes / 1024 / 1024, 0) - NVL (f.bytes / 1024 / 1024, 0)))||'MB</td>' used,
'<td width='||chr(34)||'10%'||chr(34)||'>PFree: '||lpad(round((f.bytes/a.bytes)*100,0),3)||'%</td></tr></table>' pfree
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) f,
(SELECT tablespace_name, MAX(bytes) large
FROM dba_free_space
GROUP BY tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND NOT (d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')
AND lpad(round((f.bytes/a.bytes)*100,0),3)<=10
UNION ALL
select
'<table border='||chr(34)||'1'||chr(34)||' width='||chr(34)||'90%'||chr(34)||' align='||chr(34)||'center'||chr(34)||'<tr>'||
'<td width='||chr(34)||'40%'||chr(34)||'>Tablespace:'||d.tablespace_name||'</td>',
'<td>Status: '||decode(d.status,
'ONLINE', 'OLN',
'READ ONLY', 'R/O',
d.status)||'</td>' status,
'<td width='||chr(34)||'10%'||chr(34)||'>Ext_MGR: '||d.extent_management||'</td>',
'<td width='||chr(34)||'10%'||chr(34)||'>Total: '||trunc(NVL (a.bytes / 1024 / 1024, 0))||'MB</td>' MB,
'<td width='||chr(34)||'10%'||chr(34)||'>Free: '||trunc((NVL (a.bytes / 1024 / 1024, 0) - NVL (t.bytes / 1024 / 1024, 0)))||'MB</td>' free,
'<td width='||chr(34)||'10%'||chr(34)||'>Used: '||trunc(NVL (t.bytes / 1024 / 1024, 0))||'MB</td>' used,
'<td width='||chr(34)||'10%'||chr(34)||'>PFree: '||lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3)||'%</td></tr></table>' pfree
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_temp_files
GROUP BY tablespace_name order by tablespace_name) a,
(SELECT tablespace_name, SUM(bytes_used ) bytes
FROM v$temp_extent_pool
GROUP BY tablespace_name) t,
(SELECT tablespace_name, MAX(bytes_cached) large
FROM v$temp_extent_pool
GROUP BY tablespace_name order by tablespace_name) l
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = t.tablespace_name(+)
AND d.tablespace_name = l.tablespace_name(+)
AND d.extent_management LIKE 'LOCAL'
AND d.contents LIKE 'TEMPORARY'
AND lpad(round(nvl(((a.bytes-t.bytes)/NVL(a.bytes,0))*100,100),0),3) <= 10
ORDER by 1;
可以在适当的时候来尝试使用一下,效果虽然还是丑了些,不过已经做过格式化了。 改进的方向其实还是很多。比如嵌入颜色,格式布局等等都是需要改进的方向。
- HTML 教程
- HTML 简介
- html div 标签介绍
- html span 标签介绍
- html a 超链接标签
- HTML Br换行标签介绍
- HTML P段落标签介绍
- HTML br与p标签区别
- Html H 标题标签
- html px em pt长度单位
- HTML form 标签
- HTML radio 单选框
- HTML B 加粗标签
- HTML strong加粗粗体标签
- HTML em 强调标签
- HTML i 斜体标签
- HTML u下划线标签
- HTML s 删除线标签
- Html img 图片标签
- Html上标注sup与下标注sub标签
- HTML nobr 禁止换行标签
- HTML hr 水平线标签
- HTML label 标签
- HTML input 标签
- HTML textarea 标签
- HTML select下拉列表标签
- HTML checkbox 多选框
- HTML font color 标签
- HTML iframe 框架标签
- HTML Table 表格
- HTML dl dt dd 标签
- HTML ol li有序列表标签
- HTML ul li 无序列表标签
- HTML 注释
- CSS 教程
- CSS 简介
- CSS 语法
- CSS Id 和 Class选择器
- CSS 样式的创建
- CSS background 背景介绍
- CSS 文本样式
- CSS font 字体
- CSS A 链接
- CSS ul ol列表样式
- CSS TABLE 样式
- CSS 框模型
- CSS border 边框
- CSS Outlines 轮廓
- CSS 外边距 Margin
- CSS Padding 内边距
- CSS 分组和嵌套选择器
- CSS 尺寸 (Dimension)
- CSS Display 属性
- CSS Position 定位
- CSS Float 浮动
- CSS 水平对齐(Horizontal Align)
- CSS 组合选择符
- CSS 伪类
- CSS 伪元素
- CSS 导航栏
- CSS 下拉菜单
- CSS 图片廊
- CSS 图像透明/不透明
- CSS sprite 图像拼合技术
- CSS 媒体类型
- CSS 属性选择器
- CSS 实例
- 小白学PyTorch | 10 pytorch常见运算详解
- vuex的基础知识点
- 小白学PyTorch | 11 MobileNet详解及PyTorch实现
- 小白学PyTorch | 12 SENet详解及PyTorch实现
- 重拾前端技能为你的职业前程保驾护航
- input切换显示与隐藏,歘~
- 小白学PyTorch | 13 EfficientNet详解及PyTorch实现
- Java 比较两个字符串内容是否相等
- 前端模块化发展史
- 前端性能优化
- 突击并发编程JUC系列-原子更新AtomicLong
- Windows下指定的服务已经标记为删除”
- 《剑指offer》第29天:m x n 网格的最小路径和
- 环保 HJ212协议解析
- Flink源码解读系列 | 任务提交流程