1.導出被監控主機CPU使用率數據
1 select f.ip,b.*,ROUND(avg(t.value_avg),2) 'avg_value' from 2 trends t,interface f, 3 ( 4 select a.name as 'groupname',h.host,i.hostid,i.itemid,i.key_ from items i, 5 ( 6 SELECT 7 g.groupid 'groupid', 8 g.NAME 'name', 9 hg.hostid 'hostid' 10 FROM 11 groups g,hosts_groups hg 12 WHERE 13 g.groupid=hg.groupid 14 ) a,hosts h 15 where 16 i.hostid=a.hostid 17 and 18 h.hostid=a.hostid 19 ) b 20 where 21 t.itemid = b.itemid 22 and 23 f.hostid = b.hostid 24 and 25 b.groupname = 'Hostgroup_name' 26 and 27 b.key_ ='system.cpu.util[,system]' 28 and 29 t.clock > UNIX_TIMESTAMP('2017-11-01 00:00:00') 30 and 31 t.clock < UNIX_TIMESTAMP('2017-11-30 00:00:00') 32 group by t.itemid order by avg_value desc;
2.導出告警事件
1 SELECT 2 e.eventid '事件ID', 3 ( SELECT ( SELECT NAME FROM groups WHERE groupid = hg.groupid ) FROM hosts_groups hg WHERE hostid = h.hostid LIMIT 1 ) '分組', 4 h.HOST '主機', 5 REPLACE ( t.description, '{HOST.NAME}', h.HOST ) '告警內容', 6 FROM_UNIXTIME( e.clock ) '時間', 7 CASE 8 t.priority 9 WHEN 0 THEN 10 "not classified" 11 WHEN 1 THEN 12 "information" 13 WHEN 2 THEN 14 "warning" 15 WHEN 3 THEN 16 "average" 17 WHEN 4 THEN 18 "high" 19 WHEN 5 THEN 20 "disaster" 21 END AS "事件級別", 22 CASE 23 e. 24 VALUE 25 26 WHEN 1 THEN 27 "problem" 28 WHEN 0 THEN 29 "OK" 30 END AS "狀態" 31 FROM 32 events e, 33 functions f, 34 items i, 35 hosts h, 36 triggers t 37 WHERE 38 e.objectid = f.triggerid 39 AND f.itemid = i.itemid 40 AND t.triggerid = f.triggerid 41 AND f.itemid = i.itemid 42 AND i.hostid = h.hostid 43 AND e.object = 0 44 AND e.source = 0 45 AND e.clock > UNIX_TIMESTAMP( '2018-12-01 00:00:00' ) 46 AND e.clock < UNIX_TIMESTAMP( '2019-01-14 00:00:00' ) 47 ORDER BY 48 eventid DESC
3.導出網絡接口流量趨勢數據
1 select FROM_UNIXTIME(clock,'%Y年%m月%d日') date,t.value_max 'max_transmit',t.value_avg 'avg_transmit', 2 t.value_min 'min_transmit' from trends_uint t, 3 (select i.itemid from items i,(select h.hostid from 4 hosts h where h.name="FG1000D")b where b.hostid=i.hostid 5 and i.status = 0 and 6 i.name = 'Outgoing traffic on interface WAN-1514') oh 7 where t.itemid = oh.itemid and t.clock > UNIX_TIMESTAMP("2018-09-01 00:00:00") 8 and t.clock < UNIX_TIMESTAMP("2018-10-01 00:00:00") 9 group by from_unixTime(clock,'%Y-%m-%d')