select FROM_UNIXTIME(clock) as DateTime, value, round(value/1024,2) as Traffic_in
from history_uint
where itemid="28770"
;
select * from hosts where host='192.168.58.129';
select * from items where hostid='10270';
create or replace view v_item_history_uint
(host_id, item_name, item_id, item_key, status, data_time, value)
AS
select t1.hostid as host_id, t1.itemid as item_id , t1.name as item_name, t1.key_ as item_key, t1.`status`, FROM_UNIXTIME(clock) as data_time, t2.`value`
from items t1, history_uint t2
where t1.itemid = t2.itemid
;
create or replace view v_item_history
(host_id, item_name, item_id, item_key, status, data_time, value)
AS
select t1.hostid as host_id, t1.itemid as item_id , t1.name as item_name, t1.key_ as item_key, t1.`status`, FROM_UNIXTIME(clock) as data_time, t2.`value`
from items t1, history t2
where t1.itemid = t2.itemid
;
select * from v_item_history_uint where item_key='net.if.in[ens32]' order by data_time desc;
select * from v_item_history_uint where item_key='vm.memory.size[total]' order by data_time desc;
create or replace view v_host_info_tmp
(host_id, host_name, host_ip, status,cpu_used_pct, ava_mem, total_mem, net_in, net_out)
as
select t1.hostid as host_id, t1.`host` as host_name, t2.ip as host_ip, t1.`status`,
(select round(value*100,2) from v_item_history v1 where v1.host_id = t1.hostid and v1.item_key='system.cpu.load[percpu,avg1]' order by data_time desc limit 0,1) as cpu_used_pct,
(select value from v_item_history_uint v1 where v1.host_id = t1.hostid and v1.item_key='vm.memory.size[available]' order by data_time desc limit 0,1) as ava_mem,
(select value from v_item_history_uint v1 where v1.host_id = t1.hostid and v1.item_key='vm.memory.size[total]' order by data_time desc limit 0,1) as total_mem,
(select round(value/1024,2) from v_item_history_uint v1 where v1.host_id = t1.hostid and v1.item_key='net.if.in[ens32]' order by data_time desc limit 0,1) as net_in,
(select round(value/1024,2) from v_item_history_uint v1 where v1.host_id = t1.hostid and v1.item_key='net.if.out[ens32]' order by data_time desc limit 0,1) as net_out
from hosts t1, interface t2
where t1.hostid = t2.hostid
;
create or replace view v_host_info
(host_id, host_name, host_ip, status, cpu_used_pct, memory_used_pct, net_in, net_out)
as
select host_id, host_name, host_ip, status, cpu_used_pct, round(1-ava_mem/total_mem,2) as memory_used_pct, net_in, net_out
from v_host_info_tmp;
select * from items;
SELECT
a.ip,
b.ip
FROM
`interface` a
LEFT JOIN (
SELECT DISTINCT
ip
FROM
`hosts_templates` AS h
JOIN `interface` AS i ON i.hostid = h.hostid
WHERE
h.templateid = 10465
) AS b ON a.ip = b.ip
ORDER BY
b.ip DESC;