]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: add serverstats command
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 18 Jan 2016 16:09:36 +0000 (17:09 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 22 Jan 2016 12:26:38 +0000 (13:26 +0100)
Add a new command to obtain a server report with the new clientlog
statistics.

candm.h
clientlog.c
clientlog.h
cmdmon.c
pktlength.c
reports.h

diff --git a/candm.h b/candm.h
index cf7c317dca9e56da81731f339e4740313aa49e51..af55966ea64b0290f21aee13178b728655e9289f 100644 (file)
--- a/candm.h
+++ b/candm.h
@@ -91,7 +91,8 @@
 #define REQ_SMOOTHING 51
 #define REQ_SMOOTHTIME 52
 #define REQ_REFRESH 53
-#define N_REQUEST_TYPES 54
+#define REQ_SERVER_STATS 54
+#define N_REQUEST_TYPES 55
 
 /* Special utoken value used to log on with first exchange being the
    password.  (This time value has long since gone by) */
@@ -433,7 +434,8 @@ typedef struct {
 #define RPY_MANUAL_LIST 11
 #define RPY_ACTIVITY 12
 #define RPY_SMOOTHING 13
-#define N_REPLY_TYPES 14
+#define RPY_SERVER_STATS 14
+#define N_REPLY_TYPES 15
 
 /* Status codes */
 #define STT_SUCCESS 0
@@ -569,6 +571,15 @@ typedef struct {
   int32_t EOR;
 } RPY_ClientAccessesByIndex;
 
+typedef struct {
+  uint32_t ntp_hits;
+  uint32_t cmd_hits;
+  uint32_t ntp_drops;
+  uint32_t cmd_drops;
+  uint32_t log_drops;
+  int32_t EOR;
+} RPY_ServerStats;
+
 #define MAX_MANUAL_LIST_SAMPLES 16
 
 typedef struct {
@@ -630,6 +641,7 @@ typedef struct {
     RPY_Sourcestats sourcestats;
     RPY_Rtc rtc;
     RPY_ClientAccessesByIndex client_accesses_by_index;
+    RPY_ServerStats server_stats;
     RPY_ManualList manual_list;
     RPY_Activity activity;
     RPY_Smoothing smoothing;
index 942d85ef1b7a234b3a427bdbbd90f88966ede89e..48db784ed08a18782b73a0248d1c5f6e3357a9d9 100644 (file)
@@ -611,3 +611,15 @@ CLG_GetClientAccessReportByIndex(int index, RPT_ClientAccessByIndex_Report *repo
 
   return 1;
 }
+
+/* ================================================== */
+
+void
+CLG_GetServerStatsReport(RPT_ServerStatsReport *report)
+{
+  report->ntp_hits = total_ntp_hits;
+  report->cmd_hits = total_cmd_hits;
+  report->ntp_drops = total_ntp_drops;
+  report->cmd_drops = total_cmd_drops;
+  report->log_drops = total_record_drops;
+}
index 2f68e532f940167dbdd0855cf4a0d0f0f47527cf..6f77b3570f46c4962d68fb98c46cf8dc13bdaf5c 100644 (file)
@@ -42,5 +42,6 @@ extern int CLG_LimitCommandResponseRate(int index);
 
 extern int CLG_GetNumberOfIndices(void);
 extern int CLG_GetClientAccessReportByIndex(int index, RPT_ClientAccessByIndex_Report *report, struct timeval *now);
+extern void CLG_GetServerStatsReport(RPT_ServerStatsReport *report);
 
 #endif /* GOT_CLIENTLOG_H */
index 3322cb7ec735b17b73dd7720cc6cc0bc21a51ba4..e5b6cd2c925d205c8338f5561df760540993f24e 100644 (file)
--- a/cmdmon.c
+++ b/cmdmon.c
@@ -130,6 +130,7 @@ static const char permissions[] = {
   PERMIT_OPEN, /* SMOOTHING */
   PERMIT_AUTH, /* SMOOTHTIME */
   PERMIT_AUTH, /* REFRESH */
+  PERMIT_AUTH, /* SERVER_STATS */
 };
 
 /* ================================================== */
@@ -1146,6 +1147,22 @@ handle_refresh(CMD_Request *rx_message, CMD_Reply *tx_message)
   NSR_RefreshAddresses();
 }
 
+/* ================================================== */
+
+static void
+handle_server_stats(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+  RPT_ServerStatsReport report;
+
+  CLG_GetServerStatsReport(&report);
+  tx_message->reply = htons(RPY_SERVER_STATS);
+  tx_message->data.server_stats.ntp_hits = htonl(report.ntp_hits);
+  tx_message->data.server_stats.cmd_hits = htonl(report.cmd_hits);
+  tx_message->data.server_stats.ntp_drops = htonl(report.ntp_drops);
+  tx_message->data.server_stats.cmd_drops = htonl(report.cmd_drops);
+  tx_message->data.server_stats.log_drops = htonl(report.log_drops);
+}
+
 /* ================================================== */
 /* Read a packet and process it */
 
@@ -1534,6 +1551,10 @@ read_from_cmd_socket(void *anything)
           handle_refresh(&rx_message, &tx_message);
           break;
 
+        case REQ_SERVER_STATS:
+          handle_server_stats(&rx_message, &tx_message);
+          break;
+
         default:
           assert(0);
           break;
index a853465f56d47f066e0b372ba530d95dd601290b..4b24e409c9fa4ff257c32e476738a809bfbe37be 100644 (file)
@@ -152,6 +152,8 @@ command_unpadded_length(CMD_Request *r)
         return offsetof(CMD_Request, data.smoothtime.EOR);
       case REQ_REFRESH:
         return offsetof(CMD_Request, data.null.EOR);
+      case REQ_SERVER_STATS:
+        return offsetof(CMD_Request, data.null.EOR);
       default:
         /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
         assert(0);
@@ -308,6 +310,8 @@ PKL_CommandPaddingLength(CMD_Request *r)
       return PADDING_LENGTH(data.smoothtime.EOR, data.null.EOR);
     case REQ_REFRESH:
       return PADDING_LENGTH(data.null.EOR, data.null.EOR);
+    case REQ_SERVER_STATS:
+      return PADDING_LENGTH(data.null.EOR, data.server_stats.EOR);
     default:
       /* If we fall through the switch, it most likely means we've forgotten to implement a new case */
       assert(0);
@@ -363,6 +367,8 @@ PKL_ReplyLength(CMD_Reply *r)
         return offsetof(CMD_Reply, data.activity.EOR);
       case RPY_SMOOTHING:
         return offsetof(CMD_Reply, data.smoothing.EOR);
+      case RPY_SERVER_STATS:
+        return offsetof(CMD_Reply, data.server_stats.EOR);
       default:
         assert(0);
     }
index c6529d6353e53ec09400690e51aa5f42764ea37d..193d933c0ef3db055c5618f46677416a167f99a1 100644 (file)
--- a/reports.h
+++ b/reports.h
@@ -99,6 +99,14 @@ typedef struct {
   uint32_t last_cmd_hit_ago;
 } RPT_ClientAccessByIndex_Report;
 
+typedef struct {
+  uint32_t ntp_hits;
+  uint32_t cmd_hits;
+  uint32_t ntp_drops;
+  uint32_t cmd_drops;
+  uint32_t log_drops;
+} RPT_ServerStatsReport;
+
 typedef struct {
   struct timeval when;
   double slewed_offset;