2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 01:59:26 +00:00

Expose the incoming transfers' rates in the statistics channel

Expose the average transfer rate (in bytes-per-second) during the
last full 'min-transfer-rate-in <bytes> <minutes>' minutes interval.
If no such interval has passed yet, then the overall average rate is
reported instead.
This commit is contained in:
Aram Sargsyan 2024-11-27 10:34:40 +00:00 committed by Arаm Sаrgsyаn
parent b9c6aa24f8
commit c701b590e4
5 changed files with 51 additions and 6 deletions

View File

@ -931,6 +931,7 @@
<th>Messages Received</th> <th>Messages Received</th>
<th>Records Received</th> <th>Records Received</th>
<th>Bytes Received</th> <th>Bytes Received</th>
<th>Transfer Rate (B/s)</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -959,6 +960,7 @@
<td><xsl:value-of select="nmsg"/></td> <td><xsl:value-of select="nmsg"/></td>
<td><xsl:value-of select="nrecs"/></td> <td><xsl:value-of select="nrecs"/></td>
<td><xsl:value-of select="nbytes"/></td> <td><xsl:value-of select="nbytes"/></td>
<td><xsl:value-of select="rate"/></td>
</tr> </tr>
</xsl:for-each> </xsl:for-each>
</tbody> </tbody>

View File

@ -1488,6 +1488,7 @@ xfrin_xmlrender(dns_zone_t *zone, void *arg) {
unsigned int nmsg = 0; unsigned int nmsg = 0;
unsigned int nrecs = 0; unsigned int nrecs = 0;
uint64_t nbytes = 0; uint64_t nbytes = 0;
uint64_t rate = 0;
statlevel = dns_zone_getstatlevel(zone); statlevel = dns_zone_getstatlevel(zone);
if (statlevel == dns_zonestat_none) { if (statlevel == dns_zonestat_none) {
@ -1701,7 +1702,7 @@ xfrin_xmlrender(dns_zone_t *zone, void *arg) {
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
if (is_running) { if (is_running) {
dns_xfrin_getstats(xfr, &nmsg, &nrecs, &nbytes); dns_xfrin_getstats(xfr, &nmsg, &nrecs, &nbytes, &rate);
} }
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "nmsg")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "nmsg"));
TRY0(xmlTextWriterWriteFormatString(writer, "%u", nmsg)); TRY0(xmlTextWriterWriteFormatString(writer, "%u", nmsg));
@ -1712,6 +1713,9 @@ xfrin_xmlrender(dns_zone_t *zone, void *arg) {
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "nbytes")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "nbytes"));
TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, nbytes)); TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, nbytes));
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "rate"));
TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, rate));
TRY0(xmlTextWriterEndElement(writer));
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "ixfr")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "ixfr"));
if (is_running && is_first_data_received) { if (is_running && is_first_data_received) {
@ -2559,6 +2563,7 @@ xfrin_jsonrender(dns_zone_t *zone, void *arg) {
unsigned int nmsg = 0; unsigned int nmsg = 0;
unsigned int nrecs = 0; unsigned int nrecs = 0;
uint64_t nbytes = 0; uint64_t nbytes = 0;
uint64_t rate = 0;
statlevel = dns_zone_getstatlevel(zone); statlevel = dns_zone_getstatlevel(zone);
if (statlevel == dns_zonestat_none) { if (statlevel == dns_zonestat_none) {
@ -2756,7 +2761,7 @@ xfrin_jsonrender(dns_zone_t *zone, void *arg) {
} }
if (is_running) { if (is_running) {
dns_xfrin_getstats(xfr, &nmsg, &nrecs, &nbytes); dns_xfrin_getstats(xfr, &nmsg, &nrecs, &nbytes, &rate);
} }
json_object_object_add(xfrinobj, "nmsg", json_object_object_add(xfrinobj, "nmsg",
json_object_new_int64((int64_t)nmsg)); json_object_new_int64((int64_t)nmsg));
@ -2766,6 +2771,10 @@ xfrin_jsonrender(dns_zone_t *zone, void *arg) {
xfrinobj, "nbytes", xfrinobj, "nbytes",
json_object_new_int64(nbytes > INT64_MAX ? INT64_MAX json_object_new_int64(nbytes > INT64_MAX ? INT64_MAX
: (int64_t)nbytes)); : (int64_t)nbytes));
json_object_object_add(xfrinobj, "rate",
json_object_new_int64(rate > INT64_MAX
? INT64_MAX
: (int64_t)rate));
if (is_running && is_first_data_received) { if (is_running && is_first_data_received) {
json_object_object_add( json_object_object_add(

View File

@ -7835,6 +7835,12 @@ Incoming Zone Transfers
64-bit unsigned Integer. This is the number of usable bytes 64-bit unsigned Integer. This is the number of usable bytes
of DNS data. It does not include transport overhead. of DNS data. It does not include transport overhead.
``Transfer Rate (B/s)`` (``rate``)
64 bit unsigned Integer. This is the average zone transfer rate in
bytes-per-second during the latest full interval that is configured by the
:any:`min-transfer-rate-in` configuration option. If no such interval
has passed yet, then the overall average rate is reported instead.
.. note:: .. note::
Depending on the current state of the transfer, some of the Depending on the current state of the transfer, some of the
values may be empty or set to ``-`` (meaning "not available"). values may be empty or set to ``-`` (meaning "not available").

View File

@ -140,10 +140,13 @@ dns_xfrin_getendserial(dns_xfrin_t *xfr);
void void
dns_xfrin_getstats(dns_xfrin_t *xfr, unsigned int *nmsgp, unsigned int *nrecsp, dns_xfrin_getstats(dns_xfrin_t *xfr, unsigned int *nmsgp, unsigned int *nrecsp,
uint64_t *nbytesp); uint64_t *nbytesp, uint64_t *ratep);
/*%< /*%<
* Get various statistics values of the xfrin object: number of the received * Get various statistics values of the xfrin object: number of the received
* messages, number of the received records, number of the received bytes. * messages, number of the received records, number of the received bytes,
* and the average transfer rate (in bytes-per-second) during the last full
* 'min-transfer-rate-in <bytes> <minutes>' minutes interval. If no such
* interval has passed yet, then the overall average rate is reported instead.
* *
* Requires: * Requires:
*\li 'xfr' is a valid dns_xfrin_t. *\li 'xfr' is a valid dns_xfrin_t.

View File

@ -154,6 +154,7 @@ struct dns_xfrin {
atomic_uint nrecs; /*%< Number of records recvd */ atomic_uint nrecs; /*%< Number of records recvd */
atomic_uint_fast64_t nbytes; /*%< Number of bytes received */ atomic_uint_fast64_t nbytes; /*%< Number of bytes received */
_Atomic(isc_time_t) start; /*%< Start time of the transfer */ _Atomic(isc_time_t) start; /*%< Start time of the transfer */
atomic_uint_fast64_t rate_bytes_per_second;
_Atomic(dns_transport_type_t) soa_transport_type; _Atomic(dns_transport_type_t) soa_transport_type;
atomic_uint_fast32_t end_serial; atomic_uint_fast32_t end_serial;
@ -975,13 +976,21 @@ xfrin_minratecheck(void *arg) {
const uint64_t nbytes = atomic_load_relaxed(&xfr->nbytes); const uint64_t nbytes = atomic_load_relaxed(&xfr->nbytes);
const uint64_t min = dns_zone_getminxfrratebytesin(xfr->zone); const uint64_t min = dns_zone_getminxfrratebytesin(xfr->zone);
uint64_t rate = nbytes - xfr->nbytes_saved;
if (nbytes - xfr->nbytes_saved < min) { if (rate < min) {
isc_timer_stop(xfr->min_rate_timer); isc_timer_stop(xfr->min_rate_timer);
xfrin_fail(xfr, ISC_R_TIMEDOUT, xfrin_fail(xfr, ISC_R_TIMEDOUT,
"minimum transfer rate reached"); "minimum transfer rate reached");
} else { } else {
xfr->nbytes_saved = nbytes; xfr->nbytes_saved = nbytes;
/*
* Calculate and store for the statistics channel the transfer
* rate in bytes-per-second for the latest interval.
*/
rate /= dns_zone_getminxfrratesecondsin(xfr->zone);
atomic_store_relaxed(&xfr->rate_bytes_per_second, rate);
} }
} }
@ -1046,13 +1055,29 @@ dns_xfrin_getendserial(dns_xfrin_t *xfr) {
void void
dns_xfrin_getstats(dns_xfrin_t *xfr, unsigned int *nmsgp, unsigned int *nrecsp, dns_xfrin_getstats(dns_xfrin_t *xfr, unsigned int *nmsgp, unsigned int *nrecsp,
uint64_t *nbytesp) { uint64_t *nbytesp, uint64_t *ratep) {
REQUIRE(VALID_XFRIN(xfr)); REQUIRE(VALID_XFRIN(xfr));
REQUIRE(nmsgp != NULL && nrecsp != NULL && nbytesp != NULL); REQUIRE(nmsgp != NULL && nrecsp != NULL && nbytesp != NULL);
uint64_t rate = atomic_load_relaxed(&xfr->rate_bytes_per_second);
if (rate == 0) {
/*
* Likely the first 'min-transfer-rate-in <bytes> <minutes>'
* minutes interval hasn't passed yet. Calculate the overall
* average transfer rate instead.
*/
isc_time_t now = isc_time_now();
isc_time_t start = atomic_load_relaxed(&xfr->start);
uint64_t sec = isc_time_microdiff(&now, &start) / US_PER_SEC;
if (sec > 0) {
rate = atomic_load_relaxed(&xfr->nbytes) / sec;
}
}
SET_IF_NOT_NULL(nmsgp, atomic_load_relaxed(&xfr->nmsg)); SET_IF_NOT_NULL(nmsgp, atomic_load_relaxed(&xfr->nmsg));
SET_IF_NOT_NULL(nrecsp, atomic_load_relaxed(&xfr->nrecs)); SET_IF_NOT_NULL(nrecsp, atomic_load_relaxed(&xfr->nrecs));
SET_IF_NOT_NULL(nbytesp, atomic_load_relaxed(&xfr->nbytes)); SET_IF_NOT_NULL(nbytesp, atomic_load_relaxed(&xfr->nbytes));
SET_IF_NOT_NULL(ratep, rate);
} }
const isc_sockaddr_t * const isc_sockaddr_t *