Skip to content

Add new chrony serverstats counters to exposed serverstats metrics #87

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

Merged
Merged
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
78 changes: 78 additions & 0 deletions collector/serverstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,66 @@ var (
),
prometheus.GaugeValue,
}

serverstatsNTPDaemonRxTimestamps = typedDesc{
prometheus.NewDesc(
prometheus.BuildFQName(namespace, serverstatsSubsystem, "ntp_daemon_rx_timestamps_total"),
"The number of NTP responses which included a receive timestamp captured by the daemon.",
nil,
nil,
),
prometheus.CounterValue,
}

serverstatsNTPDaemonTxTimestamps = typedDesc{
prometheus.NewDesc(
prometheus.BuildFQName(namespace, serverstatsSubsystem, "ntp_daemon_tx_timestamps_total"),
"The number of NTP responses which included a transmit timestamp captured by the daemon.",
nil,
nil,
),
prometheus.CounterValue,
}

serverstatsNTPKernelRxTimestamps = typedDesc{
prometheus.NewDesc(
prometheus.BuildFQName(namespace, serverstatsSubsystem, "ntp_kernel_rx_timestamps_total"),
"The number of NTP responses which included a receive timestamp captured by the kernel.",
nil,
nil,
),
prometheus.CounterValue,
}

serverstatsNTPKernelTxTimestamps = typedDesc{
prometheus.NewDesc(
prometheus.BuildFQName(namespace, serverstatsSubsystem, "ntp_kernel_tx_timestamps_total"),
"The number of NTP responses (in the interleaved mode) which included a transmit timestamp captured by the kernel.",
nil,
nil,
),
prometheus.CounterValue,
}

serverstatsNTPHwRxTimestamps = typedDesc{
prometheus.NewDesc(
prometheus.BuildFQName(namespace, serverstatsSubsystem, "ntp_hw_rx_timestamps_total"),
"The number of NTP responses which included a receive timestamp captured by the NIC.",
nil,
nil,
),
prometheus.CounterValue,
}

serverstatsNTPHwTxTimestamps = typedDesc{
prometheus.NewDesc(
prometheus.BuildFQName(namespace, serverstatsSubsystem, "ntp_hw_tx_timestamps_total"),
"The number of NTP responses (in the interleaved mode) which included a transmit timestamp captured by the NIC.",
nil,
nil,
),
prometheus.CounterValue,
}
)

func parseServerStatsPacket(p chrony.ResponsePacket) (chrony.ReplyServerStats4, error) {
Expand Down Expand Up @@ -220,5 +280,23 @@ func (e Exporter) getServerstatsMetrics(logger *slog.Logger, ch chan<- prometheu
ch <- serverstatsNTPSpanSeconds.mustNewConstMetric(float64(serverstats.NTPSpanSeconds))
logger.Debug("Serverstats Timestamps Span", "ntp_timestamps_span", serverstats.NTPSpanSeconds)

ch <- serverstatsNTPDaemonRxTimestamps.mustNewConstMetric(float64(serverstats.NTPDaemonRxtimestamps))
logger.Debug("Serverstats Daemon Rx Timestamps", "ntp_daemon_rx_timestamps", serverstats.NTPDaemonRxtimestamps)

ch <- serverstatsNTPDaemonTxTimestamps.mustNewConstMetric(float64(serverstats.NTPDaemonTxtimestamps))
logger.Debug("Serverstats Daemon Tx Timestamps", "ntp_daemon_tx_timestamps", serverstats.NTPDaemonTxtimestamps)

ch <- serverstatsNTPKernelRxTimestamps.mustNewConstMetric(float64(serverstats.NTPKernelRxtimestamps))
logger.Debug("Serverstats Kernel Rx Timestamps", "ntp_kernel_rx_timestamps", serverstats.NTPKernelRxtimestamps)

ch <- serverstatsNTPKernelTxTimestamps.mustNewConstMetric(float64(serverstats.NTPKernelTxtimestamps))
logger.Debug("Serverstats Kernel Tx Timestamps", "ntp_kernel_tx_timestamps", serverstats.NTPKernelTxtimestamps)

ch <- serverstatsNTPHwRxTimestamps.mustNewConstMetric(float64(serverstats.NTPHwRxTimestamps))
logger.Debug("Serverstats Hardware Rx Timestamps", "ntp_hw_rx_timestamps", serverstats.NTPHwRxTimestamps)

ch <- serverstatsNTPHwTxTimestamps.mustNewConstMetric(float64(serverstats.NTPHwTxTimestamps))
logger.Debug("Serverstats Hardware Tx Timestamps", "ntp_hw_tx_timestamps", serverstats.NTPHwTxTimestamps)

return nil
}