200字
Zabbix 利用 Grafana 进行图形展示
2026-04-04
2026-04-04

Zabbix 利用 Grafana 进行图形展示

虽然 Zabbix 自身带有图形功能,但是并不美观,而利用 Grafana 可以实现相当精美的 Web 图形显示

Grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和 应用分析中最流行的时序数据展示工具,目前已经支持绝大部分常用的时序数据库

Grafana支持许多不同的数据源。每个数据源都有一个特定的查询编辑器,该编辑器定制的特性和功能是 公开的特定数据来源。 官方支持以下数据源:Zabbix,Graphite,Elasticsearch,InfluxDB, Prometheus,Cloudwatch,MySQL和OpenTSDB等。

官方站点: https://grafana.com/

使用 Grafana 显示Zabbix的监控数据过程

  • 安装 grafana
  • 安装 zabbix 插件
  • 创建 zabbix 数据源
  • 导入 dashboard 模板

注意: 如果浏览器无法正常显示grafana的图形,可能是浏览器版本问题,建议更换浏览器再尝试

安装 Grafana 包

安装 Grafana 包

[root@ubuntu2204 ~]#apt list 2>/dev/null| grep grafana
ceph-grafana-dashboards/jammy-updates 17.2.0-0ubuntu0.22.04.2 all
golang-github-grafana-grafana-plugin-model-dev/jammy 0.0~git20200514.df1eb6b-1 
all

[root@ubuntu2004 ~]#apt list 2>/dev/null| grep grafana

CentOS8 系统AppStream源带有 grafana,CentOS7 则无此包

[root@zabbix-server ~]#yum info  grafana
Last metadata expiration check: 0:58:43 ago on Tue 13 Jul 2021 08:40:31 AM CST.
Available Packages
Name         : grafana
Version      : 6.7.4
Release      : 3.el8
Architecture : x86_64
Size         : 28 M
Source       : grafana-6.7.4-3.el8.src.rpm
Repository   : AppStream
Summary      : Metrics dashboard and graph editor
URL          : https://grafana.org
License      : ASL 2.0
Description  : Grafana is an open source, feature rich metrics dashboard and 
graph editor for
             : Graphite, InfluxDB & OpenTSDB.

包下载链接:

https://grafana.com/grafana/download 
https://mirrors.tuna.tsinghua.edu.cn/grafana/

两种版本: Enterprise 和 OSS

The Enterprise Edition is the default and recommended edition. It includes all 
the features of the OSS Edition, can be used for free and can be upgraded to the 
full Enterprise feature set, including support for Enterprise plugins.

最新版本下载安装

范例:Ubuntu22.04 安装grafana

[root@ubuntu2204 ~]#wget https://dl.grafana.com/enterprise/release/grafanaenterprise_9.4.7_amd64.deb
[root@ubuntu2204 ~]#apt -y  install  adduser libfontconfig1
[root@ubuntu2204 ~]#dpkg -i grafana-enterprise_9.4.7_amd64.deb

范例

#Ubuntu安装
[root@zabbix-server ~]#wget  https://mirrors.tuna.tsinghua.edu.cn/grafana/apt/pool/main/g/grafana/grafana_8.0.3_amd64.deb
[root@zabbix-serve ~]#dpkg -i grafana_8.0.3_amd64.deb

#CentOS安装新版
[root@zabbix-server ~]#wget  https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/grafana-8.0.3-1.x86_64.rpm
[root@zabbix-server ~]#yum -y install grafana-8.0.3-1.x86_64.rpm

#CentOS安装旧版
[root@zabbix-server ~]#wget https://dl.grafana.com/oss/release/grafana-7.1.5-1.x86_64.rpm
[root@zabbix-server ~]#yum -y install grafana-7.1.5-1.x86_64.rpm

开启 Grafana 服务

#无需修改配置文件,即可启动,默认监听3000/tcp端口
[root@zabbix-grafana ~]#systemctl enable  --now grafana-server.service 
[root@zabbix-grafana ~]#ss -ntlp|grep 3000
LISTEN     0  128	*:3000		user:(("grafana-server",pid=1957,fd=8))

首次登录 Grafana 的 Web 界面

首次浏览器访问 grafana的 web 界面

http://grafana-server:3000/

使用默认用户名和密码都是admin登录

首次登录修改密码,也可以选择skip仍使用原初始密码

登录成功

登录用户等信息保存在下面数据文件中

[root@zabbix-server ~]#file /var/lib/grafana/grafana.db
/var/lib/grafana/grafana.db: SQLite 3.x database, last written using SQLite 
version 3035004

以下是grafana-7.1.5版本界面

初始登录界面

修改初始密码 登录成功

在 Grafana 安装 Zabbix 插件

关于zabbix的插件官网地址

https://grafana.com/grafana/plugins
https://grafana.com/grafana/plugins/alexanderzobnin-zabbix-app

#zabbix插件官方安装说明
https://alexanderzobnin.github.io/grafana-zabbix/installation/

范例: 使用 grafana-cli 命令管理工具安装插件

#列出远程的可用插件
[root@zabbix-server ~]#grafana-cli plugins list-remote
id: abhisant-druid-datasource version: 0.0.6
id: aceiot-svg-panel version: 0.0.10
id: ae3e-plotly-panel version: 0.4.0
id: agenty-flowcharting-panel version: 0.9.1
id: aidanmountford-html-panel version: 0.0.2
id: akumuli-datasource version: 1.3.12
......

#查看zabbix相关插件
[root@zabbix-server ~]#grafana-cli plugins list-remote|grep zabbix
id: alexanderzobnin-zabbix-app version: 4.1.5

#列出插件的版本
[root@zabbix-server ~]#grafana-cli plugins list-versions   alexanderzobnin-zabbix-app
4.1.5
4.1.4
4.1.3
4.1.2
4.1.1
4.1.0
4.0.2
.......

#安装zabbix插件,可指定版本,下载安装插件至/var/lib/grafana/plugins/目录
#如果在线下载比较慢,可以先下载相关插件的zip文件,复制到/var/lib/grafana/plugins/目录下,再解压缩也可以
#下链链接https://github.com/alexanderzobnin/grafana-zabbix/releases

[root@zabbix-server ~]#grafana-cli plugins install   alexanderzobnin-zabbix-app 4.1.5
✔ Downloaded alexanderzobnin-zabbix-app v4.1.5 zip successfully

Please restart Grafana after installing plugins. Refer to Grafana documentation 
for instructions if necessary.

#查看已安装的插件
[root@zabbix-server ~]#grafana-cli plugins ls
installed plugins:
alexanderzobnin-zabbix-app @ 4.1.5
Please restart Grafana after installing plugins. Refer to Grafana documentation 
for instructions if necessary.

#查看安装的插件的目录
[root@zabbix-server ~]#ls /var/lib/grafana/plugins/
alexanderzobnin-zabbix-app
[root@zabbix-server ~]#ls /var/lib/grafana/plugins/alexanderzobnin-zabbix-app/
app_config_ctrl    img             plugin.json                 
zabbix
plugin_linux_arm64
CHANGELOG.md       MANIFEST.txt    README.md                   
plugin_windows_amd64.exe
css                module.js       zabbix-plugin_darwin_amd64
dashboards         module.js.map   zabbix-plugin_linux_amd64
datasource-zabbix  panel-triggers  zabbix-plugin_linux_arm

#重新启动服务生效
[root@zabbix-server ~]#systemctl restart grafana-server.service

针对Zabbix4.0

#列出远程的可用插件
[root@zabbix-grafana ~]#grafana-cli plugins list-remote
id: abhisant-druid-datasource version: 0.0.5
id: aceiot-svg-panel version: 0.0.8
id: agenty-flowcharting-panel version: 0.9.0
id: aidanmountford-html-panel version: 0.0.1
id: akumuli-datasource version: 1.3.11
id: alexanderzobnin-zabbix-app version: 4.0.1
id: alexandra-trackmap-panel version: 1.2.5
id: andig-darksky-datasource version: 1.0.1
id: aquaqanalytics-kdbadaptor-datasource version: 1.0.1
id: ayoungprogrammer-finance-datasource version: 1.0.0

#选择安装版本3.12.4插件,4.0.1版本有问题
[root@zabbix-grafana ~]#grafana-cli plugins install   alexanderzobnin-zabbix-app 3.12.4
installing alexanderzobnin-zabbix-app @ 3.12.4
from: https://grafana.com/api/plugins/alexanderzobnin-zabbix
app/versions/3.12.4/download
into: /var/lib/grafana/plugins

✔ Installed alexanderzobnin-zabbix-app successfully 

Restart grafana after installing plugins . <service grafana-server restart>

#查看安装的插件文件
[root@zabbix-grafana ~]#ls /var/lib/grafana/plugins
alexanderzobnin-zabbix-app

#重新启动脬务
[root@zabbix-grafana ~]#systemctl restart grafana-server.service 

在 Grafana 中启用 Zabbix 插件

可以看到zabbix插件已安装成功,点zabbix插件

启用插件

启用插件成功

添加 Zabbix 数据源

选中zabbix

在URL填写以下信息

#基于nginx
http://zabbix-server/api_jsonrpc.php
#基于apache
http://zabbix-server/zabbix/api_jsonrpc.php

输入Zabbix的用户和密码

测试连接

导入自带的 Grafana 模板

上面界面---Dashboards

可以看到三个导入的dashboard,其中第二个Zabbix System Status 常用于观察告警信息

第一个dashboard

查看第三个dashboard

System load 无数据

编辑System load

默认的监控项有问题,修改对应的监控项的名称(注意:不是监控项的key)

查看到数据出现

模板只有CPU,system load和network,可以修改模板再加其它项目的图形显示

拖动图形,放在合适的位置,并保存

导入官网的其它 Grafana 模板

grafana官网提供了很多图形显示的模板,可以从下面地址查看

https://grafana.com/grafana/dashboards

导入模板16238(适用于Zabbix6.0), 5363和787

搜索合适的模板, 一般推荐使用下载量较大的模板

查看模板信息和ID

导入5363模板

可以选择其它模板 7877

调整模板显示信息

当前导入的模板不一定都符合要求,可以进一步调整显示信息

默认导入的dashboard无法编辑

先将此dashboard设为允许编辑

保存修改后模板

查看生成的 Dashboard

删除不需要的模板

如果导入的模板不适合,可以删除

选择不需要的模板

自定义 Dashboard

先创建文件夹,然后在文件夹中创建各种图形

创建后记得save,否则刷新页面会导致数据丢失

创建文件夹

Dashboards -> Manage -> New folder ->填写名称(Zabbix) -> Create Dashboard

创建CPU图形

Add an empty panel -> Data source -> 选择 zabbix

对CPU创建两个图形:CPU 平均负载和 CPU 时间

CPU 平均负载

CPU 平均负载

  • Group: Zabbix servers
  • Host: Zabbix server
  • Application: CPU
  • Item: 获取负载的监控项,输入正则表达式 /Load/ ,注意大小写敏感
  • Item: 获取时间的监控项,输入正则表达式 /time/,再创建另一个Panel 取时间的监控项

图形配置

  • Title:CPU 平均负载
  • Tooltip mode:ALL(展示所有指标的数据)、Single(展示选中的单个指标数据)
  • Unit:CPU负载图形不需要单位(Misc-none)、CPU时间要显示为百分比(Misc-Percent 0 100)

CPU 时间

Query (数据查询)

  • Group: Zabbix servers
  • Host: Zabbix server
  • Application: CPU
  • Item: 获取时间的监控项,输入正则表达式 /time/, 创建CPU时间的监控项, ,注意大小写敏感

图形配置

  • Title:CPU 时间
  • Tooltip mode:ALL(展示所有指标的数据)、Single(展示选中的单个指标数据)
  • CPU时间要显示为百分比(Misc-Percent 0-100)

创建内存图形

Query A

  • Group: Zabbix servers
  • Host: Zabbix server
  • Application: Memory
  • Item: Total memor

Query B

  • Group: Zabbix servers
  • Host: Zabbix server
  • Application: Memory
  • Item: Available memory

图形配置

  • 选择 Pie chart 图形
  • Title:内存使用百分比
  • unit:单位选择:data -> bytes(IEC)
  • Lable: 标签选择(Name、Value)
  • Legend values:数据使用展示选择(Value、Percent)

创建流量图形

Query A

  • Group: Zabbix servers
  • Host: Zabbix server
  • Application: Interface eth0
  • Item: /Bits/

图形配置

  • Title:网卡eth0流量
  • unit:单位选择:data -> Unit/sec(SI)
  • Legend values:数据使用展示选择(Last、Min、Max)

创建告警面板

将Zabbix的 Web 仪表板的告警加加入Grafana进行展示

Query Mode:Problems

Visualizations:Zabbix Problems

Title:Zabbix 告警信息

导出 Dashboard

导出上面自定义的dashboard 为Json文件, 以方便以后使用

自定义变量实现自定义 Dashboard

以上都是单台Zabbix Server 服务器的图形比较容易展现,但需要展示多台服务器的图形就需要在从头 到位创建一次,过程比较繁琐

可以使用变量的方式获取对应的主机组,以及主机,然后基于变量来完成图形创建

创建变量

打开指定Dashboard --> Dashboard Settings --> Variables

设置主机组变量:

Name:定义名称Group
Data source:选择zabbix
Refresh: 跟随时间而变化 on time range
Query Type:选择Group
Group: 提取所有组的正则表达式:/.*/
Selection Options:全部打开
Preview of values:会自动显示当前所有的主机组

设置主机变量:

Name:定义名称Host
Data source:选择zabbix
Refresh: 跟随时间而变化 on time range
Query Type:选择Host
Group: 提取所有组的正则表达式:/.*/
Host: 提取所有主机的正则表达式:/.*/
Selection Options:全部打开
Preview of values:会自动显示当前所有的主机

设置完成后记得Save保存

使用变量

将此前创建的CPU负载图形,修改为变量方式,这样就会更加灵活

Query A

Group: $Group
Host: $Host
Application:CPU
Item: /Load/

Title:

$Group $Host CPU 平均负载

参考上面的,将CPU时间,内存使用百分比,网卡eth0流量都改为使用变量

将上面自定义的 Dashborad 导出至文件

导出为json文件

将上面自定义的 Dashborad 文件导入

将来在另一台主机上导入上面的json文件即可

评论