这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.
2022 Zabbix中国峰会
2022 Zabbix中国峰会

14 插件

概览

插件提供了扩展Zabbix监控功能的选项。插件是用 Go 语言编写的,并且只有 Zabbix agent2 支持。

插件提供了可加载模块 (由 C 编写),以及其他扩展 Zabbix 功能的方法,例如 用户参数(agent指标),外部检查 (无代理监控)和system.run[] Zabbix agent监控项

以下功能特定于agent 2 及其插件:

  • 被动、主动检查都支持定期和灵活采集间隔;
  • 与调度和任务并发相关的任务队列管理;
  • 插件级超时;
  • Zabbix agent 2 及其插件在启动时的兼容性检查。

从 Zabbix 6.0.0 开始,插件不必直接集成到agent2 中,并且可以作为单独的外部插件添加,从而使得创建额外的插件来收集新的监控指标更加容易。

本页列出了 Zabbix 原生插件,并从用户角度描述了插件配置原则。有关编写自己的插件的说明,请参阅插件开发指南

配置插件

本节提供常用的插件配置原则和最佳实践。

所有插件都使用 Plugins.* 参数配置,可以是 Zabbix agent 2 配置文件的一部分或插件自己的配置文件。如果插件使用单独的配置文件,该文件的路径应该在 Zabbix agent 2 配置文件的 Include 参数中指定。

每个插件参数应具有以下结构:

Plugins.<PluginName>.<Parameter>=<Value>

参数名称应符合以下要求:

  • 建议您的插件名称大写;
  • 参数应大写;
  • 不允许有特殊字符;
  • 嵌套不受最高层数限制;
  • 参数数量不受限制。
命名会话

命名会话代表附加级别的插件参数,可以用于为每个被监视的实例定义单独的身份验证参数集。每个命名的会话参数应具有以下结构:

Plugins.<PluginName>.Sessions.<SessionName>.<Parameter>=<Value>

会话名称可以当作连接字符串来配置监控项键值参数,而不是分别指定 URI、用户名和密码。在监控项键中,第一个参数可以是连接字符串 或 Uri。如果第一个键参数匹配配置文件中指定的会话名称,检查将使用命名会话参数执行。如果第一个key 参数没有匹配到会话名称,它将被视为Uri。

注意:

  • 在键值参数中使用连接字符串(会话名称)时,键值参数的用户名和密码必须为空;
  • 不支持传递嵌入式 URI 凭据,请考虑使用命名会话;
  • 如果没有为命名会话指定身份验证参数,将使用写死的默认值。

可用的命名会话参数列表取决于插件,详情参阅独立插件配置文件

示例:监控“MySQL1”和“MySQL2”两个实例可以采用如下配置方式:

Plugins.Mysql.Sessions.MySQL1.Uri=tcp://127.0.0.1:3306
       Plugins.Mysql.Sessions.MySQL1.User=<UsernameForMySQL1>
       Plugins.Mysql.Sessions.MySQL1.Password=<PasswordForMySQL1>
       Plugins.Mysql.Sessions.MySQL2.Uri=tcp://127.0.0.1:3307
       Plugins.Mysql.Sessions.MySQL2.User=<UsernameForMySQL2>
       Plugins.Mysql.Sessions.MySQL2.Password=<PasswordForMySQL2>

现在,这些名称可以作为连接字符串用于键值中, 而不是 URIs:

mysql.ping[MySQL1]
       mysql.ping[MySQL2]
Parameter priority

Since version 6.4.3, Zabbix agent 2 plugins search for connection-related parameter values in the following order:

  1. The first item key parameter is compared to session names. If no match is found it is treated as an actual value; in this case, step 3 will be skipped. If a match is found, the parameter value (usually, a URI) must be defined in the named session.
  2. Other parameters will be taken from the item key if defined.
  3. If an item key parameter (for example, password) is empty, plugin will look for the corresponding named session parameter.
  4. If the session parameter is also not specified, the value defined in the corresponding default parameter will be used.
  5. If all else fails, the plugin will use the hardcoded default value.
Example 1

Monitoring of two instances “MySQL1” and “MySQL2”.

Configuration parameters:

Plugins.Mysql.Sessions.MySQL1.Uri=tcp://127.0.0.1:3306
       Plugins.Mysql.Sessions.MySQL1.User=mysql1_user
       Plugins.Mysql.Sessions.MySQL1.Password=unique_password
       Plugins.Mysql.Sessions.MySQL2.Uri=tcp://192.0.2.0:3306
       Plugins.Mysql.Sessions.MySQL2.User=mysql2_user
       Plugins.Mysql.Sessions.MySQL2.Password=different_password

Item keys: mysql.ping[MySQL1], mysql.ping[MySQL2]

Example 2

Providing some of the parameters in the item key (supported since Zabbix 6.0.17).

Configuration parameters:

Plugins.Postgres.Sessions.Session1.Uri=tcp://192.0.2.234:5432
       Plugins.Postgres.Sessions.Session1.User=old_username
       Plugins.Postgres.Sessions.Session1.Password=session_password

Item key: pgsql.ping[session1,new_username,,postgres]

As a result of this configuration, the agent will connect to PostgreSQL using the following parameters:

  • URI from session parameter: 192.0.2.234:5432
  • Username from the item key: new_username
  • Password from session parameter (since it is omitted in the item key): session_password
  • Database name from the item key: postgres
Example 3

Collecting a metric using default configuration parameters.

Configuration parameters:

Plugins.Postgres.Default.Uri=tcp://192.0.2.234:5432
       Plugins.Postgres.Default.User=zabbix
       Plugins.Postgres.Default.Password=password

Item key: pgsql.ping[,,,postgres]

As a result of this configuration, the agent will connect to PostgreSQL using the parameters:

  • Default URI: 192.0.2.234:5432
  • Default username: zabbix
  • Default password: password
  • Database name from the item key: postgres
硬编码默认值

如果监控项键或命名会话参数中未提供身份验证所需的参数,则插件将使用硬编码默认值。

连接

一些插件支持同时从多个实例收集指标。可以监控本地和远程实例。 并支持TCP和Unix-socket 连接。

建议配置插件以保持与实例的连接处于打开状态。好处是减少了网络拥塞、延迟、CPU和内存使用率,因为连接数较少。客户端库负责处理这些。

未使用的连接应保持打开的时间段可由 Plugins.<PluginName>.KeepAlive 参数确定。 示例:Plugins.Memcached.KeepAlive

插件

Zabbix agent 2 支持的所有指标都由插件收集。

内置

Zabbix agent 2 的以下插件开箱即用。 单击插件名称以转到包含其他信息的插件存储库。

插件名称 描述 支持的监控项键 注释
Agent 正在使用的 Zabbix agent的指标。 agent.hostname、agent.ping、agent.version 支持的键与Zabbix agent key 具有相同的参数。
Ceph Ceph监控。 ceph.df.details,ceph。 osd.stats、ceph.osd.discovery、ceph.osd.dump、
ceph.ping、ceph.pool.discovery、ceph.status
CPU 系统CPU监控(CPU数/CPU核数,发现的CPU数,CPU利用率). system.cpu.discovery, system.cpu.num, system.cpu.util 支持的键与 Zabbix agent keys 具有相同的参数。
Docker Docker容器的监控。 docker.container_info, docker.container _stats、docker.containers、docker.containers.discovery、
docker.data_usage、docker.images、docker.images.discovery、docker.info、docker.ping
另请参阅:
配置参数
File 文件指标集合。 vfs.file.cksum、vfs.file.contents、vfs.file.exists、vfs.file.md5sum、
vfs.file.regexp、vfs.file.regmatch、vfs.file .size, vfs.file.time
支持的键与 Zabbix agent keys 具有相同的参数。
Kernel 内核监控。 kernel.maxfiles, kernel.maxproc 支持的键有与 Zabbix agent keys 具有相同的参数。
Log 日志文件监控。 log, log.count, logrt, logrt.count 支持的键与 Zabbix agent keys 具有相同的参数。

另请参阅:
插件配置参数 (Unix/Windows)
Memcached Memcached 服务器监控。 memcached.ping, memcached.stats
Modbus 读取 Modbus 数据。 modbus.get 支持的键与 Zabbix agent keys 具有相同的参数。
MQTT 接收 MQTT 主题的发布值。 mqtt.get
MySQL MySQL 及其分支的监控。 mysql.db。 discovery, mysql.db.size, mysql.get_status_variables,
mysql.ping, mysql.replication.discovery, mysql.replication.get_slave_status, mysql.version
配置数据库的加密连接 , 使用 命名会话 并在agent配置文件中为命名会话指定 TLS 参数。 目前,TLS 参数不能作为监控项键参数传递。
NetIf 网络接口监控。 net.if.collisions, net. if.discovery, net.if.in, net.if.out, net.if.total 支持的键与 Zabbix agent keys 具有相同的参数。
Oracle Oracle 数据库监控。 oracle.diskgroups.stats, oracle .diskgroups.discovery, oracle.archive.info, oracle.archive.discovery,
oracle.cdb.info, oracle.custom.query, oracle.datafiles.stats, oracle.db.discovery,
oracle.fra .stats、oracle.instance.info、oracle.pdb.info、oracle.pdb.discovery、
oracle.pga.stats、oracle.ping、oracle.proc.stats、oracle.redolog.info、
oracle .sga.stats、oracle.sessions.stats、oracle.sys.metrics、oracle.sys.params、
oracle.ts.stats、oracle.ts.discovery、oracle.user.info
在使用插件之前安装 Oracle Instant Client
Proc 进程 CPU 使用率。 proc.cpu.util 支持的键与Zabbix agent key 具有相同的参数。
Redis Redis 服务器监控。 redis.config, redis.info ,redis.ping,redis.slowlog.count
Smart S.M.A.R.T. monitoring. smart.attribute.discovery, smart.disk.discovery, smart.disk.get 执行 Zabbix agent 2 的用户需要对 smartctl 的 Sudo/root 访问权限。所需的最低 smartctl 版本为 7.1。
< br>支持的 keys 只能在 Linux/Windows 上与 Zabbix agent 2 一起使用,作为被动和主动检查。
另请参阅:
配置参数
Swap 以字节/百分比为单位的交换空间大小。 system.swap.size 支持的键与 Zabbix agent keys 具有相同的参数。
SystemRun 运行指定命令。 system.run 支持的键与 Zabbix agent keys 具有相同的参数。

另请参阅:
插件配置参数(Unix/Windows)
Systemd systemd 服务的监控。 systemd.unit.discovery、systemd.unit.get、systemd.unit.info
TCP TCP 连接可用性检查。 net.tcp.port 支持的键与 Zabbix agent key 具有相同的参数。
UDP UDP 服务可用性和性能的监控。 net.udp.service, net.udp.service.perf 支持的键与Zabbix agent keys 具有相同的参数。
Uname 检索有关系统的信息。 system.hostname, system. sw.arch, system.uname 支持的键与 Zabbix agent keys 具有相同的参数。
Uptime 系统正常运行时间指标收集。 system.uptime 支持的键与 Zabbix agent keys 具有相同的参数。
VFSDev VFS 指标收集。 vfs.dev.discovery, vfs.dev .read, vfs.dev.write 支持的键与 Zabbix agent keys 具有相同的参数。
WebCertificate TLS/SSL网站证书监控。 web.certificate.get
WebPage 网页监控. web.page.get, web.page .perf, web.page.regexp 支持的键与 Zabbix agent keys 具有相同的参数。
ZabbixAsync 异步指标收集。 net.tcp.listen, net.udp.listen, sensor, system.boottime, system.cpu.intr, system.cpu.load、
system.cpu.switches、system.hw.cpu、system.hw.macaddr、system.localtime、system.sw。 os,
system.swap.in, system.swap.out, vfs.fs.discovery
支持的键与 Zabbix agent keys 具有相同的参数。
ZabbixStats Zabbix server/proxy 内部指标或队列中延迟监控项的数量 . zabbix.stats 支持的键与 Zabbix agent keys 具有相同的参数。
ZabbixSync 同步指标收集。 net.dns, net.dns.record , net.tcp.service, net.tcp.service.perf, proc.mem,
proc.num, system.hw.chassis, system.hw.devices, system.sw.packages,
system.users .num、vfs.dir.count、vfs.dir.size、vfs.fs.get、vfs.fs.inode、
vfs.fs.size、vm.memory.size。
支持的键与 Zabbix agent keys具有相同的参数。

可加载

可加载插件,启动时:
- -V --version - 打印插件版本和许可信息;
- -h --help - 打印帮助信息。

单击插件名称以转到包含其他信息的插件存储库。

插件名称 描述 支持的监控项键 注释
MongoDB MongoDB 服务器和集群(基于文档的分布式数据库)的监控。 mongodb.collection.stats, mongodb.collections.discovery, mongodb.collections.usage, mongodb.connpool.stats,
mongodb.db.stats, mongodb.db.discovery, mongodb.jumbo _chunks.count, mongodb.oplog.stats,
mongodb.ping, mongodb.rs.config, mongodb.rs.status, mongodb.server.status,
mongodb.sh.discovery
此插件自 Zabbix 6.0.6(之前内置)起可加载。 要配置与数据库的加密连接,请使用命名会话 并在agent配置文件中为命名会话指定 TLS 参数。
在插件版本 1.2.1、6.0.13 和更新版本中受支持1
目前TLS参数不能作为监控项键参数传递。

另见[MongoDB插件配置文件](/manual/appendix/config/zabbix_agent2_plugins/mongodb_plugin# 配置文件)。
PostgreSQL PostgreSQL 及其分支的监控。 pgsql.autovacuum.count, pgsql.archive, pgsql.bgwriter, pgsql.cache.hit, pgsql.connections,
pgsql.custom.query, pgsql.dbstat, pgsql.dbstat.sum, pgsql.db.age, pgsql .db.bloating_tables,
pgsql.db.discovery, pgsql.db.size, pgsql.locks, pgsql.oldest.xid, pgsql.ping, pgsql.queries,
pgsql.replication.count, pgsql .replication.process, pgsql.replication.process.discovery, pgsql.replication.recovery_role, pgsql.replication.status,
pgsql.replication_lag.b, pgsql.replication_lag.sec, pgsql.uptime, pgsql.wal.stat
此插件自 Zabbix 6.0.10(以前内置)起可加载。

要配置与数据库的加密连接,请使用 命名会话 并在agent配置文件中为命名会话指定 TLS 参数。 目前,TLS 参数不能作为监控项键参数传递。

另请参阅:构建可加载插件

脚注

1 - 从 Zabbix 6.0.13 开始,可加载插件开始使用与 Zabbix 本身相同的版本控制系统。 因此,MongoDB 插件版本从 1.2.1 更改为 6.0.13。