うるう秒の観測しよう for Squeeze 〜結果編〜

■うるう秒挿入を確認しました。
 (日本時間08:59:60)

 別のことをしていたら、すっかり過ぎてしまいました。。。
 まあ、ログがあるので、これからログを観測します。。。

 うるう秒を観測しよう for Squeeze
 http://d.hatena.ne.jp/labunix/20120630

■UTC時間とUNIX時間

 UTC時間(+9時間=JST)
  「23:59:60」は出ませんでした。
  「23:59:59」を2回繰り返しています。
 UNIX時間
  「1341100799」を2回繰り返しています。
  1秒の逆進の発生です。
 ntp_gettime()
  「returns code 3 (OOP)」がうるう秒発生の瞬間です。

$ grep "UTC 2012\$\|^13\|ntp_gettime" /var/log/leapindicator.log | \
  grep -B 1 -A 2 '23:59:[56][0-9]\|00:00:0[0-9]' | \
  awk '{if (NR%3==0) printf $0"\n" ;else printf $0" -> "}'
1341100790 -> Sat Jun 30 23:59:50 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100791 -> Sat Jun 30 23:59:51 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100793 -> Sat Jun 30 23:59:53 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100794 -> Sat Jun 30 23:59:54 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100795 -> Sat Jun 30 23:59:55 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100796 -> Sat Jun 30 23:59:56 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100797 -> Sat Jun 30 23:59:57 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100798 -> Sat Jun 30 23:59:58 UTC 2012 -> ntp_gettime() returns code 1 (INS)
1341100799 -> Sat Jun 30 23:59:59 UTC 2012 -> ntp_gettime() returns code 3 (OOP)
1341100799 -> Sat Jun 30 23:59:59 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100800 -> Sun Jul  1 00:00:00 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100801 -> Sun Jul  1 00:00:01 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100802 -> Sun Jul  1 00:00:02 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100803 -> Sun Jul  1 00:00:03 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100804 -> Sun Jul  1 00:00:04 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100805 -> Sun Jul  1 00:00:05 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100806 -> Sun Jul  1 00:00:06 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100807 -> Sun Jul  1 00:00:07 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100808 -> Sun Jul  1 00:00:08 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341100809 -> Sun Jul  1 00:00:09 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)

■UNIX時間 -> UTC時間のチェック

$ LANG=C;date -u -d '@1341100808'
Sun Jul  1 00:00:08 UTC 2012

■逆進をkernelが認識したかどうかは「messages」ログで分かります。

$ sudo grep leap /var/log/messages
Jul  1 08:59:59 [your-host-name] kernel: [1176490.904382] Clock: inserting leap second 23:59:60 UTC

■ntptimeのログは分かりやすい。
 「ntpq」だけで見てしまうと「このサーバは、それでその後どうしたの?」の部分がごっそり抜ける。
 「ntptime」は、うるう秒経過中と、うるう秒が発生中(システムと同期中)というステータスをきちんと返す。

$ w3m -dump http://d.hatena.ne.jp/labunix/20120306/ | grep "[0-5] TIME"
0 TIME_OK        全てが OK で、閏秒の警告もありません。
1 TIME_INS       正の閏秒の警告です。 この日の最後の 23:59:59 の後に追加の 1 秒が挿入されます。
2 TIME_DEL       負の閏秒の警告です。 この日の最後の 23:59:59 はスキップされます。
3 TIME_OOP       閏秒の経過中です。
4 TIME_WAIT      閏秒が発生しました。
5 TIME_ERROR     クロックが同期していません。

■ntpサーバの同期が正常に戻ったのは、「00:18:58」でした。
 これは、ntpサーバとシステム時間が、1秒の逆進の同期を正常に完了した瞬間です。

$ grep "UTC 2012\$\|^13\|ntp_gettime" /var/log/leapindicator.log | \
  grep -B 1 -A 2 '00:18:5[5-9]\|00:19:0[0-5]' | \
  awk '{if (NR%3==0) printf $0"\n" ;else printf $0" -> "}'
1341101935 -> Sun Jul  1 00:18:55 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341101936 -> Sun Jul  1 00:18:56 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341101937 -> Sun Jul  1 00:18:57 UTC 2012 -> ntp_gettime() returns code 4 (WAIT)
1341101938 -> Sun Jul  1 00:18:58 UTC 2012 -> ntp_gettime() returns code 0 (OK)
1341101940 -> Sun Jul  1 00:19:00 UTC 2012 -> ntp_gettime() returns code 0 (OK)
1341101941 -> Sun Jul  1 00:19:01 UTC 2012 -> ntp_gettime() returns code 0 (OK)
1341101942 -> Sun Jul  1 00:19:02 UTC 2012 -> ntp_gettime() returns code 0 (OK)
1341101943 -> Sun Jul  1 00:19:03 UTC 2012 -> ntp_gettime() returns code 0 (OK)
1341101944 -> Sun Jul  1 00:19:04 UTC 2012 -> ntp_gettime() returns code 0 (OK)
1341101945 -> Sun Jul  1 00:19:05 UTC 2012 -> ntp_gettime() returns code 0 (OK)

■スクリプトと「leapindicator.log」はgithubに置いておきました。

 github:labunix / leaptime
 git://github.com/labunix/leaptime.git
 https://github.com/labunix/leaptime.git