Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

Chrony NTP Stratum Dispersion and Clock Drift Sentinel

Audits Chrony NTP daemon root dispersion and clock offset to prevent transaction timestamp anomalies in distributed databases.

Categories
CoreInfrastructure

Audits Chrony NTP daemon telemetry across compute hosts to detect clock offset drift, NTP upstream stratum degradation, and root dispersion spikes.

How it works

  1. A schedule trigger executes the NTP audit workflow every 15 minutes.
  2. The Python task queries the Chrony exporter Prometheus endpoint (chrony-exporter:9148).
  3. The script extracts last clock offset in seconds, root dispersion, current stratum, and sync status flags.
  4. An evaluation gate determines whether microsecond offset or stratum drift breaches operational safety bounds.
  5. When thresholds are breached, a high-priority Slack alert is dispatched to infrastructure reliability engineers.
  6. When clock accuracy remains within microsecond margins, nominal telemetry is logged.
  7. A structured JSON audit manifest is emitted for database timestamp compliance and distributed tracing archives.

Architecture diagram

graph TD
    Trigger[Schedule Trigger: 15m] --> ScanMetrics[Python Script: Scrape Chrony Exporter Metrics]
    ScanMetrics --> EvalBreach{Clock Offset >= Threshold OR Stratum >= 4?}
    EvalBreach -- Yes --> SlackAlert[Slack: High-Urgency Infra Alert]
    EvalBreach -- No --> LogNominal[Log: Nominal Clock Sync State]
    SlackAlert --> EmitManifest[Debug Return: NTP Audit Manifest]
    LogNominal --> EmitManifest

Architecture components

  • Trigger: Automated schedule polling at 15-minute intervals.
  • Script Task: Scrapes Chrony NTP Prometheus exporter metrics using Docker container isolation.
  • Decision Gate: Evaluates whether clock offset in microseconds exceeds database tolerance bounds.
  • Notification Task: Dispatches structured Slack alerts with host pool identity, offset, and stratum level.
  • Audit Manifest: Emits JSON execution payloads containing offset measurements and timestamps.

Key capabilities

  • Continuous surveillance of Chrony daemon microsecond-level synchronization accuracy.
  • Rapid detection of upstream stratum loss and clock slew abnormalities.
  • Protection against distributed database write conflict anomalies (Spanner, CockroachDB, Cassandra).
  • Zero external dependency execution via isolated containerized Python runners.

What you get

  • Preemptive alerting on server hardware RTC drift and network latency jitter.
  • Automated calculation of root dispersion and peer stratum level degradation.
  • Real-time audit manifests capturing time synchronization health for compliance logs.
  • Configurable tolerance thresholds adaptable to sub-millisecond database environments.

Who it's for

  • Database administrators managing distributed CockroachDB, YugabyteDB, or Cassandra clusters.
  • Financial systems engineers enforcing MiFID II nanosecond and microsecond time compliance.
  • SREs managing high-frequency trading and low-latency API gateway fleets.
  • Linux systems engineers overseeing datacenter NTP and PTP infrastructure.

Why orchestrate this with Kestra

  • Deterministic Scheduling: Guarantees regular time sync checks without fragile local crontab setups.
  • Containerized Runners: Runs Python tasks inside isolated Docker containers without host package conflicts.
  • Condition Branching: Flowable If tasks route alerts and nominal logging cleanly without custom logic.
  • Enterprise Secret Safety: Securely injects Slack webhook credentials without plain-text storage.

Use cases

  • CockroachDB Max Offset Sentinel: Prevents node ejections caused by clock drift exceeding 500 microseconds.
  • Upstream PTP Grandmaster Loss: Alerts when primary datacenter GPS/PTP grandmaster fails over to public NTP.
  • Virtual Machine Clock Slew: Detects hypervisor CPU steal time causing guest OS hardware timer distortion.
  • Distributed Tracing Consistency: Ensures Jaeger and OpenTelemetry spans across microservices do not appear in reverse order.

Inputs

Name Type Default Description
chrony_exporter_url STRING http://chrony-exporter.monitoring.svc.cluster.local:9148 Base HTTP URL exposing Chrony Prometheus metrics.
node_pool_id STRING database-storage-nodes Identifier of the host cluster or database node pool.
max_offset_microseconds_threshold INT 500 Maximum allowable clock offset in microseconds before alerting.
lookback_minutes INT 15 Lookback evaluation window in minutes for clock offset.
alert_on_clock_drift BOOL true Toggle Slack alert dispatch upon detecting clock drift.

Expected outputs

  • {{ outputs.scan_chrony_ntp_metrics.vars.offset_microseconds }}: Absolute clock offset in microseconds.
  • {{ outputs.scan_chrony_ntp_metrics.vars.dispersion_microseconds }}: Total root dispersion in microseconds.
  • {{ outputs.scan_chrony_ntp_metrics.vars.current_stratum }}: Current NTP stratum level reported by Chrony.
  • {{ outputs.scan_chrony_ntp_metrics.vars.sync_status_ok }}: Boolean flag indicating active NTP synchronization state.
  • {{ outputs.scan_chrony_ntp_metrics.vars.is_alerting }}: Boolean flag indicating whether offset thresholds were breached.
  • {{ outputs.emit_audit_manifest.value }}: Structured JSON audit manifest emitted for compliance archives.

Prerequisites

  • Chrony daemon running on target nodes with chrony_exporter or node_exporter NTP collector active.
  • Chrony exporter port 9148 reachable from the Kestra worker execution environment.
  • Docker daemon running on the Kestra host to execute containerized Python tasks.

Secrets

  • SLACK_WEBHOOK_URL: Incoming webhook URL for the target Infrastructure Slack alerting channel.

Quick start

  1. Verify that chrony_exporter is deployed and exposing metrics on port 9148.
  2. Configure the SLACK_WEBHOOK_URL secret in your Kestra namespace settings.
  3. Adjust max_offset_microseconds_threshold to match your distributed database requirements (e.g. 500us).
  4. Execute a manual test run via the Kestra UI to verify offset parsing.
  5. Enable the periodic_chrony_audit trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • Step vs Slew Mode: Chrony configured to step time rather than slew can cause sudden timestamp jumps in databases.
  • Firewall UDP Port 123: Ensure NTP UDP port 123 is allowed to upstream NTP time servers.
  • Virtualization RTC Drift: On AWS/GCP, verify that the local hypervisor PTP clock source (/dev/ptp0) is used.
  • Stratum 16 Designation: Chrony reporting stratum 16 indicates the node has completely lost upstream synchronization.

How to extend

  • Automated Chrony Slew Adjustment: Trigger a remote Ansible or SSH task to execute chronyc makestep during non-peak windows.
  • CockroachDB Health Correlator: Correlate clock drift alerts with CockroachDB leaseholder rebalancing metrics.
  • PagerDuty High Urgency: Escalate to on-call database engineers when clock offset exceeds 2000 microseconds.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.