简介
本文档介绍新的统一日志记录增强功能,用于提供收集和管理系统跟踪日志的无缝体验。
概述
实用目的:
- 故障排除。当机箱遇到问题时,跟踪文件中的数据对于识别和解决问题非常宝贵。
- 调试。跟踪文件的输出可为用户提供更精细的系统操作和操作视角。
工作方式
- 跟踪功能可记录机箱内发生的内部事件的详细信息。定期生成并刷新包含模块的完整跟踪输出的跟踪文件,并将这些文件保存在tracelog目录中。
- 您可以释放文件系统上的空间。跟踪文件可以从此目录中删除,不会影响设备的性能。
- 您可以将跟踪日志传输到备用位置。您可以使用FTP、TFTP等来复制文件以分析它们,或者将它们上传到通过技术支持中心(TAC)打开的案例中。
- 不能禁用跟踪日志,但可以更改跟踪级别,以确定要为每个模块收集多少信息。
跟踪级别
跟踪级别决定跟踪缓冲区或文件中保留的信息量。接下来是所有可用的跟踪级别,并说明在每个级别上记录的消息类型。
Emergency—>系统不稳定/不可用。
错误—>导致功能轻微损失,但不自动解决的事件,代表无法立即影响操作但将来可能会造成后果的意外问题。
警告—>一种可能会自动解决的问题,或者一种会导致功能丢失的情况(如果没有及时调查和解决)。
注意—>为模块设置的标准日志级别。此级别捕获系统中发生的重要事件。
Info ->仅信息性消息。提供与系统或其功能相关的重大事件的其他信息。
Debug—>提供调试日志。
Verbose ->提供二级调试日志。
Noise ->记录的可能消息的最大数量。
查看当前跟踪级别
您可以使用命令show platform software trace level查看和更改任何模块的跟踪级别。
此命令显示活动RP上转发管理器进程的跟踪级别。
Router#show platform software trace level forwarding-manager rp active
这是输出:
Module Name Trace Level
-----------------------------------------------
acl Notice
active-identity Notice
alg Notice
appnav-controller Notice
aps Notice
bcrpgc Informational
bfd Notice
bier Notice
修改跟踪级别
您可以修改特定模块或流程中所有模块的跟踪级别。为此,您可以使用命令set platform software trace。
此命令set platform software trace chassis-manager f0 cman_fp warning将插槽0中ESP的机箱管理器中的cman_fp跟踪级别更改为warning level。
您可以使用此命令show platform software trace level chassis-manager f0验证更改
这是输出:
Module Name Trace Level
-----------------------------------------------
bcrpgc Informational
bipc Notice
bsignal Notice
btrace Notice
btrace_ra Notice
cdllib Notice
chasfs Notice
cman_fp Warning
新跟踪选项
从16、8开始,思科推出了Unified Logging增强功能。目标是在IOS日志记录和其他进程日志记录系统之间为用户创建无缝的日志记录体验。来自两个系统的日志可以合并并按时间顺序显示,这使您更易于对系统问题进行故障排除。
显示不同进程的Tracelogs
命令show logging process可用于显示指定进程生成的跟踪日志的内容。输出中可以包含来自缓冲区和tracelogs目录的日志。
还支持部分进程名称,进程名称被接受为单词解析器。
注意:进程名称必须与tracelog的名称匹配(部分或完全),否则,可能会发生不匹配,从而导致不显示跟踪。
命令show logging process fman可以组合fman-rp和fman-fp日志。
Router#show logging process fman
Displaying logs from the last 0 days, 0 hours, 10 minutes, 0 seconds
executing cmd on chassis local ...
Unified Decoder Library Init .. DONE
Found 1 UTF Streams
2024/05/22 19:01:01.347466887 {fman_rp_R0-0}{255}: [source] [11941]: (ERR): ipc(mqipc/iosd/iosd-fman):Unable to open config channel to source
2024/05/22 19:00:50.246774567 {fman_fp_image_F0-0}{255}: [btrace] [13616]: (note): Btrace started for process fman_fp_image_pman ID 13616 with 512 modules
2024/05/22 19:00:50.246777079 {fman_fp_image_F0-0}{255}: [btrace] [13616]: (note): File size max used for rotation of tracelogs: 8192
执行多进程支持
现在,“show logging process”CLI命令允许您使用“process”关键字指定多个进程名称,以逗号分隔。合并的tracelog仅显示来自指定进程(例如sman和ios进程)的日志。
Router#show logging process sman,ios
executing cmd on chassis 1 ...
Collecting files on current[1] chassis.
时间窗口选项
如果配置了任何时间戳,则所有跟踪都可以在本地时区具有时间戳。如果没有,timestamps在“协调世界时”(UTC)中使用,但您可以使用set logging timezone <local命令在Local和UTC之间切换日志的时区 | UTC>。
默认情况下,show logging CLI命令仅显示当前时间的最后10分钟日志。
start last关键字可用于根据个人需要扩展时间窗口。
Router#show logging process btman start last ?
<0-4294967295> interval (default seconds)
boot system boot time
clear display all logs since last "clear logging"
marker selects latest matching marker from list to start displaying
logs from
注意:如果从上一个命令中选择一个数值,则可以指定天、小时、分钟或秒作为下一个选项。
添加了end last关键字选项,以与start last一起使用,指定时间窗口的结束。当同时使用start last和end last选项时,仅收集窗口内的日志。如果没有end last选项,日志收集将默认为当前时间作为结束时间。
下面是设置过去两小时和过去一小时之间的窗口的示例:
Router#show logging process btman start last 2 hours end last 1 hours
Displaying logs from the last 0 days, 2 hours, 0 minutes, 0 seconds
End time set to show logs before last 0 days, 1 hours, 0 minutes, 0 seconds
executing cmd on chassis 1 ...
Collecting files on current[1] chassis.
在特定日志级别下显示日志
只能显示特定级别的日志:
Router#show logging process wncd level ?
debug Debug messages
error Error messages
info Informational messages
notice Notice messages
verbose Verbose debug messages
warning Warning messages
下面是错误级别通知下的日志按钮示例:
Router#show logging process btman level notice
Logging display requested on 2024/07/24 06:20:23 (UTC) for Hostname: [Router], Model: [ASR1002-HX ], Version: [17.12.03a], SN: [JAD22460SN9], MD_SN: [FXS2223Q74M]
Displaying logs from the last 0 days, 0 hours, 10 minutes, 0 seconds
executing cmd on chassis local ...
Unified Decoder Library Init .. DONE
Found 1 UTF Streams
2024/07/24 06:10:59.533374335 {btman_R0-0}{255}: [utm_main] [5809]: (note): Inserted UTF(2) HT(old):droputil_R0-0[13] lnode /tmp/rp/trace/droputil_R0-0.6823_63.20240724061059.bin PID:6823
2024/07/24 06:10:59.695395289 {btman_R0-0}{255}: [utm_wq] [5809:15578]: (note): Inline sync, enqueue BTF message flags:0x1, PID:15578 BTF:/tmp/rp/trace/droputil_R0-0.6823_62.20240724060959.bin
显示来自时间戳的日志
您可以通过UTC显示来自特定时间戳的日志,如“2017/02/10 14:41:50.849425”。下面是一个示例:
Router#show logging process wncd start timestamp "2024/07/24 05:36:45.849425"
Logging display requested on 2024/07/24 06:39:15 (UTC) for Hostname: [Router], Model: [ASR1002-HX ], Version: [17.12.03a], SN: [JAD22460SN9], MD_SN: [FXS2223Q74M]
executing cmd on chassis local ...
Unified Decoder Library Init .. DONE
Found 1 UTF Streams
Filter policy: Done with UTM processing
显示两个时间戳之间的日志
可以通过添加开始时间戳和结束时间戳来显示时间窗口之间的跟踪日志。以下示例包含1小时的维护时段:
Router#show logging process wncd start timestamp "2024/07/24 05:36:45.849425" end timestamp "2024/07/24 06:36:45.849425"
Logging display requested on 2024/07/24 06:39:15 (UTC) for Hostname: [Router], Model: [ASR1002-HX ], Version: [17.12.03a], SN: [JAD22460SN9], MD_SN: [FXS2223Q74M]
executing cmd on chassis local ...
Unified Decoder Library Init .. DONE
Found 1 UTF Streams
Filter policy: Done with UTM processing
执行实时日志记录
您可以监控为进程或配置文件实时生成的日志。日志在生成时显示。
Router#monitor logging process cman ?
<0-25> instance number
filter specify filter for logs
internal select all logs. (Without the internal keyword only customer
curated logs are displayed)
level select logs above specific level
metadata CLI to display metadata for every log message
module select logs for specific modules
提示: 要退出或退出实时日志记录模式,请发出CTRL-C。
使用预定义的日志配置文件
实时日志记录提供可轻松应用的内置配置文件。这使用户无需熟悉构成该功能的基础进程日志文件。支持的配置文件包括all、file、wireless、sdwan、netconf-yang、restconf、install、hardware-diagnostics。
配置文件可与show logging或monitor logging命令一起使用。
注意:show logging profile选项仅显示来自缓冲区的日志,不包括来自tracelogs目录的日志。
SCP_Test#show logging profile ?
all all processes
file show logs for specific profile file
hardware-diagnostics hardware diagnostics specific processes
install Install specific processes
netconf-yang netconf-yang specific processes
restconf restconf specific processes
sdwan SDWAN specific processes
wireless Wireless specific processes
Router#monitor logging profile ?
all all processes
file show logs for specific profile file
hardware-diagnostics hardware diagnostics specific processes
install Install specific processes
netconf-yang netconf-yang specific processes
restconf restconf specific processes
sdwan SDWAN specific processes
wireless Wireless specific processes
在17.12+中,统计信息默认包含在“show logging <process/profile/file> ..”的末尾。 Stats显示每个严重性级别解码的跟踪消息数量已添加到现有解码器统计信息。级别计数仅用于已渲染的跟踪。
2024/07/24 04:26:41.710239127 {btman_R0-0}{255}: [utm_wq] [5806:15568]: (note): Inline sync, enqueue BTF message flags:0x1, PID:15568 BTF:/tmp/rp/trace/IOSRP_R0-0.3437_2.20240724042222.bin
2024/07/24 04:26:41.759114843 {btman_R0-0}{255}: [utm_wq] [5806]: (note): utm delete /tmp/rp/trace/IOSRP_R0-0.3437_2.20240724042222.bin
===========================================================
======= Unified Trace Decoder Information/Statistics ======
===========================================================
----------------- Decoder Input Information ---------------
===========================================================
Num of Unique Streams .. 1
Total UTF To Process ... 1
Total UTM To Process ... 89177
UTM Process Filter ..... btman
MRST Filter Rules ...... 1
===========================================================
----------------- Decoder Output Information --------------
===========================================================
First UTM TimeStamp ............... 2024/07/24 02:51:45.623542304
Last UTM TimeStamp ................ 2024/07/24 04:26:48.710794233
UTM [Skipped / Rendered / Total] .. 89047 / 130 / 89177
UTM [ENCODED] ..................... 130
UTM [PLAIN TEXT] .................. 0
UTM [DYN LIB] ..................... 0
UTM [MODULE ID] ................... 0
UTM [TDL TAN] ..................... 0
UTM [APP CONTEXT] ................. 0
UTM [MARKER] ...................... 0
UTM [PCAP] ........................ 0
UTM [LUID NOT FOUND] .............. 0
UTM Level [EMERGENCY / ALERT / CRITICAL / ERROR] .. 0 / 0 / 0 / 0
UTM Level [WARNING / NOTICE / INFO / DEBUG] ....... 0 / 130 / 0 / 0
UTM Level [VERBOSE / NOISE / INVALID] ............. 0 / 0 / 0
===========================================================
将日志输出发送到文件
可以使用to-file关键字使用show logging命令的输出创建一个文件。此示例说明如何将进程btman的跟踪日志发送到bootflash文件系统中名为btman_log.txt的文件:
Router#show logging process btman to-file bootflash:btman_log.txt
Logging display requested on 2024/07/25 03:49:41 (UTC) for Hostname: [Router], Model: [ASR1006-X ], Version: [17.09.05a], SN: [FXS221200GH], MD_SN: [FXS2221Q0EL]
Displaying logs from the last 0 days, 0 hours, 10 minutes, 0 seconds
executing cmd on chassis local ...
Files being merged in the background, please check [/bootflash/btman_log.txt] output file
Unified Decoder Library Init .. DONE
unified trace decoder estimates: [1] number of files, [139913] number of messages
that may be processed. Use CTRL+SHIFT+6 to break.
Found 1 UTF Streams
2024-07-25 03:49:41.694987 - unified trace decoder estimate: processed 5%
2024-07-25 03:49:41.701433 - unified trace decoder estimate: processed 10%
2024-07-25 03:49:41.707803 - unified trace decoder estimate: processed 15%
2024-07-25 03:49:41.714185 - unified trace decoder estimate: processed 20%
2024-07-25 03:49:41.720592 - unified trace decoder estimate: processed 25%
2024-07-25 03:49:41.726951 - unified trace decoder estimate: processed 30%
2024-07-25 03:49:41.733306 - unified trace decoder estimate: processed 35%
2024-07-25 03:49:41.739734 - unified trace decoder estimate: processed 40%
2024-07-25 03:49:41.746114 - unified trace decoder estimate: processed 45%
2024-07-25 03:49:41.752462 - unified trace decoder estimate: processed 50%
2024-07-25 03:49:41.758864 - unified trace decoder estimate: processed 55%
2024-07-25 03:49:41.765225 - unified trace decoder estimate: processed 60%
2024-07-25 03:49:41.771582 - unified trace decoder estimate: processed 65%
2024-07-25 03:49:41.777968 - unified trace decoder estimate: processed 70%
2024-07-25 03:49:41.784330 - unified trace decoder estimate: processed 75%
2024-07-25 03:49:41.790693 - unified trace decoder estimate: processed 80%
2024-07-25 03:49:41.797099 - unified trace decoder estimate: processed 85%
2024-07-25 03:49:41.803462 - unified trace decoder estimate: processed 90%
2024-07-25 03:49:41.811411 - unified trace decoder estimate: processed 95%
2024-07-25 03:49:41.822322 - unified trace decoder estimate: processed 100%
2024-07-25 03:49:41.822335 - unified trace decoder : processing complete Result:[Success]
您可以使用命令dir bootflash验证文件是否已创建,然后按如下方式过滤文件的名称:
Router#dir bootflash: | include btman_log.txt
17 -rw- 26939 Jul 25 2024 03:49:41 +00:00 btman_log.txt