zabbix mysql数据库 查询数据sql

zabbix mysql数据库 查询数据sql

hosts --存储被监控的机器的信息
items --items表是zabbix核心表之一,记录item的所有设置
hstgrp --机器所属组表
history --性能数据保存表
history_uint --性能数据保存表

SELECT 
  HOST,
  hosts.name AS host_name,
  items.name AS item_name,
  items.itemid,
  hstgrp.name AS group_name,
  history.value AS VALUE 
FROM
  `hosts` 
  JOIN hosts_groups 
    ON hosts_groups.hostid = hosts.hostid 
  JOIN hstgrp 
    ON hosts_groups.groupid = hstgrp.groupid 
  JOIN items 
    ON items.hostid = hosts.hostid 
  JOIN history
    ON h1.itemid = items.itemid 
WHERE hosts.host = "10.203.4.23" 
  AND h1.clock > UNIX_TIMESTAMP(NOW()) - 3 * 60 
UNION
SELECT 
  HOST,
  hosts.name AS host_name,
  items.name AS item_name,
  items.itemid,
  hstgrp.name AS group_name,
  history_uint.value 
FROM
  `hosts`
  JOIN hosts_groups 
    ON hosts_groups.hostid = hosts.hostid 
  JOIN hstgrp 
    ON hosts_groups.groupid = hstgrp.groupid 
  JOIN items 
    ON items.hostid = hosts.hostid 
  JOIN history_uint
    ON h2.itemid = items.itemid 
WHERE hosts.host = "10.203.4.23" 
  AND h2.clock > UNIX_TIMESTAMP(NOW()) - 3 * 60 
ORDER BY item_name

Copyright: 采用 知识共享署名4.0 国际许可协议进行许可

Links: https://www.hesc.info/archives/20200708111002

Buy me a cup of coffee ☕.