@@ -108,9 +108,59 @@ var (
108
108
),
109
109
prometheus .GaugeValue ,
110
110
}
111
+
112
+ sourcesPeerOffset = typedDesc {
113
+ prometheus .NewDesc (
114
+ prometheus .BuildFQName (namespace , sourcesSubsystem , "peer_offset_seconds" ),
115
+ "Chrony sources peer offset" ,
116
+ []string {"source_address" , "source_name" },
117
+ nil ,
118
+ ),
119
+ prometheus .GaugeValue ,
120
+ }
121
+
122
+ sourcesPeerDelay = typedDesc {
123
+ prometheus .NewDesc (
124
+ prometheus .BuildFQName (namespace , sourcesSubsystem , "peer_delay_seconds" ),
125
+ "Chrony sources peer delay" ,
126
+ []string {"source_address" , "source_name" },
127
+ nil ,
128
+ ),
129
+ prometheus .GaugeValue ,
130
+ }
131
+
132
+ sourcesPeerDispersion = typedDesc {
133
+ prometheus .NewDesc (
134
+ prometheus .BuildFQName (namespace , sourcesSubsystem , "peer_dispersion_seconds" ),
135
+ "Chrony sources peer dispersion" ,
136
+ []string {"source_address" , "source_name" },
137
+ nil ,
138
+ ),
139
+ prometheus .GaugeValue ,
140
+ }
141
+
142
+ sourcesPeerResponseTime = typedDesc {
143
+ prometheus .NewDesc (
144
+ prometheus .BuildFQName (namespace , sourcesSubsystem , "peer_response_time_seconds" ),
145
+ "Chrony sources peer response time" ,
146
+ []string {"source_address" , "source_name" },
147
+ nil ,
148
+ ),
149
+ prometheus .GaugeValue ,
150
+ }
151
+
152
+ sourcesPeerJitterAsymmetry = typedDesc {
153
+ prometheus .NewDesc (
154
+ prometheus .BuildFQName (namespace , sourcesSubsystem , "peer_jitter_asymmetry_seconds" ),
155
+ "Chrony sources peer jitter asymmetry" ,
156
+ []string {"source_address" , "source_name" },
157
+ nil ,
158
+ ),
159
+ prometheus .GaugeValue ,
160
+ }
111
161
)
112
162
113
- func (e Exporter ) getSourcesMetrics (logger * slog.Logger , ch chan <- prometheus.Metric , client chrony.Client ) error {
163
+ func (e Exporter ) getSourcesMetrics (logger * slog.Logger , ch chan <- prometheus.Metric , client chrony.Client , collectNtpdata bool ) error {
114
164
packet , err := client .Communicate (chrony .NewSourcesPacket ())
115
165
if err != nil {
116
166
return err
@@ -157,6 +207,22 @@ func (e Exporter) getSourcesMetrics(logger *slog.Logger, ch chan<- prometheus.Me
157
207
ch <- sourcesPollInterval .mustNewConstMetric (math .Pow (2 , float64 (r .Poll )), sourceAddress , sourceName )
158
208
ch <- sourcesStateInfo .mustNewConstMetric (1.0 , sourceAddress , sourceName , r .State .String (), r .Mode .String ())
159
209
ch <- sourcesStratum .mustNewConstMetric (float64 (r .Stratum ), sourceAddress , sourceName )
210
+
211
+ if collectNtpdata {
212
+ ntpDataPacket , err := client .Communicate (chrony .NewNTPDataPacket (r .IPAddr ))
213
+ if err != nil {
214
+ return fmt .Errorf ("Failed to get ntpdata response for: %s" , r .IPAddr )
215
+ }
216
+ ntpData , ok := ntpDataPacket .(* chrony.ReplyNTPData )
217
+ if ! ok {
218
+ return fmt .Errorf ("Got wrong 'ntpdata' response: %q" , packet )
219
+ }
220
+ ch <- sourcesPeerOffset .mustNewConstMetric (ntpData .Offset , sourceAddress , sourceName )
221
+ ch <- sourcesPeerDelay .mustNewConstMetric (ntpData .PeerDelay , sourceAddress , sourceName )
222
+ ch <- sourcesPeerResponseTime .mustNewConstMetric (ntpData .ResponseTime , sourceAddress , sourceName )
223
+ ch <- sourcesPeerDispersion .mustNewConstMetric (ntpData .PeerDispersion , sourceAddress , sourceName )
224
+ ch <- sourcesPeerJitterAsymmetry .mustNewConstMetric (ntpData .JitterAsymmetry , sourceAddress , sourceName )
225
+ }
160
226
}
161
227
162
228
return nil
0 commit comments