dns_one 0.5.11 → 0.5.12

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: f12f10496fca1e19fe6106fb11be22ddeaf59c67
4
- data.tar.gz: 1476e1bf132d0c6481affd30c9b6183366674fe4
3
+ metadata.gz: f81dde3459b31d4c83ba7bb115f03a1ed708b21d
4
+ data.tar.gz: bb87f0b070fda97d18cfc9923657619d99c257e4
5
5
  SHA512:
6
- metadata.gz: ea7a2b8153302481094af3cd822c4585bd05b774dcee61bd20d9a63cc47d435362e12d50d3b25db070c1e046d2fba950a4a8b70733d8d0a60d5e61fc21983dfe
7
- data.tar.gz: 8149ccdec1a471fd53d02826948a4452dec0b7878c66bd1307e73d678506af11421085464531bc01c3bdd18103a45a0e8e5762960ef1cd0a1228866092fd500f
6
+ metadata.gz: 91830beaf2f9d7b72ae7b77e2d384b6d53701ee9f99337fa2845c6ea8c0657799ad2017e693164add1b3da7f1e84bff3648a6aa7cf1411e1b65ce4c082c88428
7
+ data.tar.gz: b85b09c99d752241540905b2f578b7e59bc72f61a5e60426677dbbbcb0c46b3c8092d85aa21ed7ae4716b19a7e6917f5e7e5a7f47f2b35836259dbd0b7392bb5
@@ -2,15 +2,19 @@ module DnsOne; module ReqLog; class Account
2
2
 
3
3
  def initialize
4
4
  @conf = Global.conf
5
+
5
6
  @stat = {}
7
+ @stat_mutex = Mutex.new
8
+
6
9
  @last_stat = nil
7
- @mutex = Mutex.new
8
- open_socket
9
- reap
10
+ @last_stat_mutex = Mutex.new
11
+
12
+ Thread.new { open_socket }
13
+ Thread.new { reap }
10
14
  end
11
15
 
12
16
  def on_response ip_address, domain_name, res_class, rcode, resp_log, from_cache
13
- @mutex.synchronize {
17
+ @stat_mutex.synchronize {
14
18
  @stat[:requests] ||= 0
15
19
  @stat[:requests] += 1
16
20
 
@@ -31,48 +35,47 @@ module DnsOne; module ReqLog; class Account
31
35
  Global.logger.error e.desc
32
36
  end
33
37
 
38
+ def update_last_stat stat
39
+ if !@allow_update_last_stat
40
+ @allow_update_last_stat = true
41
+ return
42
+ end
43
+ @last_stat_mutex.synchronize {
44
+ @last_stat = stat
45
+ }
46
+ end
47
+
34
48
  def reap
35
- Thread.new do
36
- loop do
37
- sleep (300 - Time.now.to_f % 300)
38
- @mutex.synchronize {
39
- @last_stat = @stat.deep_dup
40
- reset @stat
41
- }
42
- end
49
+ loop do
50
+ sleep (300 - Time.now.to_f % 300)
51
+ stat = nil
52
+ @stat_mutex.synchronize {
53
+ stat = @stat.deep_dup
54
+ reset @stat
55
+ }
56
+ update_last_stat stat
57
+ rescue => e
58
+ Global.logger.error e.desc
59
+ sleep 10
43
60
  end
44
61
  end
45
62
 
63
+ def write_socket sock
64
+ last_stat = @last_stat_mutex.synchronize{ @last_stat.deep_dup }
65
+ sock.puts last_stat.to_json
66
+ rescue => e
67
+ Global.logger.error e.desc
68
+ end
69
+
46
70
  def open_socket
47
- conf = @conf
48
- mutex = @mutex
49
- stat = @stat
50
- last_stat = @last_stat
51
- sock = Thread.new do
52
- sleep 1
53
- begin
54
- Socket.unix_server_loop(Global.conf.log_req_socket_file) do |sock, addr|
55
- Thread.new do
56
- loop do
57
- begin
58
- mutex.synchronize {
59
- sock.write "#{ last_stat.to_json }\n"
60
- }
61
- rescue Errno::EPIPE => e
62
- break
63
- rescue => e
64
- Global.logger.error e.desc
65
- break
66
- end
67
- Thread.pass
68
- sleep 0.1
69
- end
70
- end
71
- end
72
- rescue => e
73
- Global.logger.error e.desc
71
+ sleep 1 # wait for UID change before create the socket file
72
+ Socket.unix_server_loop(Global.conf.log_req_socket_file) do |sock, addr|
73
+ Thread.new do
74
+ write_socket sock
74
75
  end
75
76
  end
77
+ rescue => e
78
+ Global.logger.error e.desc
76
79
  end
77
80
 
78
81
  def reset hash
@@ -1,3 +1,3 @@
1
1
  module DnsOne
2
- VERSION = "0.5.11"
2
+ VERSION = "0.5.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lobato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-22 00:00:00.000000000 Z
11
+ date: 2018-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler