dns_one 0.4.37 → 0.4.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2fc5f20cb89e4598dafa6f6629380674f751cb9
4
- data.tar.gz: b607a3f8d376cd5f72c3f7a3fa19e7a8fa7efb18
3
+ metadata.gz: 296dafdbba064fefc2ab86745dd516d80c0eee93
4
+ data.tar.gz: b20222d54553e1bb9c95bc7e1fd6d31594480470
5
5
  SHA512:
6
- metadata.gz: bd0c5a0208678999846c0832902699825e82e8bc9cfb301e8fbb2610f472b4bbf52462ca1714121e80b7833fefc1f19b3217660b6bc0f0457bd725e584002f2e
7
- data.tar.gz: 0073ae574a4db7381f79bb11840924044f9b189dad97e775121bd5fec7ff52b91330aa6658d1a1aba6a594cb75d9cb34bef640dfedfb16b58d1f3f6c1ebb32bb
6
+ metadata.gz: e06fdebdd04f7f013d606beeb25370531049fbaea8af66490b0c7ec5d1bc84ae3eb1cf6d890c1dec6a99e70685d500d4d83c8829d80a6ea21e032f86876ea503
7
+ data.tar.gz: 30abb3413dbcaacbc16a9d673f9151f0dc2b8645261d77742536faa273125949ffc2d6fe5afadb62be8fb80e3922ad28f6238772343a500fe6d0331c79e7dd73
@@ -1,5 +1,6 @@
1
1
  module DnsOne; class Stat
2
2
  DB_FNAME = "stat.db"
3
+ SQL_PROF = false
3
4
 
4
5
  def initialize conf = {}
5
6
  @conf = conf
@@ -12,7 +13,7 @@ module DnsOne; class Stat
12
13
 
13
14
  def save rcode, req_resource, cache
14
15
  Log.i "saving stat (user: #{ `id -un #{Process.uid}`.strip })"
15
- @db.execute(
16
+ rsql(
16
17
  "INSERT INTO responses (time, rcode, req_resource, cache) VALUES (?, ?, ?, ?)",
17
18
  [
18
19
  Time.now.to_i,
@@ -25,6 +26,7 @@ module DnsOne; class Stat
25
26
  Log.e e
26
27
  end
27
28
 
29
+ # select rcode, count(*) from responses where time > strftime('%s', 'now') - 300 group by rcode
28
30
  def get_counts counter, from = nil
29
31
  validate_counter counter
30
32
  validate_from from
@@ -40,7 +42,7 @@ module DnsOne; class Stat
40
42
 
41
43
  counts = {}
42
44
 
43
- @db.execute(s) do |row|
45
+ rsql(s) do |row|
44
46
  _counter, count = row
45
47
  counts[_counter] = count
46
48
  end
@@ -128,30 +130,17 @@ module DnsOne; class Stat
128
130
  end
129
131
 
130
132
  def create_tables
131
- sqls = []
132
-
133
- sqls << <<-SQL
133
+ @db.execute_batch <<-SQL
134
134
  create table responses (
135
135
  time int,
136
136
  rcode int,
137
137
  req_resource int,
138
138
  cache int
139
139
  );
140
- SQL
141
-
142
- sqls << <<-SQL
143
140
  CREATE INDEX responses_time_rcode ON responses (time, rcode);
144
- SQL
145
-
146
- sqls << <<-SQL
147
141
  CREATE INDEX responses_time_req_resource ON responses (time, req_resource);
148
- SQL
149
-
150
- sqls << <<-SQL
151
142
  CREATE INDEX responses_time_cache ON responses (time, cache);
152
143
  SQL
153
-
154
- sqls.each{|sql| @db.execute sql }
155
144
  end
156
145
 
157
146
 
@@ -169,5 +158,23 @@ module DnsOne; class Stat
169
158
  name
170
159
  end
171
160
 
161
+ def rsql sql
162
+ if SQL_PROF
163
+ t0 = Time.now
164
+ end
165
+
166
+ res = @db.execute sql
167
+
168
+ if SQL_PROF
169
+ @sql_profiler ||= Logger.new '/tmp/dnsone_sql_prof.log'
170
+ time = Time.now.strftime '%y%m%d-%H%M%S.%L'
171
+ dur = "%.3f" % ((Time.now - t0) * 1000.0)
172
+ _sql = sql.gsub /\n+/, ' '
173
+ @sql_profiler.info "#{time} #{dur} #{_sql}"
174
+ end
175
+
176
+ res
177
+ end
178
+
172
179
  end; end
173
180
 
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.37"
2
+ VERSION = "0.4.39"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.37
4
+ version: 0.4.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
@@ -177,7 +177,6 @@ files:
177
177
  - lib/dns_one/zone_search.rb
178
178
  - util/benchmark-cache_store.rb
179
179
  - util/dns_one.service
180
- - util/dnsone_munin_
181
180
  - util/sample_conf.yml
182
181
  homepage: https://tomlobato.github.io/dns_one/
183
182
  licenses:
@@ -1,186 +0,0 @@
1
- #!/root/.rbenv/shims/ruby
2
-
3
- # Install
4
-
5
- # wget https://raw.githubusercontent.com/tomlobato/dns_one/master/util/dnsone_munin_ -O /usr/local/sbin/dnsone_munin_
6
- # chmod 755 /usr/local/sbin/dnsone_munin_
7
- # dnsone_munin_ install
8
- # /etc/init.d/munin-node restart
9
-
10
- require 'active_support/core_ext/hash/conversions'
11
- require 'msgpack'
12
- require 'ostruct'
13
- require 'resolv'
14
-
15
- class MuninDnsOne
16
-
17
- CACHE_FILE = '/tmp/dns_one_cache'
18
- CACHE_EXPIRE = 30
19
-
20
- GRAPHS = {
21
- rcode: {
22
- percent: true,
23
- vlabel: '%',
24
- fields: %w(not_imp refused yx_domain yxrr_set nxrr_set not_auth not_zone badvers no_error badsig badkey badtime badmode nx_domain badalg badname form_err serv_fail).sort
25
- },
26
- req_resource: {
27
- percent: true,
28
- vlabel: '%',
29
- fields: %w(a aaaa any cname hinfo minfo mx ns ptr soa txt wks)
30
- },
31
- cache: {
32
- percent: true,
33
- vlabel: '%',
34
- fields: {
35
- hit: 'Domain found in cache.',
36
- miss: 'Domain not found in cache, requiring a backend access.',
37
- },
38
- },
39
- requests: {
40
- vlabel: 'count',
41
- fields: {
42
- requests: 'requests',
43
- },
44
- }
45
- }
46
-
47
- def initialize argv
48
- @argv = argv
49
- end
50
-
51
- def cli
52
- case @argv[0]
53
- when 'config'
54
- @param = get_params
55
- config
56
- when 'install'
57
- install
58
- else
59
- @param = get_params
60
- run
61
- end
62
- end
63
-
64
- private
65
-
66
- def graph
67
- GRAPHS[@param.graph]
68
- end
69
-
70
- def fields
71
- if graph[:fields].is_a? Hash
72
- graph[:fields]
73
- else
74
- _fields = {}
75
- graph[:fields].each do |field|
76
- _fields[field.to_sym] = field
77
- end
78
- _fields
79
- end
80
- end
81
-
82
- def config
83
- puts <<-CONFIG
84
- graph_category DnsOne
85
- graph_title #{@param.graph}
86
- graph_vlabel #{graph[:vlabel]}
87
- graph_args --base 1000 -l 0
88
-
89
- CONFIG
90
-
91
- fields.each_pair do |k, v|
92
- puts "#{k}.label #{k}"
93
- end
94
-
95
- exit 0
96
- end
97
-
98
- def run
99
- stats = get_stats[@param.graph.to_s]
100
-
101
- if graph[:percent]
102
- sum = stats.values.reduce(:+).to_f
103
- end
104
-
105
- fields.keys.each do |k|
106
- value = stats[k] || 0.0
107
- if graph[:percent]
108
- value *= 100 / sum
109
- end
110
- puts "#{k}.value #{ value }"
111
- end
112
-
113
- exit 0
114
- end
115
-
116
- # Util
117
-
118
- def get_params
119
- filename = File.basename __FILE__
120
-
121
- if filename =~ /^dnsone_(#{ GRAPHS.keys.join '|' })/
122
- graph_key = $1
123
- OpenStruct.new(
124
- graph: graph_key.to_sym,
125
- )
126
- else
127
- error "Invalid graph type for filename #{filename}."
128
- end
129
- end
130
-
131
- def get_stats
132
- if false and File.exists?(CACHE_FILE) and
133
- (Time.now - File.stat(CACHE_FILE).ctime) < CACHE_EXPIRE
134
- MessagePack.unpack File.open(CACHE_FILE, 'rb').read
135
- else
136
- stat = fetch_stats
137
- File.open(CACHE_FILE, 'wb', 0600).write MessagePack.pack(stat)
138
- stat
139
- end
140
- end
141
-
142
- def fetch_stats
143
- stat = {}
144
- section = nil
145
-
146
- `dns_one stats`.each_line do |l|
147
- if l =~ /---\s*(\S+)\s*---/
148
- section = $1
149
- elsif l =~ /^(.*?)\s+(.*)$/
150
- key = $1.to_sym
151
- val = $2.strip.to_f
152
- stat[section] ||= {}
153
- stat[section][key] = val
154
- end
155
- end
156
-
157
- stat["requests"] = {
158
- requests: stat["cache"].values.reduce(:+).to_i
159
- }
160
-
161
- stat
162
- end
163
-
164
- def install
165
- # Links
166
- links = []
167
- GRAPHS.keys.each do |graph_key|
168
- links << graph_key
169
- end
170
- target = File.expand_path(__FILE__)
171
- links.each do |link|
172
- system "ln -s #{target} /etc/munin/plugins/dnsone_#{link}"
173
- end
174
-
175
- # munin_node_conf
176
- munin_node_conf = "[dnsone_*]\nuser root\n\n"
177
- File.open('/etc/munin/plugin-conf.d/munin-node', 'a').write munin_node_conf
178
- end
179
-
180
- def error msg
181
- STDERR.puts msg
182
- exit 1
183
- end
184
- end
185
-
186
- MuninDnsOne.new(ARGV).cli