[collectd] [Patch] Bind plugin: Add support for per-zone stats in v3 XML

Bruno Prémont bonbons at linux-vserver.org
Sat Nov 15 22:21:21 CET 2014


Contrary to Victor's saying in commit 78e89b2e0c205 (bind plugin: add
support for the new XML v3 API.), XML v3 API does support per-zone
statistics.

By default those statistics are limited to zone serial as if
  zone-statistics terse;
was listed in each zone definition block.

To obtain full statistics the above default must be overridden with:
  zone-statistics full;

Signed-off-by: Bruno Prémont <bonbons at linux-vserver.org>
---

diff --git a/src/bind.c b/src/bind.c
--- a/src/bind.c	2014-11-15 18:22:56.859427723 +0100
+++ b/src/bind.c	2014-11-15 18:14:45.644410680 +0100
@@ -718,25 +718,40 @@ static int bind_xml_stats_handle_zone (i
   int i;
   size_t j;
 
+  if (version >= 3)
-  path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
-  if (path_obj == NULL)
   {
+    char *n = (char *) xmlGetProp (node, BAD_CAST "name");
+    char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
+    if (n && c)
+    {
+      zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
+      snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
+    }
+    xmlFree(n);
+    xmlFree(c);
-    ERROR ("bind plugin: xmlXPathEvalExpression failed.");
-    return (-1);
   }
+  else
-
-  for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
   {
+    path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
+    if (path_obj == NULL)
+    {
+      ERROR ("bind plugin: xmlXPathEvalExpression failed.");
+      return (-1);
+    }
+
+    for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+    {
+      zone_name = (char *) xmlNodeListGetString (doc,
+          path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
+      if (zone_name != NULL)
+        break;
+    }
+    xmlXPathFreeObject (path_obj);
-    zone_name = (char *) xmlNodeListGetString (doc,
-        path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
-    if (zone_name != NULL)
-      break;
   }
 
   if (zone_name == NULL)
   {
     ERROR ("bind plugin: Could not determine zone name.");
-    xmlXPathFreeObject (path_obj);
     return (-1);
   }
 
@@ -758,9 +751,8 @@ static int bind_xml_stats_handle_zone (i
   xmlFree (zone_name);
   zone_name = NULL;
 
-  if (j >= views_num)
+  if (j >= view->zones_num)
   {
-    xmlXPathFreeObject (path_obj);
     return (0);
   }
 
@@ -786,14 +790,31 @@ static int bind_xml_stats_handle_zone (i
     ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
         view->name, zone_name);
 
+    if (version == 3)
+    {
+      list_info_ptr_t list_info =
+      {
+        plugin_instance,
+        /* type = */ "dns_qtype"
+      };
+      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
+        /* callback = */ bind_xml_table_callback,
+        /* user_data = */ &table_ptr,
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
+      bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
+        /* callback = */ bind_xml_list_callback,
+        /* user_data = */ &list_info,
+        doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
+    else
+    {
-    bind_parse_generic_value_list (/* xpath = */ "counters",
-        /* callback = */ bind_xml_table_callback,
-        /* user_data = */ &table_ptr,
-        doc, path_ctx, current_time, DS_TYPE_COUNTER);
+      bind_parse_generic_value_list (/* xpath = */ "counters",
+          /* callback = */ bind_xml_table_callback,
+          /* user_data = */ &table_ptr,
+          doc, path_ctx, current_time, DS_TYPE_COUNTER);
+    }
   } /* }}} */
 
-  xmlXPathFreeObject (path_obj);
-
   return (0);
 } /* }}} int bind_xml_stats_handle_zone */
 
@@ -968,8 +968,7 @@ static int bind_xml_stats_handle_view (int version, xmlDoc *doc, /* {{{ */
         doc, path_ctx, current_time, DS_TYPE_GAUGE);
   } /* }}} */
 
-  // v3 does not provide per-zone stats any more
-  if (version < 3 && view->zones_num > 0)
+  if (view->zones_num > 0)
     bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
         current_time);
 
--



More information about the collectd mailing list