-static int chrony_read (void)
-{
- //plugin_dispatch_values (&vl);
- int status,now_src;
- char ip_addr_str0[ IPV6_STR_MAX_SIZE];
- char ip_addr_str1[IPV6_STR_MAX_SIZE];
-
- size_t chrony_resp_size;
- tChrony_Request chrony_req,chrony_req1;
- tChrony_Response chrony_resp,chrony_resp1;
-
- DEBUG("chrony plugin: Requesting data");
- chrony_init_req(&chrony_req);
- status = chrony_query (REQ_N_SOURCES, &chrony_req, &chrony_resp, &chrony_resp_size);
- if (status != 0)
- {
- ERROR ("chrony plugin: chrony_query (REQ_N_SOURCES) failed with status %i", status);
- return (status);
- }
-
- int n_sources = ntohl(chrony_resp.body.n_sources.f_n_sources);
- DEBUG("chrony plugin: Getting data of %d clock sources", n_sources);
-
- for (now_src = 0; now_src < n_sources; ++now_src)
- {
- chrony_init_req(&chrony_req);
- chrony_init_req(&chrony_req1);
- chrony_req.body.source_data.f_index = htonl(now_src);
- chrony_req1.body.source_stats.f_index = htonl(now_src);
- status = chrony_query(REQ_SOURCE_DATA, &chrony_req, &chrony_resp, &chrony_resp_size);
- if (status != 0)
- {
- ERROR ("chrony plugin: chrony_query (REQ_SOURCE_DATA) failed with status %i", status);
- return (status);
- }
- status = chrony_query(REQ_SOURCE_STATS, &chrony_req1, &chrony_resp1, &chrony_resp_size);
- if (status != 0)
- {
- ERROR ("chrony plugin: chrony_query (REQ_SOURCE_STATS) failed with status %i", status);
- return (status);
- }
- memset(ip_addr_str0,0,sizeof(ip_addr_str0));
- niptoha(&chrony_resp.body.source_data.addr,ip_addr_str0,sizeof(ip_addr_str0));
- DEBUG("chrony plugin: Source[%d] data: .addr = %s, .poll = %u, .stratum = %u, .state = %u, .mode = %u, .flags = %u, .reach = %u, .latest_meas_ago = %u, .orig_latest_meas = %f, .latest_meas = %f, .latest_meas_err = %f",
- now_src,
- ip_addr_str0,
- ntohs(chrony_resp.body.source_data.f_poll),
- ntohs(chrony_resp.body.source_data.f_stratum),
- ntohs(chrony_resp.body.source_data.f_state),
- ntohs(chrony_resp.body.source_data.f_mode),
- ntohs(chrony_resp.body.source_data.f_flags),
- ntohs(chrony_resp.body.source_data.f_reachability),
- ntohl(chrony_resp.body.source_data.f_since_sample),
- ntohf(chrony_resp.body.source_data.f_origin_latest_meas),
- ntohf(chrony_resp.body.source_data.f_latest_meas),
- ntohf(chrony_resp.body.source_data.f_latest_meas_err));
-#if 1
- memset(ip_addr_str1,0,sizeof(ip_addr_str1));
- niptoha(&chrony_resp1.body.source_stats.addr,ip_addr_str1,sizeof(ip_addr_str1));
- DEBUG("chrony plugin: Source[%d] stat: .addr = %s, .ref_id= %u, .n_samples = %u, .n_runs = %u, .span_seconds = %u, .rtc_seconds_fast = %f, .rtc_gain_rate_ppm = %f, .skew_ppm= %f, .est_offset = %f, .est_offset_err = %f",
- now_src,
- ip_addr_str1,
- ntohl(chrony_resp1.body.source_stats.f_ref_id),
- ntohl(chrony_resp1.body.source_stats.f_n_samples),
- ntohl(chrony_resp1.body.source_stats.f_n_runs),
- ntohl(chrony_resp1.body.source_stats.f_span_seconds),
- ntohf(chrony_resp1.body.source_stats.f_rtc_seconds_fast),
- ntohf(chrony_resp1.body.source_stats.f_rtc_gain_rate_ppm),
- ntohf(chrony_resp1.body.source_stats.f_skew_ppm),
- ntohf(chrony_resp1.body.source_stats.f_est_offset),
- ntohf(chrony_resp1.body.source_stats.f_est_offset_err));
-#endif
-#if 1
- chrony_push_data("clock_stratum", ip_addr_str0,ntohs(chrony_resp.body.source_data.f_stratum));
- chrony_push_data("clock_state", ip_addr_str0,ntohs(chrony_resp.body.source_data.f_state));
- chrony_push_data("clock_mode", ip_addr_str0,ntohs(chrony_resp.body.source_data.f_mode));
- chrony_push_data("clock_reachability",ip_addr_str0,ntohs(chrony_resp.body.source_data.f_reachability));
- chrony_push_data("clock_last_meas", ip_addr_str0,ntohs(chrony_resp.body.source_data.f_since_sample));
- chrony_push_data("clock_skew_ppm", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_skew_ppm));
- chrony_push_data("frequency_error", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_rtc_gain_rate_ppm)); //unit: ppm
- chrony_push_data("time_offset", ip_addr_str1,ntohf(chrony_resp1.body.source_stats.f_est_offset)); //unit: s
+
+static int
+chrony_request_daemon_stats(void)
+{
+ /* Perform Tracking request */
+ int rc;
+ size_t chrony_resp_size;
+ tChrony_Request chrony_req;
+ tChrony_Response chrony_resp;
+
+ chrony_init_req(&chrony_req);
+ rc =
+ chrony_query(REQ_TRACKING, &chrony_req, &chrony_resp, &chrony_resp_size);
+ if (rc != 0)
+ {
+ ERROR(PLUGIN_NAME ": chrony_query (REQ_TRACKING) failed with status %i",
+ rc);
+ return rc;
+ }
+#if COLLECT_DEBUG
+ {
+ char src_addr[IPV6_STR_MAX_SIZE] = { 0 };
+ niptoha(&chrony_resp.body.tracking.addr, src_addr, sizeof(src_addr));
+ DEBUG(PLUGIN_NAME ": Daemon stat: .addr = %s, .ref_id= %u, .stratum = %u, .leap_status = %u, .ref_time = %u:%u:%u, .current_correction = %f, .last_offset = %f, .rms_offset = %f, .freq_ppm = %f, .skew_ppm = %f, .root_delay = %f, .root_dispersion = %f, .last_update_interval = %f", src_addr, ntohs(chrony_resp.body.tracking.f_ref_id),
+ ntohs(chrony_resp.body.tracking.f_stratum),
+ ntohs(chrony_resp.body.tracking.f_leap_status),
+ ntohl(chrony_resp.body.tracking.f_ref_time.tv_sec_high),
+ ntohl(chrony_resp.body.tracking.f_ref_time.tv_sec_low),
+ ntohl(chrony_resp.body.tracking.f_ref_time.tv_nsec),
+ ntohf(chrony_resp.body.tracking.f_current_correction),
+ ntohf(chrony_resp.body.tracking.f_last_offset),
+ ntohf(chrony_resp.body.tracking.f_rms_offset),
+ ntohf(chrony_resp.body.tracking.f_freq_ppm),
+ ntohf(chrony_resp.body.tracking.f_skew_ppm),
+ ntohf(chrony_resp.body.tracking.f_root_delay),
+ ntohf(chrony_resp.body.tracking.f_root_dispersion),
+ ntohf(chrony_resp.body.tracking.f_last_update_interval));
+ }