Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allamiro dev Adding chrony.sh to parse Chrony NTP clients #187

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions chrony.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash

# Author: Tamir Suliman
# Script inspired by the chrony.py
#
#


# Extract chronyc tracking data and write it to a Prometheus text file collector

# Run chronyc to get tracking data and store it in a variable
tracking_data=$(chronyc tracking)

# HELP node_chronyc_refid Reference ID of the NTP server.
# TYPE node_chronyc_refid gauge
echo "$tracking_data" | awk -F '[(]' '/Reference ID/{print "node_chronyc_refid{server=\""$1"\"} 1"}'

# HELP node_chronyc_stratum Stratum of the NTP server.
# TYPE node_chronyc_stratum gauge
echo "$tracking_data" | awk '/Stratum/ {print "node_chronyc_stratum "$3}'

# HELP node_chronyc_offset Last offset from NTP time (seconds).
# TYPE node_chronyc_offset gauge
echo "$tracking_data" | awk '/Last offset/ {print "node_chronyc_last_offset "$4}'

# HELP node_chronyc_rms_offset Last offset from NTP time (seconds).
# TYPE node_chronyc_rms_offset gauge
echo "$tracking_data" | awk '/RMS offset/ {print "node_chronyc_rms_offset "$4}'

# HELP node_chronyc_frequency Frequency of the NTP server(ppm).
# TYPE node_chronyc_frequency gauge
echo "$tracking_data" | awk '/Frequency/ {print "node_chronyc_frequency "$3}'

# HELP node_chronyc_residual_freq Residual Frequency of the NTP server(ppm).
# TYPE node_chronyc_residual_freq gauge
echo "$tracking_data" | awk '/Residual freq/ {print "node_chronyc_resideual_freq "$4}'

# HELP node_chronyc_skew Skew of the NTP server(ppm).
# TYPE node_chronyc_skew gauge
echo "$tracking_data" | awk '/Skew/ {print "node_chronyc_skew "$3}'

# HELP node_chronyc_root_delay Root delay of the NTP server (seconds).
# TYPE node_chronyc_root_delay gauge
echo "$tracking_data" | awk '/Root delay/ {print "node_chronyc_root_delay "$4}'

# HELP node_chronyc_root_dispersion Root dispersion of the NTP server (seconds).
# TYPE node_chronyc_root_dispersion gauge
echo "$tracking_data" | awk '/Root dispersion/ {print "node_chronyc_root_dispersion "$4}'

# HELP node_chronyc_update_interval Update interval of the NTP server (seconds).
# TYPE node_chronyc_update_interval gauge
echo "$tracking_data" | awk '/Update interval/ {print "node_chronyc_update_interval "$4}'

# HELP node_chronyc_leap_status Leap status of the NTP server.
# TYPE node_chronyc_leap_status gauge
echo "$tracking_data" | awk '/Leap status/ {print "node_chronyc_leap_status{status=\""$4"\"} 1"}'