使用SQL查询Zabbix所监控主机的磁盘空间使用率

简介:

本文主要描述使用自定义的SQL查询Zabbix所监控主机的磁盘使用率。虽然zabbix能单独监控每台主机的相关信息,但是缺乏对所有主机磁盘空间信息的直观展示,因此本人提供一个SQL语句完成此功能。


欢迎转载,请注明作者、出处。
作者:张正
blog:http://space.itpub.net/26355921 
QQ:176036317
如有疑问,欢迎联系。

Zabbix 2.0 
一共有109张表:
mysql> show tables;
+-----------------------+
| Tables_in_zabbix      |
+-----------------------+
| acknowledges          |
| actions               |
| alerts                |
| application_template  |
| applications          |
| auditlog              |
| auditlog_details      |
| autoreg_host          |
| conditions            |
| config                |
| dbversion             |
| dchecks               |
| dhosts                |
| drules                |
| dservices             |
| escalations           |
| events                |
| expressions           |
| functions             |
| globalmacro           |
| globalvars            |
| graph_discovery       |
| graph_theme           |
| graphs                |
| graphs_items          |
| group_discovery       |
| group_prototype       |
| groups                |
| history               |
| history_log           |
| history_str           |
| history_str_sync      |
| history_sync          |
| history_text          |
| history_uint          |
| history_uint_sync     |
| host_discovery        |
| host_inventory        |
| hostmacro             |
| hosts                 |
| hosts_groups          |
| hosts_templates       |
| housekeeper           |
| httpstep              |
| httpstepitem          |
| httptest              |
| httptestitem          |
| icon_map              |
| icon_mapping          |
| ids                   |
| images                |
| interface             |
| interface_discovery   |
| item_discovery        |
| items                 |
| items_applications    |
| maintenances          |
| maintenances_groups   |
| maintenances_hosts    |
| maintenances_windows  |
| mappings              |
| media                 |
| media_type            |
| node_cksum            |
| nodes                 |
| opcommand             |
| opcommand_grp         |
| opcommand_hst         |
| opconditions          |
| operations            |
| opgroup               |
| opmessage             |
| opmessage_grp         |
| opmessage_usr         |
| optemplate            |
| profiles              |
| proxy_autoreg_host    |
| proxy_dhistory        |
| proxy_history         |
| regexps               |
| rights                |
| screens               |
| screens_items         |
| scripts               |
| service_alarms        |
| services              |
| services_links        |
| services_times        |
| sessions              |
| slides                |
| slideshows            |
| sysmap_element_url    |
| sysmap_url            |
| sysmaps               |
| sysmaps_elements      |
| sysmaps_link_triggers |
| sysmaps_links         |
| timeperiods           |
| tmp3                  |
| trends                |
| trends_uint           |
| trigger_depends       |
| trigger_discovery     |
| triggers              |
| user_history          |
| users                 |
| users_groups          |
| usrgrp                |
| valuemaps             |
+-----------------------+
109 rows in set (0.00 sec)


select a1.host,
       a1.g_name,
       round((1 - a1.value / a2.value) * 100, 2) pct_used,
       round(a2.value / 1024 / 1024 / 1024, 2) "total_size(G)"
  from (select host, value, graphid, g_name
          from (select t1.itemid,
                       t1.i_name,
                       t1.g_name,
                       t1.host,
                       from_unixtime(h.clock),
                       h.value,
                       t1.graphid,
                       t1.type
                  from (select i.itemid,
                               i.name    i_name,
                               g.graphid,
                               g.name    g_name,
                               h.hostid,
                               h.host,
                               gi.type
                          from items i
                          join graphs_items gi
                            on i.itemid = gi.itemid
                          join graphs g
                            on gi.graphid = g.graphid
                          join hosts h
                            on i.hostid = h.hostid
                         where h.name like '192.168.%'
                           and g.name like 'Disk space usage %'
                           and g.name not like '%{#FSNAME}') t1,
                       history_uint h,
                       (select itemid, max(clock) clock
                          from history_uint
                         group by itemid) t2
                 where t1.itemid = h.itemid
                   and t1.itemid = t2.itemid
                   and h.clock = t2.clock) b1
         where type = 0) a1
  join (select host, value, graphid, g_name
          from (select t1.itemid,
                       t1.i_name,
                       t1.g_name,
                       t1.host,
                       from_unixtime(h.clock),
                       h.value,
                       t1.graphid,
                       t1.type
                  from (select i.itemid,
                               i.name    i_name,
                               g.graphid,
                               g.name    g_name,
                               h.hostid,
                               h.host,
                               gi.type
                          from items i
                          join graphs_items gi
                            on i.itemid = gi.itemid
                          join graphs g
                            on gi.graphid = g.graphid
                          join hosts h
                            on i.hostid = h.hostid
                         where h.name like '192.168.%'
                           and g.name like 'Disk space usage %'
                           and g.name not like '%{#FSNAME}') t1,
                       history_uint h,
                       (select itemid, max(clock) clock
                          from history_uint
                         group by itemid) t2
                 where t1.itemid = h.itemid
                   and t1.itemid = t2.itemid
                   and h.clock = t2.clock) b2
         where type = 2) a2
    on a1.host = a2.host
   and a1.graphid = a2.graphid
 order by 3;
+----------------+----------------------------------+----------+---------------+
| host           | g_name                           | pct_used | total_size(G) |
+----------------+----------------------------------+----------+---------------+
| 192.168.44.151 | Disk space usage /oacle          |     5.60 |        503.97 |
| 192.168.44.132 | Disk space usage /               |     7.31 |        200.81 |
| 192.168.44.135 | Disk space usage /               |     7.58 |        200.81 |
| 192.168.44.153 | Disk space usage /oot            |     8.08 |          0.19 |
| 192.168.44.53  | Disk space usage /oracle         |     8.58 |        362.70 |
| 192.168.44.250 | Disk space usage /               |     8.99 |        192.25 |
| 192.168.44.249 | Disk space usage /               |    10.01 |        192.25 |
| 192.168.241.6  | Disk space usage /oracle/u1      |    10.27 |        916.89 |
| 192.168.44.130 | Disk space usage /               |    10.33 |        200.81 |
| 192.168.44.134 | Disk space usage /oracle         |    10.84 |       3347.70 |
| 192.168.241.3  | Disk space usage /boot           |    11.26 |          0.19 |
| 192.168.241.2  | Disk space usage /boot           |    11.26 |          0.19 |
| 192.168.241.10 | Disk space usage /boot           |    11.26 |          0.19 |
| 192.168.44.55  | Disk space usage /boot           |    11.30 |          0.19 |
| 192.168.44.151 | Disk space usage /boot           |    11.30 |          0.19 |
| 192.168.241.6  | Disk space usage /boot           |    11.30 |          0.19 |
| 192.168.44.154 | Disk space usage /boot           |    11.30 |          0.19 |
| 192.168.44.53  | Disk space usage /boot           |    11.36 |          0.19 |
| 192.168.44.135 | Disk space usage /oracle         |    11.38 |       3347.70 |
| 192.168.44.52  | Disk space usage /boot           |    11.39 |          0.19 |
| 192.168.44.134 | Disk space usage /               |    11.39 |        200.81 |
| 192.168.44.54  | Disk space usage /boot           |    11.41 |          0.19 |
| 192.168.44.134 | Disk space usage /boot           |    11.45 |          0.19 |
| 192.168.44.132 | Disk space usage /boot           |    11.45 |          0.19 |
| 192.168.44.130 | Disk space usage /boot           |    11.45 |          0.19 |
| 192.168.44.131 | Disk space usage /boot           |    11.45 |          0.19 |
| 192.168.44.133 | Disk space usage /boot           |    11.45 |          0.19 |
| 192.168.44.135 | Disk space usage /boot           |    11.45 |          0.19 |
| 192.168.44.56  | Disk space usage /boot           |    11.85 |          0.19 |
| 192.168.44.102 | Disk space usage /boot           |    11.98 |          0.19 |
| 192.168.44.57  | Disk space usage /boot           |    12.12 |          0.19 |
| 192.168.44.131 | Disk space usage /               |    13.47 |        200.81 |
| 192.168.44.53  | Disk space usage /               |    14.86 |         28.38 |
| 192.168.44.132 | Disk space usage /oracle         |    17.42 |       3347.70 |
| 192.168.241.10 | Disk space usage /               |    17.73 |         28.38 |
| 192.168.44.131 | Disk space usage /oracle         |    18.01 |       3347.70 |
| 192.168.44.151 | Disk space usage /               |    18.07 |         28.38 |
| 192.168.241.3  | Disk space usage /               |    19.98 |         28.38 |
| 192.168.44.250 | Disk space usage /boot           |    20.93 |          0.19 |
| 192.168.44.249 | Disk space usage /boot           |    20.94 |          0.19 |
| 192.168.44.154 | Disk space usage /oracle         |    23.45 |        491.22 |
| 192.168.44.154 | Disk space usage /               |    23.51 |         28.38 |
| 192.168.44.55  | Disk space usage /               |    24.07 |         28.38 |
| 192.168.44.52  | Disk space usage /               |    24.62 |         28.38 |
| 192.168.241.6  | Disk space usage /               |    26.20 |         28.38 |
| 192.168.44.249 | Disk space usage /oracle         |    26.49 |       1761.90 |
| 192.168.44.153 | Disk space usage /               |    28.37 |         28.38 |
| 192.168.44.57  | Disk space usage /oracle         |    28.96 |        232.28 |
| 192.168.44.54  | Disk space usage /               |    29.40 |         28.38 |
| 192.168.44.56  | Disk space usage /               |    30.41 |         28.83 |
| 192.168.44.250 | Disk space usage /oracle         |    32.92 |       1761.90 |
| 192.168.241.2  | Disk space usage /               |    32.99 |         28.38 |
| 192.168.44.133 | Disk space usage /               |    39.06 |        200.81 |
| 192.168.44.54  | Disk space usage /oracle         |    43.43 |        486.09 |
| 192.168.241.3  | Disk space usage /oracle         |    54.91 |        250.75 |
| 192.168.44.102 | Disk space usage /               |    56.31 |        108.40 |
| 192.168.44.130 | Disk space usage /oracle         |    56.55 |       3347.70 |
| 192.168.44.52  | Disk space usage /oracle         |    57.65 |        626.13 |
| 192.168.241.6  | Disk space usage /oracle         |    61.26 |        503.97 |
| 192.168.44.153 | Disk space usage /oracle         |    62.64 |       1021.01 |
| 192.168.44.151 | Disk space usage /oracle         |    66.70 |        916.89 |
| 192.168.44.55  | Disk space usage /oracle         |    72.50 |        491.22 |
| 192.168.44.56  | Disk space usage /oracle         |    76.33 |        368.56 |
| 192.168.44.133 | Disk space usage /oracle         |    82.00 |       3347.70 |
| 192.168.44.102 | Disk space usage /oracle_oradata |    83.86 |         98.43 |
| 192.168.241.2  | Disk space usage /oracle         |    91.82 |        250.75 |
| 192.168.44.57  | Disk space usage /               |    94.83 |         28.83 |
| 192.168.241.10 | Disk space usage /oracle         |    96.30 |        250.75 |
+----------------+----------------------------------+----------+---------------+
68 rows in set (0.77 sec)
本文转自ITPUB博客84223932的博客,原文链接:使用SQL查询Zabbix所监控主机的磁盘空间使用率,如需转载请自行联系原博主。
相关文章
|
1月前
|
SQL 监控 关系型数据库
一键开启百倍加速!RDS DuckDB 黑科技让SQL查询速度最高提升200倍
RDS MySQL DuckDB分析实例结合事务处理与实时分析能力,显著提升SQL查询性能,最高可达200倍,兼容MySQL语法,无需额外学习成本。
|
1月前
|
SQL 存储 关系型数据库
MySQL体系结构详解:一条SQL查询的旅程
本文深入解析MySQL内部架构,从SQL查询的执行流程到性能优化技巧,涵盖连接建立、查询处理、执行阶段及存储引擎工作机制,帮助开发者理解MySQL运行原理并提升数据库性能。
|
29天前
|
SQL 监控 关系型数据库
SQL优化技巧:让MySQL查询快人一步
本文深入解析了MySQL查询优化的核心技巧,涵盖索引设计、查询重写、分页优化、批量操作、数据类型优化及性能监控等方面,帮助开发者显著提升数据库性能,解决慢查询问题,适用于高并发与大数据场景。
|
5月前
|
SQL 数据挖掘 数据库
第三篇:高级 SQL 查询与多表操作
本文深入讲解高级SQL查询技巧,涵盖多表JOIN操作、聚合函数、分组查询、子查询及视图索引等内容。适合已掌握基础SQL的学习者,通过实例解析INNER/LEFT/RIGHT/FULL JOIN用法,以及COUNT/SUM/AVG等聚合函数的应用。同时探讨复杂WHERE条件、子查询嵌套,并介绍视图简化查询与索引优化性能的方法。最后提供实践建议与学习资源,助你提升SQL技能以应对实际数据处理需求。
314 1
|
2月前
|
SQL XML Java
通过MyBatis的XML配置实现灵活的动态SQL查询
总结而言,通过MyBatis的XML配置实现灵活的动态SQL查询,可以让开发者以声明式的方式构建SQL语句,既保证了SQL操作的灵活性,又简化了代码的复杂度。这种方式可以显著提高数据库操作的效率和代码的可维护性。
157 18
|
7月前
|
SQL 运维 监控
SQL查询太慢?实战讲解YashanDB SQL调优思路
本文是Meetup第十期“调优实战专场”的第二篇技术文章,上一篇《高效查询秘诀,解码YashanDB优化器分组查询优化手段》中,我们揭秘了YashanDB分组查询优化秘诀,本文将通过一个案例,助你快速上手YashanDB慢日志功能,精准定位“慢SQL”后进行优化。
|
2月前
|
SQL 人工智能 数据库
【三桥君】如何正确使用SQL查询语句:避免常见错误?
三桥君解析了SQL查询中的常见错误和正确用法。AI产品专家三桥君通过三个典型案例:1)属性重复比较错误,应使用IN而非AND;2)WHERE子句中非法使用聚合函数的错误,应改用HAVING;3)正确的分组查询示例。三桥君还介绍了学生、课程和选课三个关系模式,并分析了SQL查询中的属性比较、聚合函数使用和分组查询等关键概念。最后通过实战练习帮助读者巩固知识,强调掌握这些技巧对提升数据库查询效率的重要性。
93 0
|
7月前
|
SQL 索引
【YashanDB知识库】字段加上索引后,SQL查询不到结果
【YashanDB知识库】字段加上索引后,SQL查询不到结果
|
3月前
|
SQL
SQL中如何删除指定查询出来的数据
SQL中如何删除指定查询出来的数据
|
5月前
|
SQL 关系型数据库 MySQL
凌晨2点报警群炸了:一条sql 执行200秒!搞定之后,我总结了一个慢SQL查询、定位分析解决的完整套路
凌晨2点报警群炸了:一条sql 执行200秒!搞定之后,我总结了一个慢SQL查询、定位分析解决的完整套路
凌晨2点报警群炸了:一条sql 执行200秒!搞定之后,我总结了一个慢SQL查询、定位分析解决的完整套路

热门文章

最新文章

推荐镜像

更多