在 Junos 中配置 NETCONF 代理遥测传感器
使用 Junos 遥测流,您可以通过 XML 代理功能将任何可用的状态信息转换为遥测传感器。NETCONF XML 管理协议和 Junos XML API 完整记录了每个受支持的 Junos OS 操作请求的所有选项。配置 XML 代理传感器后,可以通过 NETCONF“获取”远程过程调用 (RPC) 访问数据。
此任务说明如何流式传输 Junos OS 操作模式命令的输出。
建议不要使用映射到具有大量或详细输出的 Junos OS 操作命令的 YANG 文件,或者生成输出速度较慢的文件。应避免在 YANG 文件中使用具有明显延迟的命令。包含此类命令可能会影响其他 xmlproxyd 传感器以及 xmlproxy 的性能。
某些操作模式命令的输出是动态的,其详细程度取决于配置和硬件等因素。此类命令的示例包括 、 show route
show bfd
show arp
show bgp
和 show ddos-protection
的任何show interfaces
变体。
要检查命令的详细级别,请发出 command-name| display xml | count 命令。如果行数超过 4000 行的值,则不建议将该命令用于 XML 代理流式处理。此值更像是基于内部基线的近似值。根据各种因素,例如设备类型、设备的处理能力和现有的 CPU 负载,它可能会更少。因此,需要根据设备的性能明智地使用此功能。
在使用映射到 Junos OS 的 YANG 文件或 Junos OS 演化操作模式命令之前,可以发出命令 | display xml 来验证该命令command-name是否生成有效的 XML 输出,并且不包含无效的标记、数据或格式。
使用映射到详细命令的 YANG 文件会导致以下一项或多项:
-
xmlproxyd 进程 CPU 利用率仍然很高。如果 xmlproxyd 启用了跟踪,则 CPU 利用率甚至更高。
-
xmlproxyd 进程内存利用率增加。
-
xmlproxyd 进程状态可能显示
sbwait
,表示命令输出非常详细,并且 xmlproxyd 正在花费大量时间读取命令的远程过程调用 (RPC) 的输出。 -
xmlproxyd 传感器数据不会完成包装。
-
xmlproxyd 流传输传感器的部分数据或没有数据。
-
xmlproxyd 错过了报告间隔周期。由于命令的详细输出,间隔开始重叠,从而导致 xmlproxy 的传感器流数据变慢或延迟。
-
提供详细命令的 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
的内容。
显示系统用户(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 分钟的平均系统负载。您可以通过使用show system users | display xml
命令查看输出字段的 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) 的数据建模语言 (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