ITPub博客

首页 > 自动化运维 > 应用服务器 > [20191226]dmesg与时间戳.txt

[20191226]dmesg与时间戳.txt

原创 应用服务器 作者:lfree 时间:2019-12-26 09:29:30 0 删除 编辑

[20191226]dmesg与时间戳.txt

--//昨天例行检查时,我发现rh7的服务器执行dmesg时前面有一串数字.

# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.7 (Maipo)

# dmesg | head -3
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct

# dmesg | tail -4
[   66.621051] fuse init (API version 7.23)
[825806.735240] FS-Cache: Loaded
[825806.797058] FS-Cache: Netfs 'nfs' registered for caching
[1294335.827275] Adjusting tsc more than 11% (3895849 vs 4906388)

--//可以猜测中括号里面的数字一定与时间相关.dmesg输出开头都是0,也就是这个时间应该表示某种偏移量,单位猜测应该是秒.
--//看了man demsg文档,发现rh7.7版本对dmesg做了许多改进,增加许多功能.
-T, --ctime
    Print human readable timestamps.  The timestamp could be inaccurate!

# dmesg -L -T | head -3 ; dmesg -L -T | tail -3
[Thu Dec  5 12:07:43 2019] Initializing cgroup subsys cpuset
[Thu Dec  5 12:07:43 2019] Initializing cgroup subsys cpu
[Thu Dec  5 12:07:43 2019] Initializing cgroup subsys cpuacct
--//head
[Sun Dec 15 01:31:09 2019] FS-Cache: Loaded
[Sun Dec 15 01:31:09 2019] FS-Cache: Netfs 'nfs' registered for caching
[Fri Dec 20 11:39:58 2019] Adjusting tsc more than 11% (3895849 vs 4906388)
--//tail

# last | grep reboot | head -1
reboot   system boot  4.1.12-124.33.4. Thu Dec  5 12:07 - 08:34 (20+20:26)

# uptime
08:34:25 up 20 days, 20:26,  2 users,  load average: 1.00, 1.03, 1.05

--//结合这两个输出,可以判断时间就是Thu Dec  5 12:07:43 2019 加上 1294335.827275秒.验证看看.
# date -d "Thu Dec  5 12:07:43 2019 UTC  1294335.827275 seconds" +"%Y-%m-%d %T"
2019-12-20 19:39:58

--//不要考虑时区.取消UTC.
# date -d "Thu Dec  5 12:07:43 2019   1294335.827275 seconds" +"%Y-%m-%d %T"
2019-12-20 11:39:58
--//正好与[Fri Dec 20 11:39:58 2019] Adjusting tsc more than 11% (3895849 vs 4906388)的输出时间一致.

--//当时当我看我的测试环境:
# cat /etc/issue | head -1
Oracle Linux Server release 5.9

# dmesg | tail -2
warning: `avahi-daemon' uses 32-bit capabilities (legacy support in use)
eth0: no IPv6 routers present

--//并没有时间戳信息.也就是rh7.7版本内核做了某些改进,增加显示时间戳.我看了一些文档:
--//实际上就是设置/sys/module/printk/parameters/time等于Y就ok了.
# cat /sys/module/printk/parameters/time
N
# echo Y >| /sys/module/printk/parameters/time

--//尝试加载ip_tables模块.也就是尝试写入一些信息.

# modprobe ip_tables
# dmesg | tail -4
warning: `avahi-daemon' uses 32-bit capabilities (legacy support in use)
eth0: no IPv6 routers present
ip_tables: (C) 2000-2006 Netfilter Core Team
[231838.112752] ip_tables: (C) 2000-2006 Netfilter Core Team
--//也就是出现时间戳.可以这个要过来计算日期比较麻烦.

# modprobe xfs;zdate
2019/12/26 09:14:58

# dmesg | tail -1
[233458.384254] SGI XFS Quota Management subsystem

# cat /proc/uptime ;zdate
233980.52 5611536.56
2019/12/26 09:15:45

# date -d "$(zdate) -$(cat /proc/uptime|cut -d' ' -f1) seconds" +"%Y-%m-%d %T"
2019-12-23 16:16:04

# date -d "2019/12/26 09:15:45 -233980.52 seconds" +"%Y-%m-%d %T"
2019-12-23 16:16:04

# date -d "2019-12-23 16:16:04 233458.384254 seconds" +"%Y-%m-%d %T"
2019-12-26 09:07:02

--//有接近8分钟误差,不知道那个计算环节出了问题.放弃!!

--//补充:我重新在rh7服务器测试:
# date -d "$(zdate) -$(cat /proc/uptime|cut -d' ' -f1) seconds" +"%Y-%m-%d %T"
2019-12-05 12:07:43

--//这个时间与dmesg -T看到的时间一致.使用它计算应该是对的.不知道在测试环境问题出在哪里.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2670625/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969290