1、环境介绍
操作系统:龙蜥os 7.9
软件:dataease v1.18.18
zabbix: 6.0
2、软件下载
https://community.fit2cloud.com/#/products/dataease/downloads
3、将软件包上传到服务器并解压缩
tar -xvf dataease-v1.18.18-offline.tar.gz
4、修改安装配置
根据自己需求修改配置
5、执行安装脚本
sh install.sh
6、登录web ui并修改登录密码
注意:上一步安装成功后会输出默认用户名密码admin dataease
登录成功后这样(这是1.0版本,2.0版本整洁比较,但是模版不如1.0版本多)
7、添加zabbix数据源(以下 数据源、模版、官方展示数据屏全部删除了)
这里根据自己的zabbix 数据库版本选择,我这里是mysql
填写数据库信息,验证成功后保存
8、创建zabbix仪表盘目录
9、选择zabbix模版
选择上一步建立的目录zabbix
10、创建数据集(这里只写一个示例,最后我将记录全部使用的数据集,sql如果有出入自行修改,没啥字段说明,只能自己看数据库)
提示建立一个文件夹
点加号建立数据集,这里选择sql
SELECT
CASE
WHEN p.severity = '0' THEN '未分类'
WHEN p.severity = '1' THEN '信息'
WHEN p.severity = '2' THEN '警告'
WHEN p.severity = '3' THEN '一般严重'
WHEN p.severity = '4' THEN '严重'
WHEN p.severity = '5' THEN '灾难级'
END AS severity_name,
COUNT(*) AS num
FROM problem p
JOIN (
SELECT triggerid, MIN(itemid) AS itemid
FROM functions
GROUP BY triggerid
) f ON p.objectid=f.triggerid
JOIN items i ON f.itemid=i.itemid
JOIN hosts h ON i.hostid=h.hostid
LEFT JOIN interface inf ON inf.hostid=h.hostid AND inf.main=1
WHERE p.r_clock=0
AND h.status IN (0,1)
AND i.status=0
AND (inf.ip IS NULL OR inf.ip <> '127.0.0.1')
GROUP BY
CASE
WHEN p.severity = '0' THEN '未分类'
WHEN p.severity = '1' THEN '信息'
WHEN p.severity = '2' THEN '警告'
WHEN p.severity = '3' THEN '一般严重'
WHEN p.severity = '4' THEN '严重'
WHEN p.severity = '5' THEN '灾难级'
END,
p.severity
ORDER BY CAST(p.severity AS SIGNED) DESC;
点击运行检查 成功出数据后,保存
11、将数据集应用到模版
点击更换数据集,拖动数据到维度和指标(维度就是表头,指标就是数,如果维度和指标不对就在数据集中更改,或者转换)
填好后这里数据就变了 这就是一个区域弄好了,按照这个思路完善其他区域即可(如有需求这里可以编辑图标的样式)
12、补充数据集(自行调整,有不对的欢迎留言)
主机组数量统计
SELECT COUNT(*) as 主机组数量
FROM hstgrp;
主机数量统计
SELECT
COUNT(DISTINCT h.hostid) AS 主机数量
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
WHERE
h.status = 0;
可监控主机数量统计
SELECT
COUNT(DISTINCT h.hostid) AS 可监控主机
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
JOIN
interface i ON h.hostid = i.hostid
WHERE
h.status = 0
AND i.available = 1;
不可监控主机数量统计
SELECT
COUNT(DISTINCT h.hostid) AS 不可监控主机
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
JOIN
interface i ON h.hostid = i.hostid
WHERE
h.status = 0
AND i.available = 2;
未知监控主机数量统计
SELECT
COUNT(DISTINCT h.hostid) AS 未知监控主机
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
JOIN
interface i ON h.hostid = i.hostid
WHERE
h.status = 0
AND i.available = 0;
告警主机数量统计
SELECT
COUNT(DISTINCT h.hostid) AS 告警主机数量
FROM
triggers t
JOIN
problem p ON t.triggerid = p.objectid
JOIN
functions f ON t.triggerid = f.triggerid
JOIN
items it ON f.itemid = it.itemid
JOIN
hosts h ON it.hostid = h.hostid
WHERE
p.r_eventid IS NULL
AND h.status = 0;
待处理警告数量统计
SELECT COUNT(DISTINCT p.eventid) AS 待处理警告数
FROM problem p
JOIN triggers t ON p.objectid = t.triggerid
JOIN functions f ON t.triggerid = f.triggerid
JOIN items i ON f.itemid = i.itemid
JOIN hosts h ON i.hostid = h.hostid
WHERE p.r_eventid IS NULL
AND p.acknowledged = 0;
已处理警告数量统计
SELECT COUNT(*) AS 已处理警告数量
FROM (
SELECT eventid
FROM problem
WHERE acknowledged = 1
UNION ALL
SELECT eventid
FROM events
WHERE severity = 0
) AS resolved_warnings;
主机状态数量统计
SELECT
'可监控主机' AS 主机状态,
COUNT(DISTINCT CASE WHEN i.available = 1 THEN h.hostid END) AS 数量
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
JOIN
interface i ON h.hostid = i.hostid
WHERE
h.status = 0
UNION ALL
SELECT
'不可监控主机' AS 主机状态,
COUNT(DISTINCT CASE WHEN i.available = 2 THEN h.hostid END) AS 数量
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
JOIN
interface i ON h.hostid = i.hostid
WHERE
h.status = 0
UNION ALL
SELECT
'未知监控主机' AS 主机状态,
COUNT(DISTINCT CASE WHEN i.available = 0 THEN h.hostid END) AS 数量
FROM
hstgrp hg
JOIN
hosts_groups hgh ON hg.groupid = hgh.groupid
JOIN
hosts h ON hgh.hostid = h.hostid
JOIN
interface i ON h.hostid = i.hostid
WHERE
h.status = 0;
top 10 待处理问题数
SELECT
h.name AS 主机名称,
COUNT(p.eventid) AS 问题数
FROM
problem p
LEFT JOIN (
SELECT
s1.triggerid,
(
SELECT
s2.itemid
FROM
functions s2
WHERE
s2.triggerid = s1.triggerid
LIMIT 1
) AS itemid
FROM
functions s1
GROUP BY
s1.triggerid
) AS f ON f.triggerid = p.objectid
LEFT JOIN `items` AS i ON i.itemid = f.itemid
LEFT JOIN `hosts` AS h ON h.hostid = i.hostid
LEFT JOIN `interface` AS inf ON inf.hostid = h.hostid
WHERE
p.r_eventid IS NULL
AND h.status = 0
AND i.status = 0
GROUP BY
h.hostid, h.host
ORDER BY
问题数 DESC
LIMIT 10;
top 10 主机组告警数
SELECT
total_problems.主机组名,
SUM(total_problems.num_problems) AS 问题数
FROM (
SELECT
hs.NAME AS 主机组名,
COUNT(DISTINCT p.eventid) AS num_problems
FROM
problem p
LEFT JOIN (
SELECT
s1.triggerid,
(
SELECT
s2.itemid
FROM
functions s2
WHERE
s2.triggerid = s1.triggerid
LIMIT 1
) AS itemid
FROM
functions s1
GROUP BY
s1.triggerid
) AS f ON f.triggerid = p.objectid
LEFT JOIN `items` AS i ON i.itemid = f.itemid
LEFT JOIN `hosts` AS h ON h.hostid = i.hostid
LEFT JOIN hosts_groups AS hg ON hg.hostid = h.hostid
LEFT JOIN hstgrp AS hs ON hs.groupid = hg.groupid
WHERE
ISNULL(p.r_eventid)
AND h.STATUS = 0
AND i.`status` = 0
GROUP BY
hs.NAME
) AS total_problems
GROUP BY
total_problems.主机组名
ORDER BY
问题数 DESC
LIMIT 10;
主机组异常设备占比
SELECT
hg.groupid AS '组ID',
COALESCE(hs.name, '无') AS '组名',
COUNT(DISTINCT CASE WHEN p.eventid IS NOT NULL THEN h.hostid END) AS '异常主机数量',
COUNT(DISTINCT h.hostid) AS '总主机数量',
CONCAT(ROUND(COUNT(DISTINCT CASE WHEN p.eventid IS NOT NULL THEN h.hostid END) / COUNT(DISTINCT h.hostid) * 100, 2), '%') AS '异常主机占比'
FROM
hosts_groups hg
LEFT JOIN hosts h ON hg.hostid = h.hostid
LEFT JOIN hstgrp hs ON hg.groupid = hs.groupid
LEFT JOIN (
SELECT
i.hostid,
p.eventid
FROM
problem p
JOIN functions f ON p.objectid = f.triggerid
JOIN items i ON f.itemid = i.itemid
WHERE
p.r_eventid IS NULL
) AS p ON h.hostid = p.hostid
WHERE
h.status = 0
GROUP BY
hg.groupid, hs.name
ORDER BY
hg.groupid;
告警信息详细
SELECT DISTINCT
e.clock,
FROM_UNIXTIME(e.clock) AS '告警时间',
e.name AS '告警名称',
e.severity AS '严重程度',
CASE e.severity
WHEN '0' THEN '未定义'
WHEN '1' THEN '信息'
WHEN '2' THEN '警告'
WHEN '3' THEN '一般严重'
WHEN '4' THEN '严重'
WHEN '5' THEN '灾难'
ELSE '未知'
END AS '严重程度名称',
h.host AS '主机名',
h.name_upper AS '主机名显示',
i.ip AS 'IP地址'
FROM
events e
LEFT JOIN
triggers t ON e.objectid = t.triggerid
LEFT JOIN
functions f ON t.triggerid = f.triggerid
LEFT JOIN
items it ON f.itemid = it.itemid
LEFT JOIN
hosts h ON it.hostid = h.hostid
LEFT JOIN
interface i ON h.hostid = i.hostid
WHERE
e.source = 0
AND e.value = 1
ORDER BY
e.clock DESC;
最终效果