Ad Widget

Collapse

Monitoring ntp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Member
    • Jan 2006
    • 39

    #1

    Monitoring ntp

    The following UserParameters allow you to monitor various aspect of an ntpd server.

    Code:
    UserParameter=ntp.offset,/usr/sbin/ntpq -pn | /usr/bin/awk 'BEGIN { offset=1000 } $1 ~ /\*/ { offset=$9 } END { print offset }'
    UserParameter=ntp.stratum,/usr/sbin/ntpq -pn | /usr/bin/awk 'BEGIN { stratum=99 } $1 ~ /\*/ { stratum=$3 } END { print stratum }'
    UserParameter=ntp.npeers,ntpq -pn | grep -E -c '^\*|^\+'
    The returned values will give (compare with raw output of ntpq below)
    1. the offset to the currently selected peer (ntp.offset): 3.055
    2. the stratum of the currently selected peer (ntp.stratum): 2
    3. the number of possible peers, i.e. those prefixed with '*' or '+' (ntp.npeers): 2


    Code:
    # ntpq -pn
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     10.1.1.1        .INIT.          16 u    - 1024    0    0.000    0.000 4000.00
     130.102.128.23  .INIT.          16 u    - 1024    0    0.000    0.000 4000.00
    [B]+[/B]202.181.31.242  203.26.24.6      3 u  880 1024  377   32.171  -12.953   0.608
    [B]*[/B]130.102.128.23  130.102.152.7    [B]2[/B] u    1 1024  377   51.986    [B]3.055[/B]   0.253
     127.127.1.0     73.78.73.84      5 l   12   64  377    0.000    0.000   0.001
    If I could only find out how to pass arguments to UserParameters then one could easi;y expand this to monitor remote ntpd servers, e.g. ntp.offset[130.102.128.23].

    Markus
  • marc
    Senior Member
    • Oct 2004
    • 146

    #2
    Code:
    UserParameter=ntp.offset,/usr/sbin/ntpq -pn | /usr/bin/awk 'BEGIN { offset=1000 } $1 ~ /\*/ { offset=$9 } END { print offset }'
    UserParameter=ntp.stratum,/usr/sbin/ntpq -pn | /usr/bin/awk 'BEGIN { stratum=99 } $1 ~ /\*/ { stratum=$3 } END { print stratum }'
    UserParameter=ntp.npeers,ntpq -pn | grep -E -c '^\*|^\+'
    If I could only find out how to pass arguments to UserParameters then one could easi;y expand this to monitor remote ntpd servers, e.g. ntp.offset[130.102.128.23].
    Markus
    just do the following...
    1.) change UserParameter to something similar UserParameter=ntp.stratum[*],/usr/sbin/ntpq -pn | /usr/bin/awk 'BEGIN { stratum=99 } $1 ~ /\*/ { stratum=$3 } END { print stratum }'

    the[*] is placeholder for variable passed to UserParameter.
    you are also able to pass multiple vars using a syntax like UserParameter=ntp.stratum[*,*,*]....

    2.) change item in gui to ntp.stratum[xxx.xxx.xxx.xx] were xxx=an ip address octed.

    3.) open beer + cheers

    Comment

    • Markus
      Member
      • Jan 2006
      • 39

      #3
      Thanks Marc for answering how to pass arguments to UserParameter. Unfortunately this does not work for the very example above. The '$x' variables in the awk script will get substituted, too, which will lead to a syntax errror. I have to find a work-around for this...

      Markus

      Comment

      • Markus
        Member
        • Jan 2006
        • 39

        #4
        I found a work-around but it's quite sneaky! Anyway, the trick is to pass the '$x' parameters in the awk script literally as arguments to the UserParameter call. Example:

        Code:
        UserParameter=ntp.offset[*],/usr/sbin/ntpq -pn [B]$1[/B] | /usr/bin/awk 'BEGIN { offset=0 } [B]$2[/B] ~ /\*/ { offset=[B]$3[/B] } END { print offset }'
        ...when this is called as...

        Code:
        ntp.offset[[B]130.102.128.23,$1,$9[/B]]
        ... then '$1 be will replaced by '130.102.128.23', '$2' is replaced by '$1' and '$3' is replaced by '$9'. That way we sneak the correct variable names into the awk script and what actually gets executed is.

        Code:
        UserParameter=ntp.offset[*],/usr/sbin/ntpq -pn [B]130.102.128.23[/B] | /usr/bin/awk 'BEGIN { offset=0 } [B]$1[/B] ~ /\*/ { offset=[B]$9[/B] } END { print offset }'
        There you go...

        Markus

        Comment

        Working...