Merge remote-tracking branch 'origin/pr/752' into wh_low_speed_limit
[collectd.git] / src / powerdns.c
index 29f6bca..151e09c 100644 (file)
@@ -18,7 +18,7 @@
  *
  * Author:
  *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  *
  * DESCRIPTION
  *   Queries a PowerDNS control socket for statistics
@@ -147,22 +147,34 @@ statname_lookup_t lookup_table[] = /* {{{ */
   {"recursing-questions",    "dns_question", "recurse"},
   {"tcp-queries",            "dns_question", "tcp"},
   {"udp-queries",            "dns_question", "udp"},
+  {"rd-queries",             "dns_question", "rd"},
 
   /* Answers */
   {"recursing-answers",      "dns_answer",   "recurse"},
   {"tcp-answers",            "dns_answer",   "tcp"},
   {"udp-answers",            "dns_answer",   "udp"},
+  {"recursion-unanswered",   "dns_answer",   "recursion-unanswered"},
+  {"udp-answers-bytes",      "total_bytes",  "udp-answers-bytes"},
 
   /* Cache stuff */
   {"packetcache-hit",        "cache_result", "packet-hit"},
   {"packetcache-miss",       "cache_result", "packet-miss"},
   {"packetcache-size",       "cache_size",   "packet"},
+  {"key-cache-size",         "cache_size",   "key"},
+  {"meta-cache-size",        "cache_size",   "meta"},
+  {"signature-cache-size",   "cache_size",   "signature"},
   {"query-cache-hit",        "cache_result", "query-hit"},
   {"query-cache-miss",       "cache_result", "query-miss"},
 
   /* Latency */
   {"latency",                "latency",      NULL},
 
+  /* DNS updates */
+  {"dnsupdate-answers",      "dns_answer",   "dnsupdate-answer"},
+  {"dnsupdate-changes",      "dns_question", "dnsupdate-changes"},
+  {"dnsupdate-queries",      "dns_question", "dnsupdate-queries"},
+  {"dnsupdate-refused",      "dns_answer",   "dnsupdate-refused"},
+
   /* Other stuff.. */
   {"corrupt-packets",        "ipt_packets",  "corrupt"},
   {"deferred-cache-inserts", "counter",      "cache-deferred_insert"},
@@ -175,6 +187,9 @@ statname_lookup_t lookup_table[] = /* {{{ */
   {"udp4-queries",           "dns_question", "queries-udp4"},
   {"udp6-answers",           "dns_answer",   "udp6"},
   {"udp6-queries",           "dns_question", "queries-udp6"},
+  {"security-status",        "dns_question", "security-status"},
+  {"udp-do-queries",         "dns_question", "udp-do_queries"},
+  {"signatures",             "counter",      "signatures"},
 
   /***********************
    * Recursor statistics *
@@ -224,8 +239,8 @@ statname_lookup_t lookup_table[] = /* {{{ */
   {"throttle-entries",    "gauge",        "entries-throttle"},
   {"unauthorized-tcp",    "counter",      "denied-unauthorized_tcp"},
   {"unauthorized-udp",    "counter",      "denied-unauthorized_udp"},
-  {"unexpected-packets",  "dns_answer",   "unexpected"}
-  /* {"uptime", "", ""} */
+  {"unexpected-packets",  "dns_answer",   "unexpected"},
+  {"uptime",              "uptime",       NULL}
 }; /* }}} */
 int lookup_table_length = STATIC_ARRAY_SIZE (lookup_table);
 
@@ -259,9 +274,6 @@ static void submit (const char *plugin_instance, /* {{{ */
     if (strcmp (lookup_table[i].name, pdns_type) == 0)
       break;
 
-  if (lookup_table[i].type == NULL)
-    return;
-
   if (i >= lookup_table_length)
   {
     INFO ("powerdns plugin: submit: Not found in lookup table: %s = %s;",
@@ -269,6 +281,9 @@ static void submit (const char *plugin_instance, /* {{{ */
     return;
   }
 
+  if (lookup_table[i].type == NULL)
+    return;
+
   type = lookup_table[i].type;
   type_instance = lookup_table[i].type_instance;
 
@@ -321,6 +336,9 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
 
   struct sockaddr_un sa_unix;
 
+  struct timeval stv_timeout;
+  cdtime_t cdt_timeout;
+
   sd = socket (PF_UNIX, item->socktype, 0);
   if (sd < 0)
   {
@@ -361,12 +379,13 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
       break;
     }
 
-    struct timeval timeout;
-    timeout.tv_sec=2;
-    if (timeout.tv_sec < interval_g * 3 / 4)
-      timeout.tv_sec = interval_g * 3 / 4;
-    timeout.tv_usec=0;
-    status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout));
+    cdt_timeout = plugin_get_interval () * 3 / 4;
+    if (cdt_timeout < TIME_T_TO_CDTIME_T (2))
+      cdt_timeout = TIME_T_TO_CDTIME_T (2);
+
+    CDTIME_T_TO_TIMEVAL (cdt_timeout, &stv_timeout);
+
+    status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &stv_timeout, sizeof (stv_timeout));
     if (status != 0)
     {
       FUNC_ERROR ("setsockopt");