1、-- 主机,监控项,监控状态,触发器
SELECT
a.ip,
b. HOST,
b.`status`,
b.flags,
b.`name`,
c.`name`
FROM
interface a
LEFT JOIN HOSTS b ON a.hostid = b.hostid
LEFT JOIN items c on a.hostid = c.hostid;
2、默认情况下,监控项采集的数据会存储在历史表中,这些采集的数据如果超过1000,zabbix会将其除以1000存储在数据库中 如果单位是B(byte)或者bps(bytes per second),那么这些采集的数据会除以1024然后存储在数据库中,zabbix的时间已unix时间存储
-- unix时间转换
DATE_FORMAT(FROM_UNIXTIME(clock),'%Y-%m-%d')
-- 历史监控项数据,历史表有5张,分别对应5个类型的数据
SELECT
a.host,
a.name,
b.key_,
FROM_UNIXTIME(c.clock,'%Y-%m-%d %H:%i:%s'),
c.value
FROM
hosts a
LEFT JOIN items b ON a.hostid = b.hostid
LEFT JOIN history c on b.itemid = c.itemid where a.hostid = '10424';
3、获取一个机器某个键值一定时间范围的数值
select a.host,b.key_,c.clock,FROM_UNIXTIME(c.clock,'%Y-%m-%d %H:%i:%s'),c.value from hosts a left join items b ON a.hostid = b.hostid LEFT JOIN history c on b.itemid = c.itemid where a.hostid = '11513' and b.key_ = 'system.cpu.util[,idle,avg1]' and c.clock > '1574179200' and c.clock < '1574265599';