dns_one 0.4.34 → 0.4.35

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: a71e4738e469dca6259edb0d2f8cf63b758d655f
4
- data.tar.gz: 4f625bf190b16ca76effd3d4dac4c7a763c92b4d
3
+ metadata.gz: d90cfd8e37c93aa0ffb5110110aabcf5e7a28eea
4
+ data.tar.gz: bc22d9dd4b5c9aab56a9546bbc5b45a65454862d
5
5
  SHA512:
6
- metadata.gz: '018db44416746224cdcf73bbd5ab8a0362195cbfc24a62a2d262a7ec2ed9d924e5dba77dde4359b6b914e54bb36a66f34a9a5cc04a8400ec2f8c941b7ef96230'
7
- data.tar.gz: ec3ae33290c5b58a58acf2beacba8850f4e8879240be891631394448c74eb0f5c40a9f207a42cf0bf00a8aece9433132602d7fae06e640799b2edb201fe65ff5
6
+ metadata.gz: 8d9ac4198ba572f9016c1d42451c812e5cafb288a7a7670d6eaf52427a57551ec2bdc6fac97f3fdd15856d06dd79fdce54ee88248841e1a825833ac639046e28
7
+ data.tar.gz: d9b7f7d590339a1708f8a513614e8fbed2f0db8c9e4e88f2305a5a8da514423a6e14a89fb145a840422a2c8b04e2f37dbbf86f0c4bd2c3105d110543c9ea64ca
@@ -11,7 +11,7 @@ module DnsOne; class Stat
11
11
  end
12
12
 
13
13
  def save rcode, req_resource, cache
14
- Log.i "saving stat (user: #{ `id -un #{Process.uid}` })"
14
+ Log.i "saving stat (user: #{ `id -un #{Process.uid}`.strip })"
15
15
  @db.execute(
16
16
  "INSERT INTO responses (time, rcode, req_resource, cache) VALUES (?, ?, ?, ?)",
17
17
  [
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.4.34"
2
+ VERSION = "0.4.35"
3
3
  end
@@ -0,0 +1,146 @@
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
+ vlabel: 'Return Code count',
23
+ 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)
24
+ },
25
+ req_resource: {
26
+ vlabel: 'Request resource count',
27
+ fields: %w(a aaaa any cname hinfo minfo mx ns ptr soa txt wks)
28
+ },
29
+ cache: {
30
+ vlabel: 'count',
31
+ fields: {
32
+ hit: 'Domain found in cache.',
33
+ miss: 'Domain not found in cache, requiring a backend access.',
34
+ },
35
+ },
36
+ }
37
+
38
+ def initialize argv
39
+ @argv = argv
40
+ end
41
+
42
+ def cli
43
+ case @argv[0]
44
+ when 'config'
45
+ @param = get_params
46
+ config
47
+ when 'install'
48
+ install
49
+ else
50
+ @param = get_params
51
+ run
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def graph
58
+ GRAPHS[@param.graph]
59
+ end
60
+
61
+ def config
62
+ puts <<-CONFIG
63
+ graph_category Passenger
64
+ graph_title #{@param.graph}
65
+ graph_vlabel #{graph[:vlabel]}
66
+ graph_args --base 1000 -l 0
67
+ graph_info GI
68
+
69
+ CONFIG
70
+
71
+ graph[:fields].each do |f|
72
+ k = Array === f ? f[0] : f
73
+ v = Array === f ? f[1] : f
74
+ puts "#{k}.label #{v}"
75
+ end
76
+
77
+ exit 0
78
+ end
79
+
80
+ def run
81
+ get_stats[@param.graph.to_s].each_pair do |k, v|
82
+ puts "#{k}.value #{v}"
83
+ end
84
+ exit 0
85
+ end
86
+
87
+ # Util
88
+
89
+ def get_params
90
+ filename = File.basename __FILE__
91
+
92
+ if filename =~ /^dnsone_(#{ GRAPHS.keys.join '|' })/
93
+ graph_key = $1
94
+ OpenStruct.new(
95
+ graph: graph_key.to_sym,
96
+ )
97
+ else
98
+ error "Invalid graph type for filename #{filename}."
99
+ end
100
+ end
101
+
102
+ def get_stats
103
+ if false and File.exists?(CACHE_FILE) and
104
+ (Time.now - File.stat(CACHE_FILE).ctime) < CACHE_EXPIRE
105
+ MessagePack.unpack File.open(CACHE_FILE, 'rb').read
106
+ else
107
+ stat = fetch_stats
108
+ File.open(CACHE_FILE, 'wb', 0600).write MessagePack.pack(stat)
109
+ stat
110
+ end
111
+ end
112
+
113
+ def fetch_stats
114
+ stat = {}
115
+ section = nil
116
+ `dns_one stats`.each_line do |l|
117
+ if l =~ /---\s*(\S+)\s*---/
118
+ section = $1
119
+ elsif l =~ /^(.*?)\s+(.*)$/
120
+ key = $1.to_sym
121
+ val = $2.strip
122
+ stat[section] ||= {}
123
+ stat[section][key] = val
124
+ end
125
+ end
126
+ stat
127
+ end
128
+
129
+ def install
130
+ links = []
131
+ GRAPHS.keys.each do |graph_key|
132
+ links << graph_key
133
+ end
134
+ target = File.expand_path(__FILE__)
135
+ links.each do |link|
136
+ system "ln -s #{target} /etc/munin/plugins/dnsone_#{link}"
137
+ end
138
+ end
139
+
140
+ def error msg
141
+ STDERR.puts msg
142
+ exit 1
143
+ end
144
+ end
145
+
146
+ MuninDnsOne.new(ARGV).cli
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.34
4
+ version: 0.4.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
@@ -177,6 +177,7 @@ 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
180
181
  - util/sample_conf.yml
181
182
  homepage: https://tomlobato.github.io/dns_one/
182
183
  licenses: