Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove old monitor tool

  • Loading branch information...
commit 16bfa3e2c53ecb2d27b38cd5cb5c8603c3e1172f 1 parent 1a95c58
@abh authored
Showing with 0 additions and 203 deletions.
  1. +0 −83 monitor/lib/Monitor.pm
  2. +0 −47 monitor/monitor.pl
  3. +0 −73 monitor/monitor_rrd.pl
View
83 monitor/lib/Monitor.pm
@@ -1,83 +0,0 @@
-package Monitor;
-use strict;
-use warnings;
-use base 'Exporter';
-our @EXPORT_OK = qw(read_config dbh);
-
-use JSON 2.12;
-
-use Net::DNS::Resolver ();
-
-my $resolv = Net::DNS::Resolver->new();
-
-my $config_file = 'servers.json';
-
-
-my $json = JSON->new->relaxed(1);
-
-sub dbh {
- my $dbh = DBI->connect("dbi:SQLite:dbname=measurements.db",
- "", "", {RaiseError => 1})
- or die "Could not open DB measurements.db: " . DBI->errstr;
- setup_table($dbh);
- return $dbh;
-}
-sub read_config {
-
- open my $json_fh, '<', $config_file or die "Could not open $config_file: $!\n";
- my $data = eval { local $/ = undef; <$json_fh> };
- close $json_fh;
-
- my $config = $json->decode($data);
- die "no zones configured" unless $config->{zones};
- $config->{servers} ||= {};
-
- my @ips;
- for my $zone (@{$config->{zones}}) {
- my $ns_query = $resolv->query($zone, 'NS');
- for my $rr ($ns_query->answer) {
- next unless $rr->type eq "NS";
- my $ns = $rr->nsdname;
-
- #print "NS: $ns\n";
- my $a_query = $resolv->query($ns, 'A');
- for my $rr ($a_query->answer) {
- next unless $rr->type eq "A";
- my $ip = $rr->address;
- my $server = $config->{servers}->{$ip};
- unless ($server) {
- warn qq[no configuration for\n "$ip": { "name": "" },\n];
- $config = $config->{servers}->{$ip} = {name => $ns};
- }
-
- #print " - IP: $ip\n";
- $server->{aliases}->{$ns} = 1;
- $server->{zones} ||= [];
- push @{$server->{zones}}, $zone;
- }
- }
- }
-
- for my $ip (keys %{$config->{servers}}) {
- my $c = $config->{servers}->{$ip};
- my @ip = split /\./, $ip;
- $c->{ip24} = 256*256*256*$ip[0] + 256*256*$ip[1] + 256*$ip[2] + $ip[3];
- }
-
- return $config;
-}
-
-sub setup_table {
- my $dbh = shift;
- $dbh->do
- (q[create table if not exists measurements (
- ip int,
- measurement_time int,
- queries int,
- query_time float
- );
- ]);
-}
-
-
-1;
View
47 monitor/monitor.pl
@@ -1,47 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-use Net::DNS::Resolver ();
-use Time::HiRes qw(time);
-
-use DBI;
-use Data::Dumper;
-use lib 'lib';
-use Monitor qw(read_config dbh);
-
-my $resolv = Net::DNS::Resolver->new();
-
-my $dbh = dbh();
-
-my $config = read_config();
-collect_query_counts();
-
-sub collect_query_counts {
-
- my $sth_insert = $dbh->prepare
- (q[insert into measurements
- (ip, measurement_time, queries, query_time)
- values (?,?,?,?)]
- );
-
- for my $ip (keys %{$config->{servers}}) {
- my $c = $config->{servers}->{$ip};
- #print "checking $ip/$c->{name}\n";
- $resolv->nameservers($ip);
- my $time = time;
- my $status_query = $resolv->query('status.pool.ntp.org', 'TXT');
- my $elapsed = time - $time;
- for my $rr ($status_query->answer) {
- next unless $rr->type eq "TXT";
- #print $rr->rdatastr, "\n";
- my ($queries) = ($rr->rdatastr =~ m/q: (\d+)/)[0];
- #print "Q: $queries\n";
- my $ip24 = $c->{ip24};
- $sth_insert->execute($ip24, int $time, $queries, $elapsed);
- }
- }
-
-}
-
-1;
View
73 monitor/monitor_rrd.pl
@@ -1,73 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-use lib 'lib';
-use Monitor qw(read_config dbh);
-
-use DBI;
-use Data::Dumper;
-use RRD::Simple;
-
-my $dbh = dbh;
-
-my $config = read_config();
-
-
-for my $ip (keys %{$config->{servers}}) {
- my $c = $config->{servers}->{$ip};
-
- my $file = "rrd/$ip.rrd";
-
- my $rrd = RRD::Simple->new
- (
- file => "rrd/$ip.rrd",
- rrdtool => "/opt/local/bin/rrdtool",
- tmpdir => "/tmp",
- cf => [ qw(AVERAGE MAX MIN) ],
- default_dstype => "DERIVE",
- on_missing_ds => "add",
- );
- $rrd->create('3years',
- queries => 'DERIVE',
- ) unless -e $file;
-
- system("rrdtool tune $file --minimum queries:0 --maximum queries:1000");
-
- my $last = $rrd->last;
-
- my $data = $dbh->selectall_arrayref
- (q[select measurement_time, queries from measurements
- where ip = ? and measurement_time > ?
- order by measurement_time],
- undef, $c->{ip24}, $last
- );
-
- for my $r (@$data) {
- next if $last == $r->[0];
- $last = $r->[0];
- $rrd->update($file,
- $r->[0],
- queries => $r->[1],
- );
- }
-
-
-
- my %rtn = $rrd->graph(
- destination => "graphs",
- basename => "$ip",
- timestamp => "rrd",
- #periods => [ qw(week month) ], # omit to generate all graphs
- #sources => [ qw(queries) ],
- #source_colors => [ qw(ff0000) ],
- source_labels => [ ("Queries/sec") ],
- source_drawtypes => [ qw(LINE1) ],
- line_thickness => 1,
- extended_legend => 1,
- title => "Queries/sec for $ip",
- width => '420',
- height => '150',
- );
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.