On Wed, 26 Jun 2013, Kenyon Ralph wrote:

> On 2013-06-26T18:00:47+1000, Tim Connors <report...@rather.puzzling.org> 
> wrote:
> > Package: munin-plugins-core
> > Version: 2.0.6-4+deb7u1
> > Severity: normal
> >
> > Investigating why uptime plugin wasn't running, logs were showing the
> > ntp_state was timing out.  Running manually, I find one of the dynamic
> > peers isn't returning reverse DNS, and this simple patch fixes it
> > (only 1 second because it's not that critical if you don't resolve
> > successfully, and it tries twice, and you don't want to wait more than
> > 2 seconds when you only have 10 or so seconds to get through all the
> > plugins):
>
> I added 5-second timeouts to the plugin in this commit, and I haven't
> had any more timeout problems:
> https://github.com/munin-monitoring/munin/commit/e2a01b5be031f93fb3e2cdd00a28f1796727cd17

Although 5 seconds is a bit much because it actually turns to 10 seconds
by the time the second retry within libc is attempted (and we only have 60
seconds total to play with in munin-node, by the time we go through all
the other plugins, which might include ntp_states which also has the same
timeout issue.

Since most people have access to a reasonably good caching name server
(even their ISP will respond within 1 second after the first attempt, and
should keep it around for at least 5 minutes so the second and subsequent
lookups will get the cached result), I chose 1 second.

Now, the same bug is in ntp_states, but requires a small rewrite (copying
the DNS code from ntp_states without fixing up the irrelevant function
name; bad me) to fix.  Please consider incorporating a variation of that
too... (now I've finally got munin-node consistently taking under 60
seconds!):


--- /usr/share/munin/plugins/ntp_.old   2013-06-10 01:41:52.000000000 +1000
+++ /usr/share/munin/plugins/ntp_       2013-11-07 18:12:38.951852117 +1100
@@ -38,6 +38,46 @@
 use Net::hostent;
 use Socket;

+my $ret = undef;
+
+if (!eval "require Net::DNS;")
+{
+        $ret = "Net::DNS not found";
+        if (!defined $ARGV[0]) {
+                die $ret;
+        }
+}
+
+my $resolver = Net::DNS::Resolver->new;
+$resolver->tcp_timeout(1);
+$resolver->udp_timeout(1);
+
+# Takes an address and returns the Internet hostname
+sub make_names {
+        my $addr = shift;
+        my $host;
+        my $packet = $resolver->query($addr);
+
+        # Can use core perl routines (from the Socket module) to do
+        # the address -> hostname lookup in perls newer than 5.10.1
+        # with, but that's all I have to test with right now. So using
+        # libnet-dns-perl.
+
+        if ($packet) {
+                my @answer = $packet->answer;
+                foreach my $rr (@answer) {
+                        if ("PTR" eq $rr->type) {
+                                $host = $rr->ptrdname;
+                        }
+                }
+        }
+
+        $host = defined $host ? $host : $addr;
+        my $hostname = $host;
+
+        return $hostname;
+}
+
 my $nodelay = $ENV{'nodelay'} || 0;

 if ($ARGV[0] and $ARGV[0] eq "autoconf") {
@@ -67,8 +107,8 @@
                        $lcid = $lcid - 1;
                        $name = "LOCAL($lcid)";
                } else {
-                       $name = gethostbyaddr(inet_aton($addr));
-                       $name = defined $name ? $name->name : $addr;
+                       $name = make_names($addr);
+                       $name = defined $name ? $name : $addr;
                }
                $name = lc $name if exists $ENV{"lowercase"};
                $name =~ s/[\.\-()]/_/g;
@@ -93,8 +133,8 @@
                        $lcid = $lcid - 1;
                        $host = "LOCAL($lcid)"
                } else {
-                       $host = gethostbyaddr(inet_aton($addr));
-                       $host = defined $host ? $host->name : $addr;
+                       $host = make_names($addr);
+                       $host = defined $host ? $host : $addr;
                }
                $host = lc $host if exists $ENV{"lowercase"};
                my $host_ = $host;
@@ -127,8 +167,8 @@
                $lcid = $lcid - 1;
                $host = "LOCAL($lcid)"
        } else {
-               $host = gethostbyaddr(inet_aton($addr));
-               $host = defined $host ? $host->name : $addr;
+               $host = make_names($addr);
+               $host = defined $host ? $host : $addr;
        }
        $host = lc $host if exists $ENV{"lowercase"};
        $host =~ s/[\.\-()]/_/g;


-- 
Tim Connors


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to