博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Timestamping Linux kernel printk output in dmesg for fun and profit
阅读量:4136 次
发布时间:2019-05-25

本文共 2924 字,大约阅读时间需要 9 分钟。

转自:

http://www.digitalprognosis.com/linuxtips/timestamping-linux-kernel-printk-output-in-dmesg-for-fun-and-profit/

 

 

 

Timestamps are a wonderful thing. When you have systems with an uptime of hundreds of days or more, knowing when an event happened can go a long way. This post will show you how to enable and use Linux kernel printk timestamps effectively. Printk is a Linux kernel function used to send messages to the kernel log ring buffer. This is most commonly read with .

Enable CONFIG_PRINTK_TIME=y if you are building a custom kernel and want this feature. Most major Linux distributions enable this by default. Verify your kernel has printk time enabled like this:

jeff@beastmaster:~$ grep CONFIG_PRINTK_TIME /boot/config-$(uname -r)CONFIG_PRINTK_TIME=yjeff@beastmaster:~$ head -n1 /etc/issueUbuntu 8.10 /n /l

Ubuntu enables timestamps by default. Some distributions such as configure their kernel to enable CONFIG_PRINTK_TIME=y, but don't enable timestamps by default. Setting it up requires some changes to the bootloader and a reboot. For CentOS / RHEL just add "time=1" to the kernel command line in /boot/grub/menu.lst and reboot.

The "time" kernel boot option  from the 2.6.25 kernel and superseded by "printk.time".

Enough background, lets look at how this is useful and go from there. We'll first look for a disk error.

jeff@desktopmonster:~/bin$ dmesg | grep 'Buffer I/O' | tail -n 1[337567.060046] Buffer I/O error on device sr0, logical block 0

337567.060046 is the time in seconds.nanoseconds in relation to system uptime the Buffer I/O error happened. Breaking down exactly when this happened requires a bit of math. There are 60 seconds in 1 minute, 60 minutes in 1 hour, and 24 hours in 1 day. Figuring out when this error occurred is simple with a bit of math and our good friend . The first field of /proc/uptime is the system uptime according to in the format of seconds.microseconds. The key is to subtract the two and divide by the time you want.

jeff@desktopmonster:~/bin$ dmesg | grep 'Buffer I/O' |  tail -n 1 | egrep -o '[0-9]+/.[0-9]+'337567.060046jeff@desktopmonster:~/bin$ echo "$(awk '{print $1}' /proc/uptime) - $(dmesg | grep 'Buffer I/O' |  tail -n 1 | egrep -o '[0-9]+/.[0-9]+')" | bc # Seconds103376.359954jeff@desktopmonster:~/bin$ echo "($(awk '{print $1}' /proc/uptime) - $(dmesg | grep 'Buffer I/O' |  tail -n 1 | egrep -o '[0-9]+/.[0-9]+')) / 60" | bc # Minutes1723jeff@desktopmonster:~/bin$ echo "($(awk '{print $1}' /proc/uptime) - $(dmesg | grep 'Buffer I/O' |  tail -n 1 | egrep -o '[0-9]+/.[0-9]+')) / 60 / 60" | bc # Hours28jeff@desktopmonster:~/bin$ echo "($(awk '{print $1}' /proc/uptime) - $(dmesg | grep 'Buffer I/O' |  tail -n 1 | egrep -o '[0-9]+/.[0-9]+')) / 60 / 60 / 24" | bc # Days1

Using this info we see that the error happened 28 hours ago. Now you can go complain to your datacenter technician for bumping your server when running new cables to another server.

转载地址:http://krmvi.baihongyu.com/

你可能感兴趣的文章
CentOS7 安装MySQL 5.6.43
查看>>
使用Java 导入/导出 Excel ----Jakarta POI
查看>>
本地tomcat 服务器内存不足
查看>>
IntelliJ IDAE 2018.2 汉化
查看>>
基于S5PV210的uboot移植中遇到的若干问题记录(一)DM9000网卡移植
查看>>
Openwrt源码下载与编译
查看>>
我和ip_conntrack不得不说的一些事
查看>>
Linux 查看端口使用情况
查看>>
文件隐藏
查看>>
两个linux内核rootkit--之二:adore-ng
查看>>
两个linux内核rootkit--之一:enyelkm
查看>>
关于linux栈的一个深层次的问题
查看>>
rootkit related
查看>>
桥接模式--2
查看>>
桥接模式--3
查看>>
桥接模式--4
查看>>
最长回文子串算法-- Manacher算法--O(n)
查看>>
线程同步
查看>>
常量指针 指针常量
查看>>
LIS 最长单调上升子序列
查看>>