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';