Results 1 to 5 of 5
Is it possible to monitor the NTP drift value ( I mean measuring the time difference between the NTP server and the server that I am trying to monitor) using ...
- 12-02-2011 #1Just Joined!
- Join Date
- Dec 2011
- Posts
- 4
Is it possible to monitor NTP through SNMP in Linux
Is it possible to monitor the NTP drift value ( I mean measuring the time difference between the NTP server and the server that I am trying to monitor) using SNMP.
Appreciate any help in this regard.
- 12-02-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
All this is assuming you have snmp daemon configured and running on your Linux box.
You can get current system date/time with:
provided that snmpd is set up and configured properly for this on the Linux box, but you probably want something more granular.Code:snmpwalk -Cc -On -v2c -c public localhost .1.3.6.1.4.1.2021.100.4.0
There may be a way to directly access NTP info via an OID, but I don't know it.
Fortunately, it is possible to monitor anything in SNMP via the exec directive or maybe pass (PASS-THROUGH-CONTROL), never used the latter. For example, you can put this in your snmpd.conf on the Linux box:
Then create /tmp/get-drift.sh and put in it the code to determine drift. I don't know how to do that, but I gather it would be some sort of ntpdate command. Here's something to start with that would work on a RH/Fedora box, e.g.:Code:# run external script to return drift info exec 1.3.6.1.4.1.2021.8.1.101 get-drift /tmp/get-drift.sh
Note that the above doesn't actually output anything. You'll have to figure that out yourself. Just be sure to send whatever you get on a single line of output, to make it easier for snmpwalk to parse.Code:#!/bin/bash # location of ntp config file ntpConf=/etc/ntp.conf # make sure it exists ! [ -f $ntpConf ] && echo "$ntpConf: No such file" && exit 1 # get an ntp server from the config file server=$(awk '/^server/{print $2}' $ntpConf|head -n1) # see if we need to stop the ntp daemon pidof ntpd >/dev/null 2>&1 if [ $? -eq 0 ]; then /etc/init.d/ntpd stop >/dev/null 2>&1 || exit 1 restart_ntp=1 fi # do something with this output output=$(ntpdate -d $server 2>&1) # restart the daemon if necessary (distro-specific) [ -n "$restart_ntp" ] && /etc/init.d/ntpd start >/dev/null 2>&1
Don't forget to make your script executable:
Then you'd call it (locally) with something like:Code:chmod +x /tmp/get-drift.sh
again, depends on your snmpd config.Code:snmpwalk -c public -v2c localhost .1.3.6.1.4.1.2021.8.1.101
Read more on snmp.conf in the man page:
Code:man 5 snmpd.conf
Last edited by atreyu; 12-02-2011 at 03:01 PM. Reason: snmpwalk cmd
- 12-05-2011 #3Just Joined!
- Join Date
- Dec 2011
- Posts
- 4
Thanks let me try this.b
- 12-05-2011 #4Just Joined!
- Join Date
- Dec 2011
- Posts
- 4
Is there any direct MIB from SNMP for monitoring the NTP time difference
- 12-08-2011 #5Just Joined!
- Join Date
- Dec 2011
- Posts
- 4
I am able to get the drift value using the above method. but still trying to find a MIB for NTP monitoring.someone help please


Reply With Quote