6个版本 (重大更改)
0.9.0 | 2024年6月22日 |
---|---|
0.8.1 | 2024年6月12日 |
0.7.4 | 2024年6月10日 |
0.6.0 | 2024年6月3日 |
0.5.0 | 2024年5月31日 |
#1 in #zabbix
370KB
6.5K SLoC
适用于Zabbix服务器的通用数据网关
通用数据网关(UDG),简称UDG,是Zabbix联邦生态系统中的关键组件。它是一个软件组件,旨在提取、分析和共享由Zabbix可观察性平台产生的遥测数据。作为Zabbix的实时数据连接器,它从Zabbix服务器接收遥测数据,将其转换为扩展的JSON格式,然后将其传递给输出处理器之一。
遥测连接器
首先,ZBUS UDG的标准内部组件是一个实时Zabbix连接器接口。它捕获从Zabbix服务器发送的数据,从负载中提取遥测数据,并将其馈送到内部的“IN”管道。
遥测处理器
下一个内部软件组件被称为“处理器”。此线程从“IN”内部管道接收遥测数据,将其转换为增强的JSON,将Zabbix项解析为Zabbix键,并将结果发送到“OUT”内部管道。
捕获处理器
捕获处理器是ZBUSUDG的组件,它连接到所选的遥测生成和分发服务,收集遥测数据,并将收集到的遥测数据路由到所选的输出处理器。目前支持以下捕获处理器:
捕获处理器 ZABBIX
当使用CLI关键字--zabbix选择时,它将启动实时ZABBIX遥测捕获器。在这个例子中,我们正在运行Zabbix实时捕获器并将接收到的遥测数据发送到NONE输出处理器。
zbusdg --zabbix-api http://127.0.0.1:8080/zabbix gateway --zabbix --none --zabbix-token zabbixapitoken
捕获处理器 NATS_CATCHER
当使用CLI关键字--nats-catcher选择时,ZBUSUDG通过订阅由--nats-subscribe-key指定的频道从NATS.io服务启动捕获线程。在这个例子中,第一个命令正在运行Zabbix遥测捕获器并将它传递给NATS聚合模式。第二个命令从NATS服务器接收遥测数据并将其发送到STDOUT输出处理器。
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --nats --zabbix-token zabbixapitoken --nats-aggregate
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --nats-catcher --zabbix-token zabbixtoken --stdout --pretty
捕获处理器 ZBUS
当使用CLI关键字--zbus-catcher选择时,ZBUSUDG通过订阅由--zbus-subscribe-key指定的主题从ZBUS遥测总线启动捕获线程。在这个例子中,我们正在从遥测总线捕获指标并将它们发送到标准输出。
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zbus-catcher --stdout --pretty
捕获处理器 PROMETHEUS_EXPORTER
当使用CLI关键字--prometheus-exporter-catcher选择时,ZBUSUDG启动一个收集线程,该线程将从Prometheus导出器中抓取指标并将它们转换为ZBUS遥测格式。在这个例子中,我们正在抓取Prometheus遥测数据并将它们发送到标准输出。
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --prometheus-exporter-catcher --stdout --pretty
捕获SYSLOGD消息
当使用CLI关键字--syslogd-catcher选择时,ZBUSUDG启动一个收集线程,该线程将接收标准的syslogd消息并将它们传递给任何支持的输出处理器。
zbusdg gateway --syslogd-catcher --stdout --pretty
输出处理器
UDG输出处理器的功能是从“OUT”内部管道读取准备好的遥测数据,并将其发送到正确的目的地。
以下是适用于通用数据网关的可用输出处理器列表
输出处理器NONE
正如其名所示,这是一个NOOP遥测处理器。如果网关使用此处理器,收集的遥测数据将被静默丢弃。
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --none --zabbix-token zabbixapitoken
输出处理器STDOUT
从“OUT”内部管道接收到的收集遥测数据将被发送到标准输出。如果您将——pretty指定为UDG CLI选项,则处理器将美化输出JSON。
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --stdout --pretty --zabbix-token zabbixapitoken
输出处理器SOCKET
以JSON格式提供的遥测数据将被发送到原始TCP套接字,每行一个遥测项目。
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --socket --pretty --zabbix-token zabbixapitoken --tcp-connect 127.0.0.1:55554
要接受遥测数据,您可以运行以下命令
nc -k -l 55554
输出处理器ZBUS
收集的遥测数据将被发送到ZBUS遥测总线,存储并交付给所有Zabbix联邦可观测性成员。交付可以是聚合的或按Zabbix密钥模式进行。如果指定了聚合交付,则所有遥测数据都将发送到总线上的单个密钥;否则,网关将从遥测消息中提取目标密钥。
带有遥测聚合的交付
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --zbus --zabbix-token zabbixapitoken --zbus-aggregate --zbus-aggregate-key mykey
不聚合的交付,到单个项目密钥
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --nats --zabbix-token zabbixapitoken --nats-aggregate
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --zbus --zabbix-token zabbixapitoken
输出处理器NATS
收集的遥测数据将被发送到NATS.io服务器,并且可以被任何NATS.io客户端访问。交付可以是聚合的或按Zabbix密钥模式进行。如果指定了聚合交付,则所有遥测数据都将发送到总线上的单个密钥;否则,网关将从遥测消息中提取目标密钥。
带有遥测聚合的交付
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --nats --zabbix-token zabbixapitoken --nats-aggregate --nats-aggregate-key mykey
不聚合的交付,到单个项目密钥
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --nats --zabbix-token zabbixapitoken
输出处理器MQTT
收集的遥测数据将被发送到MQTT服务器,并且可以被任何MQTT客户端访问。交付仅支持聚合模式。
带有遥测聚合的交付
zbusdg --zabbix-api http://192.168.86.29/zabbix gateway --zabbix --mqtt --zabbix-token zabbixapitoken --mqtt-aggregate-key mykey
输出处理器STATSD
收集的遥测数据将被发送到STATSD服务器,并且可以被STATSD组件集中的任何组件访问。
zbusdg --zabbix --zabbix-api http://192.168.86.29/zabbix gateway --statsd --zabbix-token zabbixapitoken
输出处理器TELEGRAF
收集的遥测数据将被发送到Telegraf服务器,并且可以与InfluxDB、Grafana以及Telegraf支持的其它所有可观测性工具和平台集成。
zbusdg --zabbix-api http://192.168.86.29/zabbix gateway --zabbix --telegraf --zabbix-token zabbixapitoken
输出处理器CLICKHOUSE
收集的遥测数据将被发送到Clickhouse OLAP列式存储,并且可以被任何支持clickhouse的工具使用。
zbusdg --zabbix-api http://192.168.86.29/zabbix gateway --zabbix --clickhouse --zabbix-token zabbixapitoken
输出处理器ZABBIX SENDER
收集的遥测数据将被发送到Zabbix Sender接口。Zabbix主机名将从来源字段中提取,Zabbix密钥将从zabbix_item键中提取。
zbusdg gateway --syslogd-catcher --zabbix-sender --zabbix-sender-connect 127.0.0.1:10051
将UDG遥测发送到ZBUS
ZBUS UDG可以发送一些来自Zabbix服务器的内部遥测数据。
监控处理JSON遥测批次所花费的时间
您可以通过向网关命令行目标传递--telemetry-monitor-elapsed来监控JSON批处理所花费的时间。遥测将被提交到/zbus/udg/elapsed键。
zbusdg --zabbix --zabbix-api http://192.168.86.29/zabbix gateway --nats --zabbix-token zabbixapitoken --telemetry-monitor-elapsed
遥测处理的程序控制
您可以使用RHAI脚本来添加程序控制,以过滤遥测并进行遥测转换。
遥测过滤
您可以创建一个脚本函数,用于控制ZBUSUDG是否接受遥测。为此,您需要创建一个文件,例如./scripts/allowall.rhai,其中包含以下函数
fn filter(data) {
true
}
然后按照下面的示例将此脚本传递给ZBUSUDG
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --stdout --zabbix-token zabbixtoken --script ./scripts/allowall.rhai
遥测转换
在ZBUS中,遥测以JSON格式表示。您可以通过创建RHAI脚本./scripts/allowall.rhai并定义将转换遥测JSON数据的函数来程序化地添加或修改遥测JSON内容。
fn transformation(data) {
data.body.details.added_by_transformation = "Transformation routine been here";
data
}
然后按照下面的示例将此脚本传递给ZBUSUDG
zbusdg --zabbix-api http://127.0.0.1/zabbix gateway --zabbix --stdout --zabbix-token zabbixtoken --script ./scripts/allowall.rhai
程序化遥测生成和处理
ZBUSUDG可以生成和处理程序创建的遥测数据。这个功能由两个函数支持:生成函数和处理函数。生成函数不接受任何参数,返回表示遥测数据的ObjectMaps列表。例如,生成函数generator()每次运行时都会生成两个遥测项。第一个是静态值,而第二个是程序生成的随机浮点数。
fn generator() {
log::info("Generating two telemetry items");
let data_pi = #{
body: #{
details: #{
destination: "zbus/generated_metric/local/pi",
origin: ZBUS_SOURCE,
details: #{
contentType: 0,
detailType: "",
data: 3.14,
},
},
properties: #{
name: "Return a static metric with a value of PI",
tags: [],
itemname: "pi",
timestamp: timestamp::timestamp_ms(),
},
},
headers: #{
version: ZBUS_PROTOCOL_VERSION,
encryptionAlgorithm: (),
compressionAlgorithm: (),
cultureCode: (),
messageType: "generated_telemetry",
route: ZBUS_ROUTE,
streamName: ZBUS_SOURCE,
},
};
let data_float = #{
body: #{
details: #{
destination: "zbus/generated_metric/local/random_float",
origin: ZBUS_SOURCE,
details: #{
contentType: 0,
detailType: "",
data: rand_float(0.1, 9.99),
},
},
properties: #{
name: "Return a static metric with a value of PI",
tags: [],
itemname: "random_float",
timestamp: timestamp::timestamp_ms(),
},
},
headers: #{
version: ZBUS_PROTOCOL_VERSION,
encryptionAlgorithm: (),
compressionAlgorithm: (),
cultureCode: (),
messageType: "generated_telemetry",
route: ZBUS_ROUTE,
streamName: ZBUS_SOURCE,
},
};
[data_pi, data_float]
}
函数processor()设计用于处理遥测后处理。它接收一个遥测项作为参数;然而,返回值目前被忽略。提供的示例函数简单地打印遥测数据并返回。这总结了函数的当前行为。
fn processor(data) {
print(data);
data
}
要启用程序化遥测处理器和捕获器,需要指定CLI选项--rhai-catcher以启动程序化遥测生成器。同样,启动程序化遥测接收器需要使用--rhai CLI选项。这使遥测数据在ZBUSUDG中流畅流动,便于交付给程序化处理器。
zbusdg gateway --rhai-catcher --rhai --script ./scripts/helloworld.rhai --analysis
监控ZBUS提交
为了验证和调试您的网关,您可以在“监控模式”下运行zbusudg,在该模式下您订阅ZBUS上的键,并将该键接收的所有数据包输出到STDOUT。
zbusudg monitor
查询ZBUS上发现的指标的JSON RPC接口
您可以查询已发布在ZBUS上的指标。JSON RPC服务器正在监听ZBUS主题,以提交指标并存储所有发现的指标的最后128个实时值。默认情况下,JSON RPC服务器监听端口10060,但您可以使用CLI选项--api-listen重新定义它。您还可以使用CLI选项--zbus-key更改ZBUS的主题。JSON RPC api服务器启动如下:
zbusudg api
服务器公开以下方法
metrics - 接收发现的指标列表
此调用返回发布到指定主题的ZBUS上的发现的指标列表。
curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"id","method":"metrics","params":[]}' http://127.0.0.1:10060
示例结果将是
{"jsonrpc":"2.0","result":["zbus/metric/v2/local/agent.ping","zbus/metric/v2/local/net.if.in/enp0s3","zbus/metric/v2/local/net.if.in/enp0s3/dropped","zbus/metric/v2/local/net.if.in/enp0s3/errors","zbus/metric/v2/local/net.if.out/enp0s3","zbus/metric/v2/local/net.if.out/enp0s3/dropped","zbus/metric/v2/local/net.if.out/enp0s3/errors","zbus/metric/v2/local/proc.num","zbus/metric/v2/local/proc.num/run","zbus/metric/v2/local/system.cpu.intr","zbus/metric/v2/local/system.cpu.load/all/avg1","zbus/metric/v2/local/system.cpu.load/all/avg15","zbus/metric/v2/local/system.cpu.load/all/avg5","zbus/metric/v2/local/system.cpu.switches","zbus/metric/v2/local/system.cpu.util","zbus/metric/v2/local/system.cpu.util/guest","zbus/metric/v2/local/system.cpu.util/guest_nice","zbus/metric/v2/local/system.cpu.util/idle","zbus/metric/v2/local/system.cpu.util/interrupt","zbus/metric/v2/local/system.cpu.util/iowait","zbus/metric/v2/local/system.cpu.util/nice","zbus/metric/v2/local/system.cpu.util/softirq","zbus/metric/v2/local/system.cpu.util/steal","zbus/metric/v2/local/system.cpu.util/system","zbus/metric/v2/local/system.cpu.util/user","zbus/metric/v2/local/system.localtime","zbus/metric/v2/local/system.swap.size/free","zbus/metric/v2/local/system.swap.size/pfree","zbus/metric/v2/local/system.swap.size/total","zbus/metric/v2/local/system.uptime","zbus/metric/v2/local/system.users.num","zbus/metric/v2/local/vfs.dev.queue_size/sda","zbus/metric/v2/local/vfs.dev.read.await/sda","zbus/metric/v2/local/vfs.dev.read.rate/sda","zbus/metric/v2/local/vfs.dev.read.time.rate/sda","zbus/metric/v2/local/vfs.dev.util/sda","zbus/metric/v2/local/vfs.dev.write.await/sda","zbus/metric/v2/local/vfs.dev.write.rate/sda","zbus/metric/v2/local/vfs.dev.write.time.rate/sda","zbus/metric/v2/local/vfs.file.contents","zbus/metric/v2/local/vfs.fs.dependent.inode/\\/pfree","zbus/metric/v2/local/vfs.fs.dependent.inode/\\boot/pfree","zbus/metric/v2/local/vfs.fs.dependent.size/\\/pused","zbus/metric/v2/local/vfs.fs.dependent.size/\\/total","zbus/metric/v2/local/vfs.fs.dependent.size/\\/used","zbus/metric/v2/local/vfs.fs.dependent.size/\\boot/pused","zbus/metric/v2/local/vfs.fs.dependent.size/\\boot/total","zbus/metric/v2/local/vfs.fs.dependent.size/\\boot/used","zbus/metric/v2/local/vfs.fs.dependent/\\/data","zbus/metric/v2/local/vfs.fs.dependent/\\/readonly","zbus/metric/v2/local/vfs.fs.dependent/\\boot/data","zbus/metric/v2/local/vfs.fs.dependent/\\boot/readonly","zbus/metric/v2/local/vm.memory.size/available","zbus/metric/v2/local/vm.memory.size/pavailable","zbus/metric/v2/local/vm.memory.size/total","zbus/metric/v2/local/vm.memory.utilization","zbus/metric/v2/local/zabbix/connector_queue","zbus/metric/v2/local/zabbix/host/agent/available","zbus/metric/v2/local/zabbix/lld_queue","zbus/metric/v2/local/zabbix/preprocessing_queue","zbus/metric/v2/local/zabbix/process/alert/manager/avg/busy","zbus/metric/v2/local/zabbix/process/alert/syncer/avg/busy","zbus/metric/v2/local/zabbix/process/alerter/avg/busy","zbus/metric/v2/local/zabbix/process/availability/manager/avg/busy","zbus/metric/v2/local/zabbix/process/configuration/syncer/avg/busy","zbus/metric/v2/local/zabbix/process/connector/manager/avg/busy","zbus/metric/v2/local/zabbix/process/connector/worker/avg/busy","zbus/metric/v2/local/zabbix/process/discoverer/avg/busy","zbus/metric/v2/local/zabbix/process/escalator/avg/busy","zbus/metric/v2/local/zabbix/process/history/poller/avg/busy","zbus/metric/v2/local/zabbix/process/history/syncer/avg/busy","zbus/metric/v2/local/zabbix/process/housekeeper/avg/busy","zbus/metric/v2/local/zabbix/process/http/poller/avg/busy","zbus/metric/v2/local/zabbix/process/icmp/pinger/avg/busy","zbus/metric/v2/local/zabbix/process/lld/manager/avg/busy","zbus/metric/v2/local/zabbix/process/lld/worker/avg/busy","zbus/metric/v2/local/zabbix/process/odbc/poller/avg/busy","zbus/metric/v2/local/zabbix/process/poller/avg/busy","zbus/metric/v2/local/zabbix/process/preprocessing/manager/avg/busy","zbus/metric/v2/local/zabbix/process/preprocessing/worker/avg/busy","zbus/metric/v2/local/zabbix/process/proxy/poller/avg/busy","zbus/metric/v2/local/zabbix/process/self-monitoring/avg/busy","zbus/metric/v2/local/zabbix/process/service/manager/avg/busy","zbus/metric/v2/local/zabbix/process/task/manager/avg/busy","zbus/metric/v2/local/zabbix/process/timer/avg/busy","zbus/metric/v2/local/zabbix/process/trapper/avg/busy","zbus/metric/v2/local/zabbix/process/trigger/housekeeper/avg/busy","zbus/metric/v2/local/zabbix/process/unreachable/poller/avg/busy","zbus/metric/v2/local/zabbix/queue","zbus/metric/v2/local/zabbix/queue/10m","zbus/metric/v2/local/zabbix/rcache/buffer/pused","zbus/metric/v2/local/zabbix/tcache/cache/pitems","zbus/metric/v2/local/zabbix/tcache/cache/pmisses","zbus/metric/v2/local/zabbix/vcache/buffer/pused","zbus/metric/v2/local/zabbix/vcache/cache/hits","zbus/metric/v2/local/zabbix/vcache/cache/misses","zbus/metric/v2/local/zabbix/vcache/cache/mode","zbus/metric/v2/local/zabbix/wcache/history/pused","zbus/metric/v2/local/zabbix/wcache/index/pused","zbus/metric/v2/local/zabbix/wcache/trend/pused","zbus/metric/v2/local/zabbix/wcache/values","zbus/metric/v2/local/zabbix/wcache/values/float","zbus/metric/v2/local/zabbix/wcache/values/log","zbus/metric/v2/local/zabbix/wcache/values/not/supported","zbus/metric/v2/local/zabbix/wcache/values/str","zbus/metric/v2/local/zabbix/wcache/values/text","zbus/metric/v2/local/zabbix/wcache/values/uint"],"id":"id"}
last - 特定指标的最后一个接收值
此调用返回最后一个接收值
curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"id","method":"last","params":["zbus/metric/v2/local/system.uptime"]}' http://127.0.0.1:10060
将返回
{"jsonrpc":"2.0","result":1809559,"id":"id"}
sample - 返回采样值
此调用将返回指标的最后一个128个或更少的采样值。
curl -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"id","method":"sample","params":["zbus/metric/v2/local/system.uptime"]}' http://127.0.0.1:10060
将返回
{"jsonrpc":"2.0","result":[1808809,1808839,1808869,1808899,1808929,1808959,1808989,1809019,1809049,1809079,1809109,1809139,1809169,1809199,1809229,1809259,1809289,1809319,1809350,1809380,1809409,1809439,1809469,1809499,1809529,1809559,1809589],"id":"id"}
实时指标计算
如果您想启用实时指标计算,可以使用--analysis CLI参数激活通用数据网关(ZBUSUDG)的“分析”模式。此模式允许ZBUSUDG在收集遥测数据的同时执行实时统计计算和预测。ZBUSUDG将收集最新的128个浮点型遥测样本。然后,它将使用统计数据属性(如平均值、最大值、最小值、方差、标准差、统计振荡、统计时间序列预测、使用统计分析的异常检测、样本中的突破和马尔可夫链预测)增强相关指标。
实时日志分析
如果您通过CLI选项--logs-analysis,您将启动日志分析线程,并将所有日志遥测数据增强到日志分析数据中。
{
"body": {
"details": {
"destination": "zbus/log/syslog",
"details": {
"analytical_data": {
"category": "ssh"
},
"contentType": 2,
"data": "syslog[85654]: Failed password from root",
"detailType": ""
},
"origin": "home.lan",
"properties": {
"syslog_appname": "unknown",
"syslog_facility": 0,
"syslog_procid": "unknown",
"syslog_severity": 7,
"syslog_version": 0,
"timestamp": 1718680671000000000,
"zabbix_item": "log[/var/log/syslog]"
}
}
},
"headers": {
"compressionAlgorithm": null,
"cultureCode": null,
"encryptionAlgorithm": null,
"messageType": "telemetry",
"route": "local",
"streamName": "local",
"version": "v2"
},
"id": "Ez2JWwSDsOZN-74gPF6dr"
}
实时Zabbix警报接收
ZBUSUDG可以接收并将Zabbix警报作为遥测项发布到ZBUS通用遥测总线,从而实现“警报也是遥测数据”的理念。您可以启动警报接收器
zbusudg alerts
然后您可以从通用遥测总线接收警报
zbusdg gateway --stdout --pretty --zbus-catcher --zbus-subscribe-key events
这是警报的示例
{
"body": {
"details": {
"destination": "/events",
"details": {
"contentType": 3,
"data": 1,
"detailType": ""
},
"origin": "home.lan",
"properties": {
"groups": [
"Linux servers"
],
"name": "SLA triggered",
"tags": [
{
"tag": "SLA",
"value": "TEST"
}
],
"zabbix_clock": 1719087396,
"zabbix_eventid": 81,
"zabbix_host_name": [
{
"host": "test_host",
"name": "test_host"
}
],
"zabbix_ns": 170124227
}
}
},
"headers": {
"compressionAlgorithm": null,
"cultureCode": null,
"encryptionAlgorithm": null,
"messageType": "event",
"route": "local",
"streamName": "local",
"version": "v2"
},
"id": "iZ6qykdOkpDoRK10rM9Wp"
}
依赖项
~69–105MB
~2M SLoC