vitals 0.7.0 → 0.8.0

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: 3812a6ac57aece8615d8ed54806b2db5c587d2fe
4
- data.tar.gz: d1792d8265dc2b13d5b4f3bd4a228912e789907f
3
+ metadata.gz: 22251cae8ed5dfe457f58b95ab4ff44342551cb8
4
+ data.tar.gz: 81ba009c776476e8a2e92261e7d51b49a9ad6b27
5
5
  SHA512:
6
- metadata.gz: 2d699b17fe6da7822629646bbcbe1afd34d95d32244fe5d61fbff09ac9e6ed0976308583b6cd8d9824cd108c20246e36d3e412d8f266079e9c551aa626e06267
7
- data.tar.gz: ae6cef4f146d70e8bfcb636482d63762e19b09d61241cbea4d13ddad08f323d81f0cec6974db262890ba698ed470da050a794816ee1634fea31ffc71e10622b2
6
+ metadata.gz: a6833d733be34fa74b38faa5b7eee2d49af619e1b41bd2119a4de160d5cf0f974f4144ff84298d8627fdece985f6e5400449da3043d64eb60610767a414be177
7
+ data.tar.gz: ecdabc5249ec20afef0bc8507f734cf255060a2dd21bc79e3922e7e5f86722ae2a3661074cb75f65332ff568a285daf72b4c3b8a1d565e46c19bf7dfc1957041
@@ -0,0 +1,39 @@
1
+ require 'statsd-ruby'
2
+ require 'resolv'
3
+
4
+ module Vitals::Reporters
5
+ class DnsResolvingStatsdReporter < StatsdReporter
6
+ def initialize(host: 'localhost', port: 8125, format: nil)
7
+ @host = host
8
+ @port = port
9
+ @format = format
10
+ setup_statsd
11
+ end
12
+
13
+ private
14
+ def setup_statsd
15
+ ip = @host
16
+ unless (@host =~ Resolv::AddressRegex || @host == 'localhost'.freeze)
17
+ ip, ttl = query_dns
18
+ Thread.new do
19
+ while true do
20
+ sleep ttl
21
+ previous_ip = ip
22
+ ip, ttl = query_dns
23
+ if ip != previous_ip
24
+ @statsd = Statsd.new(ip, @port)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ @statsd = Statsd.new(ip, @port)
30
+ end
31
+
32
+ def query_dns
33
+ ress = Resolv::DNS.open { |dns| dns.getresource(@host, Resolv::DNS::Resource::IN::A) }
34
+ [ress.address.to_s, ress.ttl]
35
+ end
36
+ end
37
+ end
38
+
39
+
@@ -3,7 +3,7 @@ require 'statsd-ruby'
3
3
  module Vitals::Reporters
4
4
  class StatsdReporter < BaseReporter
5
5
  attr_accessor :format
6
- attr_accessor :statsd
6
+ attr_reader :statsd
7
7
 
8
8
  def initialize(host:'localhost', port:8125, format:nil)
9
9
  @statsd = Statsd.new(host, port)
@@ -1,3 +1,3 @@
1
1
  module Vitals
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/vitals.rb CHANGED
@@ -15,6 +15,7 @@ require 'vitals/reporters/inmem_reporter'
15
15
  require 'vitals/reporters/console_reporter'
16
16
  require 'vitals/reporters/multi_reporter'
17
17
  require 'vitals/reporters/statsd_reporter'
18
+ require 'vitals/reporters/dns_resolving_statsd_reporter'
18
19
 
19
20
  require 'vitals/formats/production_format'
20
21
  require 'vitals/formats/host_last_format'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dotan Nahum
@@ -234,6 +234,7 @@ files:
234
234
  - lib/vitals/integrations/rack/requests.rb
235
235
  - lib/vitals/reporters/base_reporter.rb
236
236
  - lib/vitals/reporters/console_reporter.rb
237
+ - lib/vitals/reporters/dns_resolving_statsd_reporter.rb
237
238
  - lib/vitals/reporters/inmem_reporter.rb
238
239
  - lib/vitals/reporters/multi_reporter.rb
239
240
  - lib/vitals/reporters/statsd_reporter.rb