Linux的kern日志和demsg,Linux dmesg

引言

一直用 dmesg,但在服务器上查看时,时间戳不易读。

所以查下用什么方法让其变成 human readable.

dmesg 简介

dmesg - print or control the kernel ring buffer

dmesg is used to examine or control the kernel ring buffer.

The default action is to read all messages from kernel ring buffer.

终端输入 dmesg,可以看到每行最开始显示的是一个中括号,里面的数字为 timestamp,时间戳,

该时间指示的系统从开机到现在的运行时间,单位为秒。

dmesg 时间戳转换

1.dmesg -T 参数

-T, --ctime

Print human readable timestamps. The timestamp could be inaccurate!

The time source used for the logs is not updated after system SUSPEND/RESUME.

这个参数在较老版本的 util-linux 中并没有,还要注意这个时间可能不准确。

2. 使用命令或其他工具转换

使用 bash 命令转换:

date -d "1970-01-01 UTC`echo "$(date +%s)-$(cat /proc/uptime|cut -f 1 -d' ')+[dmesg显示的时间]"|bc `seconds"

当然还有其他工具,比如这个上 Python 写的pydmesg

3. 配置 rsyslog,将 kernel 日志输出到文件

修改/etc/[r]syslog.conf,添加如下配置:

kern.*                                                  /var/log/kern.log

后续可以在/var/log/kern.log中查看 kernel 日志信息。

Ref

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值