暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

[转载]linux 时间戳转换, dmesg 时间转换

digoal 2016-03-01
521

作者

digoal

日期

2016-03-01

标签

Linux , dmesg , 时间转换


背景

原文

http://blog.csdn.net/buptapple/article/details/8568938

http://blog.csdn.net/wzb56_earl/article/details/50625705

linux时间戳转换

1. 将日期转换成时间戳

$date +%s -d "04/24/2014 15:30:00" 1398324600

2. 将时间戳转换成日期

$date -d @1398324600 Thu Apr 24 15:30:00 CST 2014

3. 将当前日期转换成时间戳

$date +%s 1398765730

dmesg 时间转换

dmesg 输出的格式不易查看,可以通过命令进行转换。

记录如下:

```
dmesg

......
[436494.327321] nf_conntrack: table full, dropping packet.
[441791.067611] nf_conntrack: table full, dropping packet.
[441791.070135] nf_conntrack: table full, dropping packet.
[441791.080384] nf_conntrack: table full, dropping packet.
[503057.990235] nf_conntrack: table full, dropping packet.
[523601.156915] nf_conntrack: table full, dropping packet.
[523601.163851] nf_conntrack: table full, dropping packet.
[523601.173434] nf_conntrack: table full, dropping packet.
[523601.178370] nf_conntrack: table full, dropping packet.
[523601.197334] nf_conntrack: table full, dropping packet.
```

时间查看:

`` date -d "1970-01-01 UTCecho "$(date +%s)-$(cat /proc/uptime|cut -f 1 -d' ')+523601"|bc ` seconds"

Mon Jun 26 17:20:29 CST 2017
```

转换脚本

```

!/bin/sh

uptime_ts=cat /proc/uptime | awk '{ print $1}'

echo $uptime_ts

dmesg | awk -v uptime_ts=$uptime_ts 'BEGIN { now_ts = systime(); start_ts = now_ts - uptime_ts; #print "system start time seconds:", start_ts; #print "system start time:", strftime("[%Y/%m/%d %H:%M:%S]", start_ts); } { print strftime("[%Y/%m/%d %H:%M:%S]", start_ts + substr($1, 2, length($1) - 2)), $0 }' ```

/proc/uptime详解

在Linux中,我们常常会使用到uptime命令去看看系统的运行时间,它与一个文件有关,就是/proc/uptime,下面对其进行详细介绍。

```
master@jay-intel:~$ cat /proc/uptime
6447032.12 48185264.69

master@jay-intel:~$ cat /proc/cpuinfo | grep processor | wc -l
8
```

第一列输出的是,系统启动到现在的时间(以秒为单位),这里简记为num1;

第二列输出的是,系统空闲的时间(以秒为单位),这里简记为num2。

注意,很多很多人都知道第二个是系统空闲的时间,但是可能你不知道是,在SMP系统里,系统空闲的时间有时会是系统运行时间的几倍,这是怎么回事呢?

因为系统空闲时间的计算,是把SMP算进去的,就是所你有几个逻辑的CPU(包括超线程)。

系统的空闲率(%) = num2/(num1*N) 其中N是SMP系统中的CPU个数。

从上面我的一台机器上的数据可知,

本机启动到现在的时间长度为:

6447032.12 seconds = 74.6 days

空闲率为:

48185264.69/(6447032.12*8)=93.4%

系统空闲率越大,说明系统比较闲,可以加重一些负载;而系统空闲率很小,则可能考虑升级本机器硬件或者迁移部分负载到其他机器上。

Some docs from Redhat:

The first number is the total number of seconds the system has been up.

The second number is how much of that time the machine has spent idle, in seconds.

(Jay’s comments: Please pay attention to SMP system.)

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论