dns_one 0.4.30 → 0.4.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -1
- data/lib/dns_one/cli.rb +1 -7
- data/lib/dns_one/server.rb +2 -1
- data/lib/dns_one/setup.rb +1 -0
- data/lib/dns_one/stat.rb +65 -37
- data/lib/dns_one/version.rb +1 -1
- data/lib/dns_one.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86b8305fbb1e6d4c2eec401c5b67ace08e282c2b
|
4
|
+
data.tar.gz: 4cf1e386c035351ba310619da3221df4ba7bd212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 536fb7c338ac4ea364a86601c5c9292e20150306b733b7d7992172a252b5cd84079828d42c755a420fa724cdf22249f7465df1eb73923ed14803feddeec6dce3
|
7
|
+
data.tar.gz: 8c15909797901a1ac9e88482faeca08e70d6d57ea25334d07aaab878011f0bf0776f207492a310927886c229bb57212facfcb2294ac521b1c7cbf1955ea35cfb
|
data/.gitignore
CHANGED
data/lib/dns_one/cli.rb
CHANGED
@@ -3,7 +3,6 @@ require "thor"
|
|
3
3
|
require 'sqlite3'
|
4
4
|
require "dns_one"
|
5
5
|
require "dns_one/setup"
|
6
|
-
require "dns_one/stat"
|
7
6
|
|
8
7
|
class DnsOne::CLI < Thor
|
9
8
|
|
@@ -59,11 +58,6 @@ class DnsOne::CLI < Thor
|
|
59
58
|
|
60
59
|
desc "stats", "show counters"
|
61
60
|
def stats
|
62
|
-
|
63
|
-
[
|
64
|
-
stat.get_counts(:rcode),
|
65
|
-
stat.get_counts(:req_resource),
|
66
|
-
stat.get_counts(:cache)
|
67
|
-
]
|
61
|
+
DnsOne::Stat.print
|
68
62
|
end
|
69
63
|
end
|
data/lib/dns_one/server.rb
CHANGED
@@ -15,7 +15,7 @@ module DnsOne; class Server
|
|
15
15
|
def initialize conf, conf_zone_search
|
16
16
|
@conf = conf
|
17
17
|
@zone_search = ZoneSearch.instance.setup conf_zone_search
|
18
|
-
@stat = Stat.new
|
18
|
+
@stat = Stat.new
|
19
19
|
end
|
20
20
|
|
21
21
|
def run
|
@@ -30,6 +30,7 @@ module DnsOne; class Server
|
|
30
30
|
RExec.change_user run_as
|
31
31
|
end
|
32
32
|
Log.i "Running as #{RExec.current_user}"
|
33
|
+
File.chown DnsOne::DnsOne::STAT_DB, RExec.current_user
|
33
34
|
end
|
34
35
|
|
35
36
|
match(/(.+)/) do |t| # transaction
|
data/lib/dns_one/setup.rb
CHANGED
data/lib/dns_one/stat.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
module DnsOne; class Stat
|
2
|
+
DB_FNAME = "stat.db"
|
2
3
|
|
3
4
|
def initialize conf = {}
|
4
5
|
@conf = conf
|
6
|
+
|
7
|
+
# Setup logger and current working dir
|
8
|
+
DnsOne.new
|
9
|
+
|
5
10
|
ensure_db
|
6
11
|
end
|
7
12
|
|
@@ -42,6 +47,49 @@ module DnsOne; class Stat
|
|
42
47
|
counts
|
43
48
|
end
|
44
49
|
|
50
|
+
def self.print
|
51
|
+
stat = new(db_file: DnsOne::DnsOne::STAT_DB, readonly: true)
|
52
|
+
%w(rcode req_resource cache).each do |key|
|
53
|
+
puts "--- #{key} ---"
|
54
|
+
stat.get_counts(key.to_sym).each_pair do |k, v|
|
55
|
+
_k = case key
|
56
|
+
when 'rcode'
|
57
|
+
stat.rcodes[k]
|
58
|
+
when 'req_resource'
|
59
|
+
stat.request_resources[k]
|
60
|
+
when 'cache'
|
61
|
+
k == 0 ? :miss : :hit
|
62
|
+
end
|
63
|
+
puts "#{_k || k}\t#{v}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def rcodes
|
69
|
+
unless defined? @@rcodes
|
70
|
+
@@rcodes = Hash[
|
71
|
+
Resolv::DNS::RCode.constants.map{|c|
|
72
|
+
[
|
73
|
+
Resolv::DNS::RCode.const_get(c),
|
74
|
+
const_underscore(c)
|
75
|
+
]
|
76
|
+
}
|
77
|
+
]
|
78
|
+
end
|
79
|
+
@@rcodes
|
80
|
+
end
|
81
|
+
|
82
|
+
def request_resources
|
83
|
+
unless defined? @@request_resources
|
84
|
+
@@request_resources = {}
|
85
|
+
%w(A AAAA ANY CNAME HINFO MINFO MX NS PTR SOA TXT WKS).each do |res|
|
86
|
+
val = Object.const_get("Resolv::DNS::Resource::IN::#{res}")::TypeValue
|
87
|
+
@@request_resources[val] = res.downcase
|
88
|
+
end
|
89
|
+
end
|
90
|
+
@@request_resources
|
91
|
+
end
|
92
|
+
|
45
93
|
private
|
46
94
|
|
47
95
|
def validate_counter counter
|
@@ -64,8 +112,16 @@ module DnsOne; class Stat
|
|
64
112
|
|
65
113
|
def ensure_db
|
66
114
|
new_db = !File.exists?(db_file)
|
67
|
-
|
68
|
-
|
115
|
+
|
116
|
+
opts = {}
|
117
|
+
opts[:readonly] = true if @conf[:readonly]
|
118
|
+
|
119
|
+
@db = SQLite3::Database.new db_file, opts
|
120
|
+
|
121
|
+
if new_db
|
122
|
+
File.chmod 0644, db_file
|
123
|
+
create_tables
|
124
|
+
end
|
69
125
|
end
|
70
126
|
|
71
127
|
def create_tables
|
@@ -80,20 +136,16 @@ module DnsOne; class Stat
|
|
80
136
|
);
|
81
137
|
SQL
|
82
138
|
|
83
|
-
sqls <<
|
84
|
-
CREATE INDEX
|
85
|
-
SQL
|
86
|
-
|
87
|
-
sqls << <<-SQL
|
88
|
-
CREATE INDEX responses_rcode ON responses (rcode);
|
139
|
+
sqls << <<-SQL
|
140
|
+
CREATE INDEX responses_time_rcode ON responses (time, rcode);
|
89
141
|
SQL
|
90
142
|
|
91
|
-
sqls <<
|
92
|
-
CREATE INDEX
|
143
|
+
sqls << <<-SQL
|
144
|
+
CREATE INDEX responses_time_req_resource ON responses (time, req_resource);
|
93
145
|
SQL
|
94
146
|
|
95
|
-
sqls <<
|
96
|
-
CREATE INDEX
|
147
|
+
sqls << <<-SQL
|
148
|
+
CREATE INDEX responses_time_cache ON responses (time, cache);
|
97
149
|
SQL
|
98
150
|
|
99
151
|
sqls.each{|sql| @db.execute sql }
|
@@ -101,18 +153,7 @@ module DnsOne; class Stat
|
|
101
153
|
|
102
154
|
|
103
155
|
def db_file
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
def request_resources
|
108
|
-
unless defined? @@request_resources
|
109
|
-
@@request_resources = {}
|
110
|
-
%w(A AAAA ANY CNAME HINFO MINFO MX NS PTR SOA TXT WKS).each do |res|
|
111
|
-
val = Object.const_get("Resolv::DNS::Resource::IN::#{res}")::TypeValue
|
112
|
-
@@request_resources[val] = res.downcase
|
113
|
-
end
|
114
|
-
end
|
115
|
-
@@request_resources
|
156
|
+
DB_FNAME
|
116
157
|
end
|
117
158
|
|
118
159
|
def const_underscore name
|
@@ -125,18 +166,5 @@ module DnsOne; class Stat
|
|
125
166
|
name
|
126
167
|
end
|
127
168
|
|
128
|
-
def rcodes
|
129
|
-
unless @@rcodes
|
130
|
-
@@rcodes = Hash[
|
131
|
-
Resolv::DNS::RCode.constants.map{|c|
|
132
|
-
[
|
133
|
-
Resolv::DNS::RCode.const_get(c),
|
134
|
-
const_underscore(c)
|
135
|
-
]
|
136
|
-
}
|
137
|
-
]
|
138
|
-
end
|
139
|
-
@@rcodes
|
140
|
-
end
|
141
169
|
end; end
|
142
170
|
|
data/lib/dns_one/version.rb
CHANGED
data/lib/dns_one.rb
CHANGED