-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbind2dog
executable file
·68 lines (56 loc) · 1.34 KB
/
bind2dog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
use strict;
use warnings;
use DataDog::DogStatsd;
use File::Slurp;
#TODO: handle options
my $debug = 0;
my $dogstatsd = DataDog::DogStatsd->new;
$dogstatsd->increment( 'dnet.script_runs') unless $debug;
my ($logfile) = @ARGV;
follow_file($logfile);
sub follow_file {
my($filename) = @_;
unless (-e $filename) {
warn "$filename missing";
return;
}
parse_bind_stats($filename);
}
sub parse_bind_stats {
my ($filename) = @_;
unless (-e $filename) {
warn "$filename missing";
return;
}
my @stats_lines = read_file($filename);
print scalar(@stats_lines) . " lines in $filename\n";
my ($section,$dumptime,$view);
foreach my $line (@stats_lines) {
chomp($line);
if ($line =~ /^[+][+] (.*) [+][+]/) {
$section = $1;
$view = '';
print "SECTION $section\n";
} elsif ($line =~ /^[+][+][+].*[+][+][+] \((\d+)\)/) {
# opening line
$dumptime = $1;
print "dumped at $dumptime\n";
} elsif ($line =~ /^--- /) {
# closing line
} elsif ($line =~ /^\[Common\]/) {
$view = 'Common';
} elsif ($line =~ /^\[View: (\w+)[ \]]/) {
# view subsection
$view = $1;
print "$section has subsection $view\n";
} elsif ($line =~ /^\s*(\d+) (.*)$/) {
# an actual stat
my $value = $1;
my $key = $2;
# print "$section/$view $key -> $value\n";
} else {
print "$section unhandled $line\n";
}
}
}