feat: Add NTP (Network Time Protocol) monitoring support#49
Merged
Conversation
- Implement NTPProber with comprehensive time synchronization monitoring - Support both ntp://server[:port] and ntp:server[:port] formats - Monitor response time and time offset from NTP servers - Add configurable max_offset threshold for time drift detection - Include extensive test suite with 75+ test cases covering: - Configuration validation (server, port, max_offset) - Target parsing (new/legacy formats, with/without ports) - Time conversion functions (NTP timestamp <-> time.Time) - Event registration and error handling - Integrate with existing ProbeManager and configuration system - Add NTP default configuration (pool.ntp.org:123) Tested with real NTP servers: - time.google.com: ~105ms offset detected correctly - pool.ntp.org: Response times 7-15ms measured accurately - Threshold testing: 50ms limit triggers errors, 200ms limit allows success - Validates against sntp tool results for accuracy verification
- Add NTP protocol to supported protocols table with examples - Include NTP usage examples in Quick Start section - Add comprehensive NTP configuration documentation - Add NTP to custom prober examples - Update feature list to include NTP monitoring - Set default MaxOffset to 5 seconds for practical time drift detection - Add time package import for MaxOffset configuration README updates include: - Protocol table: ntp://[server[:port]] format examples - Quick start: NTP monitoring and mixed protocol examples - Usage section: NTP command examples - Configuration: Complete NTP settings with max_offset explanation - Custom probers: ntp-strict example with 100ms threshold
921050a to
e964ee1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ntp://server[:port]andntp:server[:port]formatsKey Features
NTP Monitoring Capabilities
max_offsetto alert on excessive time driftProtocol Support
ntp://time.google.com,ntp://pool.ntp.org:123ntp:time.google.com,ntp:pool.ntp.org:123pool.ntp.org:123with no offset limitConfiguration Example
Implementation Details
Files Added
internal/prober/ntp.go: Core NTP prober implementation (400+ lines)internal/prober/ntp_test.go: Comprehensive test suite (200+ lines, 75+ test cases)Files Modified
internal/config/config.go: Add NTP default configurationinternal/prober/config.go: Add NTP validation supportinternal/prober/manager.go: Integrate NTP prober creationinternal/prober/validate_test.go: Add NTP validation testsTest Coverage
Test Results
Verified against real NTP servers with accurate results:
Response Time Monitoring
Time Offset Detection
With strict 50ms offset limit:
$ ./mping batch --count 3 --config strict-ntp.yml ntp-strict://time.google.com ┌──────────────────────────────┬──────┬──────┬──────┬────────┬──────┬─────┬──────┬───────┬───────────┬───────────┬─────────────────────────────────────────────────┐ │ HOST │ SENT │ SUCC │ FAIL │ LOSS │ LAST │ AVG │ BEST │ WORST │ LAST SUCC │ LAST FAIL │ FAIL REASON │ ├──────────────────────────────┼──────┼──────┼──────┼────────┼──────┼─────┼──────┼───────┼───────────┼───────────┼─────────────────────────────────────────────────┤ │ ntp-strict://time.google.com │ 4 │ 0 │ 4 │ 100.0% │ - │ - │ - │ - │ - │ 23:52:51 │ time offset too large: 107.444863ms (max: 50ms) │ └──────────────────────────────┴──────┴──────┴──────┴────────┴──────┴─────┴──────┴───────┴───────────┴───────────┴─────────────────────────────────────────────────┘Accuracy Verification
Compared against system
sntptool:Test Plan
Closes #38