Skip to content

Commit

Permalink
Add new chrony serverstats counters to exposed serverstats metrics (#87)
Browse files Browse the repository at this point in the history
Exposes the additional NTP packet timestamping counter serverstats
metrics introduced in `chronyd` version `4.4`.

Signed-off-by: Raphael Seebacher <raphael@seebachers.ch>
  • Loading branch information
raphaelthomas authored Oct 27, 2024
1 parent 3ea2eac commit e90bda9
Showing 1 changed file with 78 additions and 0 deletions.
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
}

0 comments on commit e90bda9

Please sign in to comment.