summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Kelley <simon@thekelleys.org.uk>2022-09-15 22:43:08 +0100
committerSimon Kelley <simon@thekelleys.org.uk>2022-09-15 22:43:08 +0100
commit84bd46ddd7a639b457daf74722f3bcc0c11e65df (patch)
tree4ff130c6651a50b0325fdc5e12addd3c2b1af421
parent271790685adfb5917c9e410cb6b3d86052618af7 (diff)
downloaddnsmasq-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.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/dbus.c b/src/dbus.c
index 43cae30..782fdc9 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -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;