在 Junos 中配置 NETCONF 代理遥测传感器
使用 Junos 遥测流处理,您可以通过 XML 代理功能将任何可用状态信息转换为遥测传感器。NETCONF XML 管理协议和 Junos XML API 完全记录每个受支持的 Junos OS 操作请求的所有选项。配置 XML 代理传感器后,可以通过 NETCONF“获取”远程过程调用 (RPC) 访问数据。
此任务介绍如何流传输 Junos OS 操作模式命令的输出。
建议不要使用映射到具有大量或详细输出的 Junos OS 操作命令或输出速度较慢的 YANG 文件。在 YANG 文件中应避免延迟明显的命令。包括此类命令会影响其他 xmlproxyd 传感器以及 xmlproxyd 的性能。
某些操作模式命令的输出是动态的,其详细程度取决于配置和硬件等因素。此类命令的示例包括 、 、 show route
show arp
、 show bfd
show bgp
和show ddos-protection
的任何变体show interfaces
。
要检查命令的详细程度,请发出 command-name| display xml | count 命令。如果行计数超过 4000 行的值,则不建议将命令用于 XML 代理流。此值更接近于基于内部基础衬里的近似值。它可以减少取决于各种因素,如设备类型、设备的处理能力和现有 CPU 负载。因此,需要根据设备的性能来明智地使用此功能。
在使用映射到 Junos OS 或 Junos OS 演化操作模式命令 command-name的 YANG 文件之前,您可以发出命令 | display xml ,以验证命令是否生成有效的 XML 输出,并且不包含无效的标记、数据或格式。
使用映射到详细命令的 YANG 文件可产生以下一项或多项:
-
xmlproxyd 进程 CPU 利用率仍然很高。如果启用了 xmlproxyd 跟踪,则 CPU 利用率会更高。
-
xmlproxyd 进程内存利用率的增加。
-
xmlproxyd 进程状态可能会显示
sbwait
,表明命令输出是详细的,并且 xmlproxyd 花费大量时间阅读命令的远程过程调用 (RPC) 输出。 -
xmlproxyd 传感器数据无法完成封装。
-
xmlproxyd 流传输传感器的部分或没有数据。
-
xmlproxy 会错过报告间隔周期。由于命令输出的详细输出,间隔开始重叠,从而导致 xmlproxyd 的传感器流数据变慢或延迟。
-
为详细命令的 RPC 提供服务的进程或应用程序在执行主要任务时可能会显示高 CPU 编号或延迟。当进程或应用程序忙于为具有详细输出的 RPC 提供服务时,会引发此行为。
这项任务需要具备以下要求:
-
运行 Junos OS 17.3R2 或更高版本的 MX 系列、vMX 系列或 PTX 系列路由器。
-
安装所需的网络代理软件包(network-agent-x86-32–17.4R1.16-C1.tgz 或更高版本)。
-
一个遥测数据接收器,如 OpenNTI,用于验证遥测传感器的正常运行。
在此任务中,您将流式传输 Junos OS 命令 show system users
的内容。
show system users(vMX 系列)
user@switch> show system users USER TTY FROM LOGIN@ IDLE WHAT user1 pts/0 172.31.12.36 12:40PM 39 -cli (cli) user2 pts/1 172,16.03.25 3:01AM - -cli (cli)
除了当前登录的预期用户列表外, show system users
输出还提供 1、5 和 15 分钟的平均系统负载。您可以使用命令查看输出字段的 XML 标记,从而查找负载平均 show system users | display xml
数。请参阅 <load-average-1>
、 <load-average-5>
和 <load-average-15>
下面的 XML 标记输出。
user@switch> show system users | display xml <rpc-reply xmlns:junos="http://xml.juniper.net/junos/17.4R1/junos"> <system-users-information xmlns="http://xml.juniper.net/junos/17.4R1/junos"> <uptime-information> <date-time junos:seconds="1520170982">1:43PM</date-time> <up-time junos:seconds="86460">1 day, 40 mins</up-time> <active-user-count junos:format="2 users">2</active-user-count> <load-average-1>0.70</load-average-1> <load-average-5>0.58</load-average-5> <load-average-15>0.55</load-average-15> <user-table> <user-entry> <user>root</user> <tty>pts/0</tty> <from>172.21.0.1</from> <login-time junos:seconds="1520167202">12:40PM</login-time> <idle-time junos:seconds="0">-</idle-time> <command>cli</command> </user-entry> <user-entry> <user>mwiget</user> <tty>pts/1</tty> <from>66.129.241.10</from> <login-time junos:seconds="1520170862">1:41PM</login-time> <idle-time junos:seconds="60">1</idle-time> <command>cli</command> </user-entry> </user-table> </uptime-information> </system-users-information> <cli> <banner></banner> </cli> </rpc-reply>
uptime-information
上述输出中显示的标记是一个容器,其中包含叶,例如date-time
、、up-time
active-user-count
和load-average-1
。下面是此容器的示例 YANG 文件:
container uptime-information { dr:source "uptime-information"; // Exact name of the XML tag leaf date-time { // YANG model leaf type string; // Type of value dr:source date-time; // Exact name of the XML tag } leaf up-time { // YANG model leaf type string; // Type of value dr:source up-time; // Exact name of the XML tag } leaf active-user-count { // YANG model leaf type int32; // Type of value dr:source active-user-count; // Exact name of the XML tag } leaf load-average-1 { // YANG model leaf type string; // Type of value dr:source load-average-1; // Exact name of the XML tag } ...
该 uptime-information
标记还有另一个名为的容器 user-table
,其中包含一个用户条目列表。
下面是此容器的示例 YANG 文件:
container user-table { // "user-table" container which contains list of user-entry dr:source "user-table"; // Exact name of the XML tag list user-entry { // "user-entry" list which contains the users' details in form of leafs key "user"; // Key for the list "user-entry" which is a leaf in the list "user-entry" dr:source "user-entry"; // Source of the list "user-entry" which is the exact name of the XML tag leaf user { // YANG model leaf dr:source user; // A leaf in the list "user-entry", exact name of the XML tag type string; // Type of value } leaf tty { // YANG model leaf dr:source tty; // A leaf in the list "user-entry", exact name of the XML tag type string; // Type of value } leaf from { // YANG model leaf dr:source from; // A leaf in the list "user-entry", exact name of the XML tag type string; // Type of value } leaf login-time { // YANG model leaf dr:source login-time; // A leaf in the list "user-entry", exact name of the XML tag type string; // Type of value } leaf idle-time { // YANG model leaf dr:source idle-time; // A leaf in the list "user-entry", exact name of the XML tag type string; // Type of value } leaf command { // YANG model leaf dr:source command; // A leaf in the list "user-entry", exact name of the XML tag type string; // Type of value } } }
创建用户定义的 YANG 文件
YANG 文件定义要执行的 Junos CLI 命令、传感器位于下的资源路径以及从匹配的 XML 标记中获取的键值对。
Junos OS 的自定义 YANG 文件符合 RFC 6020 YANG 1.0 YANG - 网络配置协议 (NETCONF) 和 RFC 7950 YANG 1.1 数据建模语言中定义的 YANG 语言语法。配置 XML 代理的文件中需要包含某些指令。
xmlproxyd
要使用(守护程序)进程转换遥测数据,请创建一个render.yang
文件。在此文件中,dr:command-app
将设置为xmlproxyd
。
XML 代理 YANG 文件名和模块名称必须以 xmlproxyd_
:
对于 XML 代理 YANG 文件名,添加扩展名
.yang
,例如xmlproxyd_sysusers.yang
对于模块名称,使用不带扩展名
.yang
的文件名,例如xmlproxyd_sysusers
为了简化 YANG 文件的创建,最简单的方法是修改工作示例。
在 Junos 中加载 Yang 文件
YANG 文件完成后,上传 YANG 文件并验证是否已创建模块。
收集传感器数据
使用您最喜欢的收集器从设备中提取新创建的遥测传感器数据。
启动传感器之前考虑资源限制:
- 避免为多个 XML 代理传感器指定相同的报告间隔。
- 对于运行 Junos OS 演化型的 PTX10008 路由器,对于遥测 RPC,每个路由器连接的收集器不要超过 10 个。
- 由于 xmlproxyd 执行 XML 和文本处理,设备只能包含在 CPU 利用率范围内执行的 XML 代理传感器。
以下说明使用收集器 jtimon。有关 jtimon 设置的信息,请参阅 Junos 遥测接口客户端。
如果传感器已订阅并配置了重复订阅,则收集器与设备之间的连接将会关闭,并显示错误消息 AlreadyExists
。
安装用户定义的 YANG 文件
要为 Junos 遥测接口的 XML 代理添加、验证、修改或删除用户定义的 YANG 文件,请 request system yang
从操作模式下使用命令集:
另请参阅
遥测传感器故障排除
问题
描述
使用以下方法对用户定义的遥测传感器进行故障排除:
为您的 gRPC 请求来自的接口执行 tcpdump(对于此任务,使用了接口
fxp0
)。user@switch>monitor traffic interface fxp0 no-resolve matching "tcp port 32767"
使用 set services analytics traceoptions flag xmlproxy 命令启用追踪选项。检查日志文件,
xmlproxyd
以确认是否发送 CLI 命令的 RPC 以及是否已收到响应:
show log xmlproxyd发出命令以显示 xmlproxyd 日志。字段
xmlproxy_execute_cli_command:
的值指示 RPC 是否已发送。字段xmlproxy_build_context
的值表示命令。
user@switch>show log xmlproxyd Mar 4 18:52:46 vmxdockerlight_vmx1_1 clear-log[52495]: logfile cleared Mar 4 18:52:51 xmlproxy_telemetry_start_streaming: sensor /junos/system-users-information/ Mar 4 18:52:51 xmlproxy_build_context: command show system users merge-tag: Mar 4 18:52:51 <command format="xml">show system users</command> Mar 4 18:52:51 xmlproxy_execute_cli_command: Sent RPC.. Mar 4 18:52:51 <system-users-information xmlns="http://xml.juniper.net/junos/17.4R1/junos" xmlns:junos="http://xml.juniper.net/junos/*/junos"> <uptime-information> <date-time junos:seconds="1520189571"> 6:52PM </date-time> <up-time junos:seconds="107400"> 1 day, 5:50 </up-time> <active-user-count junos:format="1 users"> 1 </active-user-count> <load-average-1> 0.94 </load-average-1> <load-average-5> 0.73 </load-average-5> <load-average-15> 0.65