]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: add interleaved stats to serverstats
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 20 Oct 2021 14:10:21 +0000 (16:10 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 21 Oct 2021 15:04:51 +0000 (17:04 +0200)
Report the number of received interleaved requests and current timestamp
count with their span.

Expand the serverstats description in chronyc man page.

candm.h
client.c
clientlog.c
cmdmon.c
doc/chronyc.adoc
pktlength.c
reports.h
test/simulation/110-chronyc
test/system/007-cmdmon

diff --git a/candm.h b/candm.h
index b560614ccbc06cecb3076993c0d0552fd6aff8b4..86d8107a97e8b9741edcf4c22c8ea9491565c2d1 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -516,7 +516,8 @@ typedef struct {
 #define RPY_CLIENT_ACCESSES_BY_INDEX3 21
 #define RPY_SERVER_STATS2 22
 #define RPY_SELECT_DATA 23
-#define N_REPLY_TYPES 24
+#define RPY_SERVER_STATS3 24
+#define N_REPLY_TYPES 25
 
 /* Status codes */
 #define STT_SUCCESS 0
@@ -659,6 +660,9 @@ typedef struct {
   uint32_t cmd_drops;
   uint32_t log_drops;
   uint32_t ntp_auth_hits;
+  uint32_t ntp_interleaved_hits;
+  uint32_t ntp_timestamps;
+  uint32_t ntp_span_seconds;
   int32_t EOR;
 } RPY_ServerStats;
 
index 4180ac5eedd040c9db952cba0989814ed01843d1..a9aa6b509efd7ec6ae8bd58daca52cae13b39640 100644 (file)
--- a/client.c
+++ b/client.c
@@ -2459,7 +2459,7 @@ process_cmd_serverstats(char *line)
   CMD_Reply reply;
 
   request.command = htons(REQ_SERVER_STATS);
-  if (!request_reply(&request, &reply, RPY_SERVER_STATS2, 0))
+  if (!request_reply(&request, &reply, RPY_SERVER_STATS3, 0))
     return 0;
 
   print_report("NTP packets received       : %U\n"
@@ -2469,7 +2469,10 @@ process_cmd_serverstats(char *line)
                "Client log records dropped : %U\n"
                "NTS-KE connections accepted: %U\n"
                "NTS-KE connections dropped : %U\n"
-               "Authenticated NTP packets  : %U\n",
+               "Authenticated NTP packets  : %U\n"
+               "Interleaved NTP packets    : %U\n"
+               "NTP timestamps held        : %U\n"
+               "NTP timestamp span         : %U\n",
                (unsigned long)ntohl(reply.data.server_stats.ntp_hits),
                (unsigned long)ntohl(reply.data.server_stats.ntp_drops),
                (unsigned long)ntohl(reply.data.server_stats.cmd_hits),
@@ -2478,6 +2481,9 @@ process_cmd_serverstats(char *line)
                (unsigned long)ntohl(reply.data.server_stats.nke_hits),
                (unsigned long)ntohl(reply.data.server_stats.nke_drops),
                (unsigned long)ntohl(reply.data.server_stats.ntp_auth_hits),
+               (unsigned long)ntohl(reply.data.server_stats.ntp_interleaved_hits),
+               (unsigned long)ntohl(reply.data.server_stats.ntp_timestamps),
+               (unsigned long)ntohl(reply.data.server_stats.ntp_span_seconds),
                REPORT_END);
 
   return 1;
index 09af04be98c2f2ed937eea7d558a260277a05e65..2a18a97f6a6a707e455d882c24f19f1860b2933e 100644 (file)
@@ -155,6 +155,7 @@ static NtpTimestampMap ntp_ts_map;
 static uint32_t total_hits[MAX_SERVICES];
 static uint32_t total_drops[MAX_SERVICES];
 static uint32_t total_ntp_auth_hits;
+static uint32_t total_ntp_interleaved_hits;
 static uint32_t total_record_drops;
 
 #define NSEC_PER_SEC 1000000000U
@@ -921,6 +922,10 @@ CLG_DisableNtpTimestamps(NTP_int64 *rx_ts)
 
   if (find_ntp_rx_ts(ntp64_to_int64(rx_ts), &index))
     get_ntp_tss(index)->flags |= NTPTS_DISABLED;
+
+  /* This assumes the function is called only to prevent multiple
+     interleaved responses to the same timestamp */
+  total_ntp_interleaved_hits++;
 }
 
 /* ================================================== */
@@ -1027,4 +1032,9 @@ CLG_GetServerStatsReport(RPT_ServerStatsReport *report)
   report->cmd_drops = total_drops[CLG_CMDMON];
   report->log_drops = total_record_drops;
   report->ntp_auth_hits = total_ntp_auth_hits;
+  report->ntp_interleaved_hits = total_ntp_interleaved_hits;
+  report->ntp_timestamps = ntp_ts_map.size;
+  report->ntp_span_seconds = ntp_ts_map.size > 1 ?
+                             (get_ntp_tss(ntp_ts_map.size - 1)->rx_ts -
+                              get_ntp_tss(0)->rx_ts) >> 32 : 0;
 }
index 8cbcd8064b4bb8c242f66011b0f9836b22ca06cf..fee398b44cb34a62d84179c55135fe986f624fe0 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -1164,7 +1164,7 @@ handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message)
   RPT_ServerStatsReport report;
 
   CLG_GetServerStatsReport(&report);
-  tx_message->reply = htons(RPY_SERVER_STATS2);
+  tx_message->reply = htons(RPY_SERVER_STATS3);
   tx_message->data.server_stats.ntp_hits = htonl(report.ntp_hits);
   tx_message->data.server_stats.nke_hits = htonl(report.nke_hits);
   tx_message->data.server_stats.cmd_hits = htonl(report.cmd_hits);
@@ -1173,6 +1173,9 @@ handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message)
   tx_message->data.server_stats.cmd_drops = htonl(report.cmd_drops);
   tx_message->data.server_stats.log_drops = htonl(report.log_drops);
   tx_message->data.server_stats.ntp_auth_hits = htonl(report.ntp_auth_hits);
+  tx_message->data.server_stats.ntp_interleaved_hits = htonl(report.ntp_interleaved_hits);
+  tx_message->data.server_stats.ntp_timestamps = htonl(report.ntp_timestamps);
+  tx_message->data.server_stats.ntp_span_seconds = htonl(report.ntp_span_seconds);
 }
 
 /* ================================================== */
index fbfea41605ad2adbc9919c727674167b22d8b3c6..cfb5eb86ab3d806f9fff1af0711dbac38852990c 100644 (file)
@@ -1107,13 +1107,9 @@ The columns are as follows:
   received/accepted.
 
 [[serverstats]]*serverstats*::
-The *serverstats* command displays how many valid NTP and command requests, and
-NTS-KE connections, *chronyd* operating as a server received from clients, and
-how many of them were dropped due to rate limiting. It also displays how many
-client log records were dropped due to the memory limit configured by the
-<<chrony.conf.adoc#clientloglimit,*clientloglimit*>> directive and how many of
-the NTP requests (from those which were not dropped) were authenticated. An
-example of the output is shown below.
+The *serverstats* command displays NTP and command server statistics.
++
+An example of the output is shown below.
 +
 ----
 NTP packets received       : 1598
@@ -1124,7 +1120,47 @@ Client log records dropped : 0
 NTS-KE connections accepted: 3
 NTS-KE connections dropped : 0
 Authenticated NTP packets  : 189
+Interleaved NTP packets    : 43
+NTP timestamps held        : 44
+NTP timestamp span         : 120
 ----
++
+The fields have the following meaning:
++
+*NTP packets received*:::
+The number of valid NTP requests received by the server.
+*NTP packets dropped*:::
+The number of NTP requests dropped by the server due to rate limiting
+(configured by the <<chrony.conf.adoc#ratelimit,*ratelimit*>> directive).
+*Command packets received*:::
+The number of command requests received by the server.
+*Command packets dropped*:::
+The number of command requests dropped by the server due to rate limiting
+(configured by the <<chrony.conf.adoc#cmdratelimit,*cmdratelimit*>> directive).
+*Client log records dropped*:::
+The number of client log records dropped by the server to limit the memory use
+(configured by the <<chrony.conf.adoc#clientloglimit,*clientloglimit*>>
+directive).
+*NTS-KE connections accepted*:::
+The number of NTS-KE connections accepted by the server.
+*NTS-KE connections dropped*:::
+The number of NTS-KE connections dropped by the server due to rate limiting
+(configured by the <<chrony.conf.adoc#ntsratelimit,*ntsratelimit*>> directive).
+*Authenticated NTP packets*:::
+The number of received NTP requests that were authenticated (with a symmetric
+key or NTS).
+*Interleaved NTP packets*:::
+The number of received NTP requests that were detected to be in the interleaved
+mode.
+*NTP timestamps held*:::
+The number of pairs of receive and transmit timestamps that the server is
+currently holding in memory for clients using the interleaved mode.
+*NTP timestamp span*:::
+The interval (in seconds) covered by the currently held NTP timestamps.
+{blank}::
++
+Note that the numbers reported by this overflow to zero after 4294967295
+(32-bit values).
 
 [[allow]]*allow* [*all*] [_subnet_]::
 The effect of the allow command is identical to the
index 1e318d60a43c02388587bcb9a087aed696c32608..642e47757c903dc7b2d666d5ddca80cf0ec289e7 100644 (file)
@@ -154,8 +154,9 @@ static const uint16_t reply_lengths[] = {
   RPY_LENGTH_ENTRY(ntp_source_name),            /* NTP_SOURCE_NAME */
   RPY_LENGTH_ENTRY(auth_data),                  /* AUTH_DATA */
   RPY_LENGTH_ENTRY(client_accesses_by_index),   /* CLIENT_ACCESSES_BY_INDEX3 */
-  RPY_LENGTH_ENTRY(server_stats),               /* SERVER_STATS2 */
+  0,                                            /* SERVER_STATS2 - not supported */
   RPY_LENGTH_ENTRY(select_data),                /* SELECT_DATA */
+  RPY_LENGTH_ENTRY(server_stats),               /* SERVER_STATS3 */
 };
 
 /* ================================================== */
index 4508e8f3a6185d31e1d73b4a4a7bba280921c9ba..c403c2395bee2adfe937785ab80b408a53b406a2 100644 (file)
--- a/reports.h
+++ b/reports.h
@@ -117,6 +117,9 @@ typedef struct {
   uint32_t cmd_drops;
   uint32_t log_drops;
   uint32_t ntp_auth_hits;
+  uint32_t ntp_interleaved_hits;
+  uint32_t ntp_timestamps;
+  uint32_t ntp_span_seconds;
 } RPT_ServerStatsReport;
 
 typedef struct {
index e95dfa0d2a38cf82003ffa4231a0f56b410c1e2d..7e4d3271461220f4da974d192bb6d46051f4e3fe 100755 (executable)
@@ -241,7 +241,10 @@ Command packets dropped    : 0
 Client log records dropped : 0
 NTS-KE connections accepted: 0
 NTS-KE connections dropped : 0
-Authenticated NTP packets  : 0$" || test_fail
+Authenticated NTP packets  : 0
+Interleaved NTP packets    : 0
+NTP timestamps held        : 0
+NTP timestamp span         : 0$" || test_fail
 
 chronyc_conf="
 deny all
index fe2b0067a5436dd15da5e4ce85f14d10755f064b..bbcc12f046c17de9c5b2a660ca58d1fb9c5d4bfd 100755 (executable)
@@ -110,7 +110,10 @@ Command packets dropped    : 0
 Client log records dropped : 0
 NTS-KE connections accepted: 0
 NTS-KE connections dropped : 0
-Authenticated NTP packets  : 0$" || test_fail
+Authenticated NTP packets  : 0
+Interleaved NTP packets    : 0
+NTP timestamps held        : 0
+NTP timestamp span         : 0$"|| test_fail
 
 run_chronyc "manual on" || test_fail
 check_chronyc_output "^200 OK$" || test_fail