diff options
author | Simon Kelley <simon@thekelleys.org.uk> | 2022-09-15 22:43:08 +0100 |
---|---|---|
committer | Simon Kelley <simon@thekelleys.org.uk> | 2022-09-15 22:43:08 +0100 |
commit | 84bd46ddd7a639b457daf74722f3bcc0c11e65df (patch) | |
tree | 4ff130c6651a50b0325fdc5e12addd3c2b1af421 | |
parent | 271790685adfb5917c9e410cb6b3d86052618af7 (diff) | |
download | dnsmasq-84bd46ddd7a639b457daf74722f3bcc0c11e65df.tar.gz |
Combine server stats from all records for the same server in DBUS method.
The DBUS per-server stats method should combine the stats from
different records (for different domains) in the same way at the
logging code.
-rw-r--r-- | src/dbus.c | 49 |
1 files changed, 31 insertions, 18 deletions
@@ -672,27 +672,40 @@ static DBusMessage *dbus_get_server_metrics(DBusMessage* message) dbus_message_iter_init_append(reply, &server_iter); dbus_message_iter_open_container(&server_iter, DBUS_TYPE_ARRAY, "a{ss}", &server_array); + + /* sum counts from different records for same server */ + for (serv = daemon->servers; serv; serv = serv->next) + serv->flags &= ~SERV_MARK; for (serv = daemon->servers; serv; serv = serv->next) - { - unsigned int port; - - dbus_message_iter_open_container(&server_array, DBUS_TYPE_ARRAY, "{ss}", &dict_array); - - port = prettyprint_addr(&serv->addr, daemon->namebuff); - add_dict_entry(&dict_array, "address", daemon->namebuff); - - add_dict_int(&dict_array, "port", port); - add_dict_int(&dict_array, "queries", serv->queries); - add_dict_int(&dict_array, "failed_queries", serv->failed_queries); - add_dict_int(&dict_array, "nxdomain", serv->nxdomain_replies); - - if (strlen(serv->domain) != 0) - add_dict_entry(&dict_array, "domain", serv->domain); - - dbus_message_iter_close_container(&server_array, &dict_array); - } + if (!(serv->flags & SERV_MARK)) + { + unsigned int port; + unsigned int queries = 0, failed_queries = 0, nxdomain_replies = 0; + struct server *serv1; + for (serv1 = serv; serv1; serv1 = serv1->next) + if (!(serv1->flags & SERV_MARK) && sockaddr_isequal(&serv->addr, &serv1->addr)) + { + serv1->flags |= SERV_MARK; + queries += serv1->queries; + failed_queries += serv1->failed_queries; + nxdomain_replies += serv1->nxdomain_replies; + } + + dbus_message_iter_open_container(&server_array, DBUS_TYPE_ARRAY, "{ss}", &dict_array); + + port = prettyprint_addr(&serv->addr, daemon->namebuff); + add_dict_entry(&dict_array, "address", daemon->namebuff); + + add_dict_int(&dict_array, "port", port); + add_dict_int(&dict_array, "queries", serv->queries); + add_dict_int(&dict_array, "failed_queries", serv->failed_queries); + add_dict_int(&dict_array, "nxdomain", serv->nxdomain_replies); + + dbus_message_iter_close_container(&server_array, &dict_array); + } + dbus_message_iter_close_container(&server_iter, &server_array); return reply; |