|
|
- Welcome to
Hiroshi's Home Page - |
|
|
|
||
|
||
|
▼ ▼ ▼ |
||
|
||
|
▼ ▼ ▼ |
||
|
||
NTPサーバとの時差をグラフ化…
はじめに
RRDTOOLを用いて、インターネット上に公開されているNTPサーバと、電波時計キット用ドライバを組み込んだNTPサーバ間の時差を、定期的に取得し、どの程度正確なのかをグラフ化します。
データ
参照するサーバは、以下の3ヶ所で、5分おきにntpdateでデータを取得します。
ntp-tk01.ocn.ad.jp
ntp1.jst.mfeed.ad.jp
ntp2.jst.mfeed.ad.jp
グラフ作成用データには、ntpdateのoffset値を用います。ntptraceではないのは、リトライするためntptraceより正確と考えるからです。
$ /usr/sbin/ntpdate -q ntp1.jst.mfeed.ad.jp server 210.173.160.27, stratum 2, offset -0.002713, delay 0.09857 7 Dec 13:36:47 ntpdate[5608]: adjust time server 210.173.160.27 offset -0.002713 secちなみに、ntptraceを用いるなら以下のようになります。
$ /usr/sbin/ntptrace -n -m 1 ntp1.jst.mfeed.ad.jp 210.173.160.27: stratum 2, offset -0.004212, synch distance 0.02687データ量はRRDTOOLのチュートリアルに習いMRTG互換で4パターンを作成します。
rrdtool create ntpdb.rrd \ DS:host1:GAUGE:600:U:U \ DS:host2:GAUGE:600:U:U \ DS:host3:GAUGE:600:U:U \ DS:host4:GAUGE:600:U:U \ RRA:MIN:0.5:1:600 \ RRA:MIN:0.5:6:700 \ RRA:MIN:0.5:24:775 \ RRA:MIN:0.5:288:797 \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 \ RRA:LAST:0.5:1:600 \ RRA:LAST:0.5:6:700 \ RRA:LAST:0.5:24:775 \ RRA:LAST:0.5:288:797ntpdateからoffset値を取得するperlスクリプトです。
#!/usr/bin/perl $NTPTRACE="/usr/sbin/ntpdate -q "; @SERVERS=("TS-JJY01のホストIP", "202.234.233.106", "210.173.160.27", "210.173.160.57"); $now = time(); print "$now"; foreach $SERVER (@SERVERS) { print ":"; if(open(FNTP, "$NTPTRACE $SERVER |") == 0) { printf("U", 0); next; } $result = <FNTP>; if($result =~ /offset\s+([0-9\.\-]+),/) { printf("%1.6f", $1); } else { printf("U", 0); } close(FNTP); } print "\n";このスクリプトで、「時間:host1のoffset値:host2のoffset値....」の形式で出力されます。
$ ./ntpdt.pl 1007907192:0.000578:-0.000037:0.000645:0.000376上記のスクリプトから受け取ったデータを、追加するシェルスクリプトです。
#!/bin/sh NTPDATA=`./ntpdt.pl` rrdtool update ntpdb.rrd $NTPDATAこのスクリプトを、5分おきに呼び出すようにcronに登録します。
グラフ化
取得したデータをグラフ化するスクリプトです。25時間、8日、32日のグラフを作成します。
#!/bin/sh rrdtool graph daily.gif \ --start -25hour \ --width 500 --height 120 \ --alt-autoscale \ --rigid \ --title "電波時計キットと公開NTPサーバの時差(1日)" \ --vertical-label "時 差 [秒]" \ DEF:host1=ntpdb.rrd:host1:AVERAGE \ DEF:host2=ntpdb.rrd:host2:AVERAGE \ DEF:host3=ntpdb.rrd:host3:AVERAGE \ DEF:host4=ntpdb.rrd:host4:AVERAGE \ LINE1:host1#606060:"TS-JJY01" \ LINE1:host2#FF0000:"ntp-tk01.ocn.ad.jp" \ LINE1:host3#008000:"ntp1.jst.mfeed.ad.jp" \ LINE1:host4#0000FF:"ntp2.jst.mfeed.ad.jp" > /dev/null rrdtool graph weekly.gif \ --start -8day \ --width 500 --height 120 \ --alt-autoscale \ --rigid \ --title "電波時計キットと公開NTPサーバの時差(1週間)" \ --vertical-label "時 差 [秒]" \ DEF:host1=ntpdb.rrd:host1:AVERAGE \ DEF:host2=ntpdb.rrd:host2:AVERAGE \ DEF:host3=ntpdb.rrd:host3:AVERAGE \ DEF:host4=ntpdb.rrd:host4:AVERAGE \ LINE1:host1#606060:"TS-JJY01" \ LINE1:host2#FF0000:"ntp-tk01.ocn.ad.jp" \ LINE1:host3#008000:"ntp1.jst.mfeed.ad.jp" \ LINE1:host4#0000FF:"ntp2.jst.mfeed.ad.jp" > /dev/null rrdtool graph monthly.gif \ --start -32day \ --width 500 --height 120 \ --alt-autoscale \ --rigid \ --title "電波時計キットと公開NTPサーバの時差(1ヶ月)" \ --vertical-label "時 差 [秒]" \ DEF:host1=ntpdb.rrd:host1:AVERAGE \ DEF:host2=ntpdb.rrd:host2:AVERAGE \ DEF:host3=ntpdb.rrd:host3:AVERAGE \ DEF:host4=ntpdb.rrd:host4:AVERAGE \ LINE1:host1#606060:"TS-JJY01" \ LINE1:host2#FF0000:"ntp-tk01.ocn.ad.jp" \ LINE1:host3#008000:"ntp1.jst.mfeed.ad.jp" \ LINE1:host4#0000FF:"ntp2.jst.mfeed.ad.jp" > /dev/nullこのスクリプトは、グラフを更新するタイミングで呼び出します。
こうして出来たグラフはこちら。
(2001/12/10)
|
||
|
▲ ▲ ▲ |
||
|
||
|
▲ ▲ ▲ |
||
|
||
|
|
||
|
(c) Copyright 1998-2002 Hiroshi OHNO All
right reserved. |
||