【发布时间】:2019-08-22 08:43:48
【问题描述】:
我正在编写一个 API 来返回系统信息数据。我正在使用 get_status() 它在仪表板具有如下数据时返回空数据。
系统信息
参数值详情 Zabbix 服务器正在运行 是 127.0.0.1:10051 主机数量(启用/禁用/模板)109 16 / 5 / 88 项目数(启用/禁用/不支持)621 328 / 287 / 6 触发器数量(启用/禁用 [问题/正常])333 197 / 136 [36 / 161] 用户数(在线) 17 1 所需的服务器性能,每秒新值 37.11
我使用 SQL 查询从数据库中选择数据。但是项目数量、触发器数量、用户数量和服务器性能的数据与仪表板无关。我的代码如下: // 项目
select count(itemid) as numberOfItems from items; => 2630
select count(itemid) as numberOfItems from items JOIN hosts on hosts.hostid = items.hostid where hosts.`status`=0; => 427
select count(itemid) as numberOfItemEnabled from items JOIN hosts on hosts.hostid = items.hostid where items.STATUS = 0 AND hosts.`status`=0; => 427
select count(itemid) as numberOfItemDisabled from items JOIN hosts on hosts.hostid = items.hostid where items.STATUS = 1 AND hosts.`status`=0; => 0
select count(itemid) as numberOfItemNotSupported from items JOIN hosts on hosts.hostid = items.hostid where items.state = 1 AND hosts.`status`=0; => 6
我的结果: 项目数(启用/禁用/不支持)427 427/ 0/ 6
网络仪表板: 项目数(启用/禁用/不支持)621 328 / 287 / 6
// 触发
select count(triggerid) as numberOfTrigger from triggers; => 1329
select count(triggerid) as numberOfTriggerEnabled from triggers where status = 0; => 1328
select count(triggerid) as numberOfTriggerDisabled from triggers where status = 1; => 1
select count(triggerid) as numberOfTriggerOn from triggers where value = 0; => 1273
select count(triggerid) as numberOfTriggerOff from triggers where value = 1; => 56
我的结果: 触发器数量(启用/禁用 [问题/正常])1329 1328/ 1[1273/ 56 ]
网络仪表板: 触发器数量(启用/禁用 [问题/正常])333 197 / 136 [36 / 161]
// Number user online
//Number of users (online)
$numberOfUser = DBfetch(DBselect('select count(userid) as numberOfUser from users'));
$numberOfUserSessions = DBfetchArray(DBselect('select distinct(userid) from sessions'));
$numberOfUserOnline = 0;
foreach ($numberOfUserSessions as $userSession)
{
$sessionStatus = DBfetchArray(DBselect('select * from sessions where userid = '.$userSession['userid'].' order by lastaccess desc limit 2'));
if($sessionStatus[0]['status'] !== $sessionStatus[1]['status'])
{
$numberOfUserOnline = $numberOfUserOnline + 1;
}
}
我的结果: 用户数(在线) 17 2
网络仪表板: 用户数(在线) 17 1
// Server performance
$vps_total = DBfetch(DBselect(
'SELECT sum(vps) AS vps
FROM (
SELECT count(*),count(*)/i.delay as vps
FROM items i
JOIN hosts h ON i.hostid=h.hostid
WHERE i.status=0
AND h.status=0
AND i.type=0
GROUP BY i.type,i.delay
ORDER BY i.type, i.delay
) as data'
));
$server_performance = round($vps_total['vps'], 2);
我的结果: 所需的服务器性能,每秒新值 35.11
网络仪表板: 所需的服务器性能,每秒新值 37.11
请为我提供与 Web 仪表板相同的结果的正确 SQL 查询建议。
感谢和最好的问候, BienHV
【问题讨论】: