Code Monkey home page Code Monkey logo

sensu-plugins-ntp's Introduction

Sensu Bonsai Asset Build Status Gem Version Code Climate Test Coverage Dependency Status

Sensu Plugins NTP Plugin

Overview

This plugin provides native network time protocol (NTP) instrumentation for monitoring and metrics collection, including server drift and metrics via ntpdate and ntpstats.

Files

  • check-ntp.rb
  • metrics-ntpdate.rb
  • metrics-ntpstats.rb

check-ntp Checks the synchronization state of the local NTP server.

  • Parameters:
    • warn: Maximum offset in ms for warning state (default: 10)
    • crit: Maximum offset in ms for critical state (default: 100)
    • stratum: Maximum stratum value (default: 15)
    • unsynced_status: Default status when unsynced (default: UNKNOWN)

metrics-ntpdate Gets metrics from ntpdate.

  • Parameters:

    • server: Comma-separated list of NTP server(s) to measure (default: localhost)
    • scheme: Prefix for metrics (default: hostname)
  • Values:

    • offset: Time difference between server and source (unit: ms)
    • delay: Roundtrip time from server to source (unit: ms)

metrics-ntpstats Gets metrics from ntpstats.

  • Parameters:

    • host: Target host (default: localhost)
    • scheme: Prefix for metrics (default: hostname)
  • Values (descriptions from https://www.eecis.udel.edu/~mills/ntp/html/ntpq.html):

    • clk_jitter: Clock jitter
    • clk_wander: Clock frequency wander
    • frequency: Frequency offset relative to hardware clock
    • mintc: Minimum time constant
    • offset: Combined offset of server relative to this host
    • stratum: Stratum
    • sys_jitter: Combined system jitter
    • tc: Time constant and poll exponent

Usage examples

Help

check-ntp.rb

Usage: check-ntp.rb (options)
    -c CRIT
    -s STRATUM                       check that stratum meets or exceeds desired value
    -u CODE                          If ntp_status is unsynced (that is, not yet connected to or disconnected from ntp), what should the response be.
    -w WARN

metrics-ntpdate.rb

Usage: metrics-ntpdate.rb (options)
    -s, --scheme SCHEME              Metric naming scheme, text to prepend to metric
        --server SERVER1[,SERVER2,..]
                                     NTP server(s)

metrics-ntpstats.rb

Usage: metrics-ntpstats.rb (options)
    -h, --host HOST                  Target host
    -s, --scheme SCHEME              Metric naming scheme, text to prepend to metric

Configuration

Sensu Go

Asset registration

Assets are the best way to make use of this plugin. If you're not using an asset, please consider doing so! If you're using sensuctl 5.13 or later, you can use the following command to add the asset:

sensuctl asset add sensu-plugins/sensu-plugins-ntp

If you're using an earlier version of sensuctl, you can download the asset definition from this project's Bonsai asset index page.

Asset definition

---
type: Asset
api_version: core/v2
metadata:
  name: sensu-plugins-ntp
spec:
  url: https://assets.bonsai.sensu.io/a24eea423200374c5b7f96082dd7e315fc1ea814/sensu-plugins-ntp_2.0.0_centos_linux_amd64.tar.gz
  sha512: 3ee7b68d91798775f70ee9cd037f98a82386ae9beccd069a4db262d6b69ef49db65a1415cc40c2a6c8726447f0cf4978a332968edf132cd79805ce4f68889a5a

Check definition

---
type: CheckConfig
spec:
  command: "check-ntp.rb"
  handlers: []
  high_flap_threshold: 0
  interval: 10
  low_flap_threshold: 0
  publish: true
  runtime_assets:
  - sensu-plugins/sensu-plugins-ntp
  - sensu/sensu-ruby-runtime
  subscriptions:
  - linux

Sensu Core

Check definition

{
  "checks": {
    "check-ntp": {
      "command": "check-ntp.rb",
      "subscribers": ["linux"],
      "interval": 10,
      "refresh": 10,
      "handlers": ["influxdb"]
    }
  }
}

Installation from source

Sensu Go

See the instructions above for asset registration.

Sensu Core

Install and setup plugins on Sensu Core.

Additional notes

Sensu Go Ruby Runtime Assets

The Sensu assets packaged from this repository are built against the Sensu Ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator, or handler), make sure to include the corresponding Sensu Ruby Runtime Asset in the list of assets needed by the resource.

Contributing

See CONTRIBUTING.md for information about contributing to this plugin.

sensu-plugins-ntp's People

Contributors

analytically avatar corro avatar cwjohnston avatar dependabot-preview[bot] avatar dependabot-support avatar eheydrick avatar evesy avatar hillaryfraley avatar jspaleta avatar majormoses avatar mdzidic avatar mjulian avatar mnjhey avatar swhyte-taos avatar tas50 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sensu-plugins-ntp's Issues

[CentOS] - Agents are unable to download the plugin build due to platform filtering w/ CentOS 7.9+Sensu 6.2

Per title, it looks like the agents are seeing the asset but are filtered out due to no match for the platform. Some light digging leads me to believe this is because the entity.system.platform element is being used instead of element.system.platform_family (as the platform reported by the agent is centos 7.9.2009, therefore not matching the filter), though I could be wrong. Other plugins which use platform_family install and run OK, hence the hunch.

Relevant log snippet:

Dec 18 15:07:55 sensugo-client1 sensu-agent[11142]: {"asset":"sensu-plugins/sensu-plugins-ntp","component":"asset-manager","entity":"sensugo-client1","filter":["entity.system.os == 'linux'","entity.system.arch == 'amd64'","entity.system.platform == 'alpine'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-12-18T15:0
Dec 18 15:07:55 sensugo-client1 sensu-agent[11142]: {"asset":"sensu-plugins/sensu-plugins-ntp","component":"asset-manager","entity":"sensugo-client1","filter":["entity.system.os == 'linux'","entity.system.arch == 'amd64'","entity.system.platform == 'rhel'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-12-18T15:07:
Dec 18 15:07:55 sensugo-client1 sensu-agent[11142]: {"asset":"sensu-plugins/sensu-plugins-ntp","component":"asset-manager","entity":"sensugo-client1","filter":["entity.system.os == 'linux'","entity.system.arch == 'amd64'","entity.system.platform == 'debian'"],"level":"debug","msg":"entity not filtered, not installing asset build","time":"2020-12-18T15:0
Dec 18 15:07:55 sensugo-client1 sensu-agent[11142]: {"asset":"sensu-plugins/sensu-plugins-ntp","component":"asset-manager","entity":"sensugo-client1","level":"warning","msg":"entity not filtered from any asset builds, not installing asset","time":"2020-12-18T15:07:55-05:00"}

CheckNTP UNKNOWN: NTP command Failed

This just occured site wide for us. I have no changes to our code base and Im not sure whats going on here:

/opt/sensu/embedded/bin/ruby /opt/sensu/embedded/bin/check-ntp.rb -w 700 -c 1000
CheckNTP UNKNOWN: NTP command Failed
 ntpq -c "rv 0"
associd=0 status=4615 leap_add_sec, sync_ntp, 1 event, clock_sync,
version="ntpd [email protected] Wed Jan 20 15:22:38 UTC 2016 (1)",
processor="x86_64", system="Linux/3.10.0-327.13.1.el7.x86_64", leap=01,
stratum=4, precision=-24, rootdelay=41.747, rootdisp=48.012,
refid=10.192.1.31,
reftime=dc1182bc.0491f3dc  Fri, Dec 30 2016 20:05:00.017,
clock=dc118408.6e8df8a6  Fri, Dec 30 2016 20:10:32.431, peer=21279, tc=6,
mintc=3, offset=0.310, frequency=17.705, sys_jitter=0.000,
clk_jitter=0.298, clk_wander=0.007
 ntpq -c "rv 0 stratum,offset"
stratum=4, offset=0.937

I noticed that status is "4615 leap_add_sec" is that due to it being a leap second month? If that is the case the check shouldnt return with command failed I would think?

Bonsai debian9 filter definition is too broad

The filters debian 9 are too broad, either remove or add debian platform_family and version to filter

- platform: "debian9"
  arch: "amd64"
  asset_filename: "#{repo}_#{version}_debian9_linux_amd64.tar.gz"
  sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
  filter:
  -  "entity.system.os == 'linux'"
  -  "entity.system.arch == 'amd64'"

Support Chrony

RedHat and CentOS have moved to Chrony from ntpd for NTP.

The equivalent command and output:

    $ chronyc sources
    210 Number of sources = 4
    MS Name/IP address         Stratum Poll Reach LastRx Last sample
    ===============================================================================
    ^+ arethusa.tweakers.net         2  10   377   22m   -574us[ -574us] +/-   27ms
    ^* ntp0.mediamatic.nl            2  10   377   22m   -946us[-1032us] +/-   32ms
    ^- dns02.wsrs.net                2   9   377   192    -54ms[  -54ms] +/-   91ms
    ^+ hosting01.spk.rickes.nl       2  10   377   22m  -1834us[-1834us] +/-   39ms

Unsynced ntp client, using local time source, returns status OK with offset 0.0ms.

If an ntp client marks all ntp sources as bad, it will use local clock as a time source. The current check always results in OK in this scenario.

In the example below, the system was previously synchronized, but chose to use local time instead of a remote source. The offset from the remote source is now 269 seconds.

Per the ntp documentation (http://doc.ntp.org/current-stable/decode.html#sys), sync_unspec in the first line of the ntpq -c "rv 0" output indicates that the system is not yet synchronized. The 4-char hex status code provides another mechanism for checking the ntp system status.

[root@host]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.186.250 LOCAL(0)        11 u  446 1024  377  999.247  269051. 1753.94

[root@host]# ntpq -c 'rv 0'
associd=0 status=00ff leap_none, sync_unspec, 15 events, stale_leapsecond_values,
version="ntpd [email protected] Mon Oct 26 15:38:27 UTC 2015 (1)",
processor="x86_64", system="Linux/3.10.0-327.4.5.el7.x86_64", leap=00,
stratum=12, precision=-23, rootdelay=997.189, rootdisp=8885.016,
refid=192.168.186.250,
reftime=dacd3628.ba39ba1a  Thu, Apr 28 2016 18:23:52.727,
clock=dad62465.92acd1ea  Thu, May  5 2016 12:58:29.572, peer=0, tc=10,
mintc=3, offset=0.000, frequency=-451.107, sys_jitter=0.000,
clk_jitter=8.733, clk_wander=0.062, tai=35, leapsec=201207010000,
expire=201312280000

[root@host]# /opt/sensu/embedded/bin/check-ntp.rb 
CheckNTP OK: NTP offset by 0.0ms

command parameters

https://github.com/sensu-plugins/sensu-plugins-ntp/blob/master/bin/check-ntp.rb#L32
https://github.com/sensu-plugins/sensu-plugins-ntp/blob/master/bin/check-ntp.rb#L37

the command line options currently are using to_i which does not evaluate decimal based values properly.

Example: ntpq -c "rv 0 stratum,offset" returns stratum=2, offset=-0.500. If you set -c .51, this should return an OK check. It currently will return critical.

Changing to use to_f fixes this issue.

I also think the stratum level could use a configurable value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.