Telegraf gNMI Listener 的 Nokia dial-out Telemetry 支持:GRPC 服务端实现与配置指南

发布时间:2026/9/14 19:24:34
Telegraf gNMI Listener 的 Nokia dial-out Telemetry 支持:GRPC 服务端实现与配置指南 Telegraf gNMI Listener 的 Nokia dial-out Telemetry 支持GRPC 服务端实现与配置指南【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf导读本文聚焦于 Telegraf 的 gnmi_listener 输入插件 中针对 Nokia诺基亚SR OS 设备的 dial-out telemetry拨号遥测支持。该功能通过一个由 nokia 子包实现的 gRPC 服务端接收 Nokia 设备主动推送的 gNMI SubscribeResponse 消息将设备遥测数据转化为 Telegraf 指标。读完本文你将理解 Nokia dial-out 协议的 gRPC 接口定义与Publish双向流处理逻辑、如何通过go generate更新 protobuf 与生成的 Go 代码、如何在 Telegraf 中配置[[inputs.gnmi_listener]]并启用 Nokia 协议以及 TLS 加密与常见排障策略。Nokia dial-out telemetry从设备主动推送到 Telegraf传统的 gNMI 采集采用dial-in拨入模式采集器作为 gNMI 客户端主动连接网络设备发起 Subscribe 订阅请求设备返回数据。而 Nokia SR OS 等设备支持的dial-out拨出模式则相反——设备作为 gNMI 客户端主动向预先配置好的采集端发起连接并持续推送遥测数据。正如 nokia/README.md 所述This package implements the GRPC server for Nokia devices to support dial-out telemetry available in Nokia SR OS (and potentially other) devices.即gnmi_listener的nokia子包在 Telegraf 侧扮演 gRPC服务端角色等待 Nokia 设备连接并将数据推送进来。这正是gnmi_listener被归类为service input的原因——它不是按固定interval主动轮询而是启动一个常驻服务监听端口等待外部事件设备推送发生。根据 service input 说明这类插件有两个关键差异全局或插件级别的interval设置可能不生效CLI 选项--test、--test-wait和--once可能不会为该插件产生输出。源码剖析Nokia gRPC 服务端的实现目录结构与核心文件plugins/inputs/gnmi_listener/ ├── gnmi_listener.go # 插件主入口负责启动 gRPC server ├── sample.conf # 插件样例配置嵌入为 SampleConfig ├── gnmi_protos/ # 通用 gNMI protobufgnmi.proto、gnmi_ext.proto └── nokia/ ├── README.md # Nokia 支持说明本文主题文档 ├── nokia-dialout-telemetry.proto # Nokia 定义的 gRPC 服务协议 ├── nokia-dialout-telemetry.pb.go # protoc 生成的协议代码 ├── nokia-dialout-telemetry_grpc.pb.go # protoc 生成的 gRPC 代码 └── server.go # gRPC 服务端实现协议定义nokia-dialout-telemetry.protoNokia 协议文件 定义了整个 dial-out 通信契约其核心内容如下syntax proto3; import gnmi.proto; package Nokia.SROS; option go_package github.com/influxdata/telegraf/plugins/inputs/gnmi_listener/nokia; service DialoutTelemetry { rpc Publish(stream gnmi.SubscribeResponse) returns (stream gnmi.SubscribeRequest); }关键信息服务名为DialoutTelemetry方法为Publish入参是stream gnmi.SubscribeResponse出参是stream gnmi.SubscribeRequest即双向流式 RPC——设备持续向服务端流式推送SubscribeResponse服务端则回送空的SubscribeRequest作为确认它复用了 OpenConfig 的标准gnmi.proto位于 gnmi_protos/说明 Nokia dial-out 推送的 payload 本质仍是标准 gNMI 消息只是传输方式由采集器拉取变成了设备推送。服务端实现server.goNokia 服务端实现 的核心逻辑清晰几个关键点如下//go:generate protoc --proto_path../gnmi_protos:. --go_out. --go-grpc_out. \ // --go_optpathssource_relative --go-grpc_optpathssource_relative \ // nokia-dialout-telemetry.protoserver结构体组合了UnimplementedDialoutTelemetryServer由 protoc 生成保证向前兼容并持有一个common_gnmi.Handler——这是 Telegraf 统一处理 gNMI 消息、将SubscribeResponse转换为指标的核心处理器。Publish方法实现了完整的 dial-out 处理循环func (s *server) Publish(srv grpc.BidiStreamingServer[gnmi.SubscribeResponse, gnmi.SubscribeRequest]) error { ctx : srv.Context() for ctx.Err() nil { // Wait for data response, err : srv.Recv() ... // Determine the message source source : unknown if p, ok : peer.FromContext(ctx); ok { ... } // Call the handler s.handler.Process(s.acc, source, response) // Send an empty response if err : srv.Send(gnmi.SubscribeRequest{}); err ! nil { ... } } return nil }该循环的逻辑可概括为三步接收通过srv.Recv()阻塞等待设备推送的SubscribeResponse溯源从 gRPC 上下文peer.FromContext解析对端地址分别处理 TCP/UDP/IP 三种地址类型将来源 IP 作为source标记附加到指标上无法解析时回退为unknown处理与回执调用s.handler.Process(s.acc, source, response)将 gNMI 消息写入 Telegraf 指标管道并向设备回送一个空的SubscribeRequest作为流式确认。当Recv返回io.EOF设备正常关闭流或上下文取消时循环退出并返回nil其他错误则包装为aborted gNMI listener返回。插件主入口如何装配 Nokia 实现gnmi_listener.go 是插件的装配层Init()中Address默认值为localhost:57400Protocol为空时默认置为nokia目前nokia也是唯一合法取值其它值会返回invalid protocol错误若配置了 TLS 则通过grpc.Creds(credentials.NewTLS(...))装配到grpc.ServerOption最后创建统一的common_gnmi.Handler默认测量名为gnmiStart()中根据Protocol选择实现当前仅有nokia.New(acc, g.handler, g.Log)通过net.Listen(tcp, address)监听端口创建grpc.NewServer并调用impl.Register(g.server)注册服务随后在 goroutine 中ServeStop()调用GracefulStop()优雅停机Gather()为空实现数据完全来自设备推送。从源码结构可以推断serverImplementation接口Register(*grpc.Server)的设计为将来支持更多厂商的 dial-out 协议预留了扩展点。更新协议文件与重新生成 Go 代码Nokia 协议文件来源于 Nokia 官方仓库7x50_protobufsTelegraf 将其拷贝到 nokia/ 目录并受 Nokia 许可条款约束。当需要升级协议定义或重新生成 Go 代码时按 nokia/README.md 的说明在仓库根目录执行go generate即可根据server.go顶部的//go:generate指令重新运行protoc产出新的nokia-dialout-telemetry.pb.go与nokia-dialout-telemetry_grpc.pb.go。注意该命令要求环境中已安装protoc及protoc-gen-go、protoc-gen-go-grpc工具链且--proto_path指向gnmi_protos目录以解析gnmi.proto的 import。Telegraf 配置启用 Nokia dial-out 协议以下完整配置来自插件的 sample.conf可直接复制使用# gNMI dial-out telemetry plugin [[inputs.gnmi_listener]] ## Address and port of the gNMI GRPC server address localhost:57400 ## Protocol to use, available options: ## nokia -- Nokia SR OS dial-out protocol # protocol nokia ## Emit a metric for delete messages # emit_delete_metrics false ## Enable to get the canonical path as field-name # canonical_field_names false ## Remove leading slashes and dots in field-name # trim_field_names false ## Prefix tags from path keys with the path element # prefix_tag_key_with_path false ## Guess the path-tag if an update does not contain a prefix-path ## Supported values are ## none -- do not add a path tag ## common path -- use the common path elements of all fields in an update ## subscription -- use the subscription path # path_guessing_strategy none ## Vendor specific options ## This defines what vendor specific options to load. ## * Juniper Header Extension (juniper_header): some sensors are directly managed by ## Linecard, which adds the Juniper GNMI Header Extension. Enabling this ## allows the decoding of the Extension header if present. Currently this knob ## adds component, component_id sub_component_id as additional tags # vendor_specific [] ## YANG model paths for decoding IETF JSON payloads ## Model files are loaded recursively from the given directories. Disabled if ## no models are specified. # yang_model_paths [] ## Used for TLS server certificate authentication # tls_cert /path/to/certfile ## Used for TLS server certificate authentication # tls_key /path/to/keyfile ## Password for encrypted key files # tls_key_pwd ## CA certificates used for verifying client certificates # tls_allowed_cacerts [] ## List of ciphers to accept, by default all secure ciphers will be accepted ## Use all, secure and insecure to add all support ciphers, secure ## suites or insecure suites respectively. # tls_cipher_suites [secure] ## Minimal TLS version to accept by the server # tls_min_version TLS12 ## Maximum TLS version to accept by the server # tls_max_version ## Whitelist for certificate DNS names to accept # tls_allowed_dns_names []参数说明参数默认值作用addresslocalhost:57400gNMI gRPC 服务端监听地址与端口需与 Nokia 设备上配置的 dial-out 目标一致protocolnokia协议选择目前仅支持nokiaNokia SR OS dial-out 协议emit_delete_metricsfalse是否为 gNMI 的 delete 消息也生成指标canonical_field_namesfalse是否使用规范化路径作为字段名trim_field_namesfalse是否去除字段名开头的斜杠与点prefix_tag_key_with_pathfalse是否用路径元素为路径键标签加前缀path_guessing_strategynoneupdate 消息缺少 prefix-path 时的路径标签推断策略none不加path标签、common path取该 update 内所有字段的公共路径元素、subscription使用订阅路径vendor_specific[]厂商扩展选项如juniper_header解码 Juniper GNMI Header Extension附加component、component_id、sub_component_id标签yang_model_paths[]解码 IETF JSON payload 所需的 YANG 模型目录递归加载未指定则禁用tls_cert/tls_key空服务端 TLS 证书与私钥路径tls_key_pwd空加密私钥文件的密码tls_allowed_cacerts[]用于验证客户端证书的 CA 证书tls_cipher_suites[secure]接受的密码套件支持all、secure、insecure或具体套件名tls_min_version/tls_max_versionTLS12/ 空服务端接受的最低/最高 TLS 版本tls_allowed_dns_names[]允许的客户端证书 DNS 名称白名单需要说明的是emit_delete_metrics至yang_model_paths这些选项来源于嵌入在插件中的 handler.conf由统一的common_gnmi.HandlerConfig处理TLS 系列选项则由 common_tls.ServerConfig 提供并用于构建 gRPC 凭据。这些选项对所有使用该 Handler 的 gNMI 插件保持一致体现出 Telegraf 对协议处理逻辑的复用设计。支持的 Nokia 设备根据 gnmi_listener README 的说明nokia协议支持具备 dial-out telemetry 能力的 Nokia SR OS 平台包括7250 Interconnect Router (IXR)7450 Ethernet Service Switch (ESS)7750 Service Router (SR)7950 Extensible Routing System (XRS)Virtualized Service Router (VSR)TLS 安全传输mTLS 与单向 TLS 配置示例dial-out 场景下设备主动连入采集端网络边界与身份验证尤为重要。仓库测试用例给出了两种 TLS 配置范本单向 TLS服务端认证—— nokia_tls/telegraf.conf[inputs.gnmi_listener] ## Used for TLS server certificate authentication tls_cert ../../../testutil/pki/servercert.pem ## Used for TLS server certificate authentication tls_key ../../../testutil/pki/serverkey.pem双向 TLSmTLS—— nokia_mtls/testcases 中除了服务端证书外还通过tls_allowed_cacerts配置客户端证书校验、通过tls_allowed_dns_names校验客户端证书中的 DNS 名称实现设备身份的强认证。测试证书可参考仓库 testutil/pki/。生产环境中建议至少启用 TLS并在设备侧配置正确的服务端地址与 CA 信任关系对安全性要求高的场景使用 mTLS 校验每个拨入设备的身份。指标生成与输出示例当 gNMI 消息到达后每条 gNMI 消息会生成一个测量measurementSubscribeResponseUpdate 消息中的叶子leaf条目成为测量中的字段field叶子路径上的 PathElement key 则作为标签tag附加到字段上。上述 Handler 相关的路径与命名选项canonical_field_names、trim_field_names、prefix_tag_key_with_path、path_guessing_strategy等正是在这一环节发挥作用。以 OpenConfig 接口计数器遥测为例gnmi_listener README 给出的输出形态如下gnmi,pathopenconfig-interfaces:/interfaces/interface/state/counters,hostlinux,nameMgmtEth0/RP0/CPU0/0,source10.49.234.115,descr/descriptionFoo in-multicast-pkts0i,out-multicast-pkts0i,out-errors0i,out-discards0i,in-broadcast-pkts0i,out-broadcast-pkts0i,in-discards0i,in-unknown-protos0i,in-errors0i,out-unicast-pkts0i,in-octets0i,out-octets0i,last-clear2019-05-22T16:53:21Z,in-unicast-pkts0i 1559145777425000000可见测量名gnmi上同时带有path订阅路径、host、name接口名以及source由服务端从对端地址解析出的设备 IP等标签字段则对应接口计数器的各项数值。排障缺失path标签的处理部分设备如 Arista在 update 中省略 prefix 并直接在 update 内指定路径会导致生成指标缺少path标签。此时应设置path_guessing_strategy subscription以订阅路径作为path标签若设备完全省略 prefix则可改用path_guessing_strategy common path通过取 update 内所有字段路径的公共前缀来推断path标签。结合source标签可以快速定位来自哪台设备的数据异常。许可说明Nokia 协议文件及其生成的 Go 代码遵循 Nokia 的许可条款Nokia 保留规范的所有权与知识产权同时授予所有相关方非独占许可可在管理 Nokia 产品时免费使用和分发未经修改的规范副本须保留版权声明与许可文本规范按原样提供、不作任何明示或暗示的担保。详情见 nokia/README.md 的 License 一节。总结Telegraf 的gnmi_listener插件通过 nokia 子包为 Nokia SR OS 设备提供了开箱即用的 dial-out telemetry 采集能力设备作为客户端主动拨入Telegraf 侧运行 gRPC 双向流服务端接收SubscribeResponse统一交由common_gnmi.Handler转换为带path、source等标签的指标。配合go generate的协议更新机制、TLS/mTLS 安全配置、path_guessing_strategy排障手段以及可扩展的serverImplementation接口设计这套实现既务实又具备良好的演进空间是网络设备拨号遥测接入监控体系的可参考方案。进一步阅读gnmi_listener 插件 README、sample.conf、服务端实现、测试用例目录、通用 gNMI Handler 配置。【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考