rack-monitor-opentsdb 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9afbff4ac650e92c2dbd3f916be7787e88b00f8
4
- data.tar.gz: 7ede01a4ebbf70501ca057ea0243bdb14d910df8
3
+ metadata.gz: e866b16f09cb44bfd2117019f9af9a31bc8aa21c
4
+ data.tar.gz: 635349b6342f3d5e6d11dfe83a284b08a9bde77e
5
5
  SHA512:
6
- metadata.gz: 41ebb0204e780f94c16e45d03d47c7fb6c544f9b04af119df80fd17c0cb21e03e92fd63bea8516063c9cfd98607d02a96694bac84e415a95e0777ae8d6bd7f29
7
- data.tar.gz: 7cc1a7f1246e936cb4f1a503ba38e50447147847e6f237a0ad35a05b5e5d9302bdf7769e50342a56057f7e5edacb17a36b5f4c59f7ba786e472572521df96b2c
6
+ metadata.gz: 36cb668d3feab5db5b8c053d42af4b851b73446f9295be7b8d6ac5f05d52147f6758f5c58cb13f56526126066aab63e5c222be03a9da7dfc2c730f7c8021c601
7
+ data.tar.gz: 68b8be2783eac44545409a392ce47fe602d9b4b142d7182ded6f6b42770c0c3b71418001332a7adf10a6fa1ffcec028b0eaa51be31e4693128be525017f9c14e
data/README.md CHANGED
@@ -13,6 +13,7 @@ Usage:
13
13
  :host => 'opentsdb.example.com',
14
14
  :port => 4242,
15
15
  :report_interval => 60,
16
+ :logger => Logger.new(STDOUT),
16
17
  :tags => {
17
18
  :host => `hostname`.chomp,
18
19
  :env => ENV['RACK_ENV'] || 'development' }
@@ -21,6 +22,10 @@ Usage:
21
22
  'Hello World'
22
23
  end
23
24
 
25
+ If you give a `logger`, some internas are logged to `debug`, `info` and
26
+ `error`. If there's no `logger` given, nothing will be logged and no error
27
+ will occur.
28
+
24
29
  Links:
25
30
  ------
26
31
 
@@ -20,10 +20,11 @@ module Rack
20
20
  :track_regex => /^(\/[^\/]+).*?$/, # Regex to select trackable string
21
21
  :track_replace => '\1', # gsub pattern to select trackable string
22
22
  :report_interval => 60,
23
+ :logger => nil,
23
24
  :tags => {}
24
25
  }.merge(options)
25
26
  @stats = Stats.new
26
- @reporter = Reporter.new(@stats, @options[:host], @options[:port], @options[:key], @options[:report_interval], @options[:tags])
27
+ @reporter = Reporter.new(@stats, @options[:host], @options[:port], @options[:key], @options[:report_interval], @options[:tags], @options[:logger])
27
28
  @reporter.start
28
29
  end
29
30
 
@@ -17,7 +17,7 @@ module Rack
17
17
  #
18
18
  # The stats parameter must be extended with MonitorMixin. Like this it
19
19
  # can be accessed synchronized.
20
- def initialize(stats, host, port, key = 'unconfigured.rack.monitor', interval = 60, tags = {})
20
+ def initialize(stats, host, port, key = 'unconfigured.rack.monitor', interval = 60, tags = {}, logger = nil)
21
21
  raise ArgumentError, "Interval less than zero" if interval < 0
22
22
  raise ArgumentError, 'stats does not support synchronize' unless stats.respond_to? :synchronize
23
23
 
@@ -27,6 +27,7 @@ module Rack
27
27
  @host = host
28
28
  @port = port
29
29
  @key = key
30
+ @logger = logger
30
31
  @tosend = []
31
32
  start
32
33
  end
@@ -34,6 +35,7 @@ module Rack
34
35
  def start
35
36
  return if @run
36
37
  @run = true
38
+ log(:info, 'Starting Reporter-Thread')
37
39
  @th = Thread.new do
38
40
  t = Time.now
39
41
  while run?
@@ -59,6 +61,8 @@ module Rack
59
61
  end
60
62
 
61
63
  def send_report
64
+ log(:debug, "Sending Report#{@tosend.empty? ? '' : " (#{@tosend.length} spooled entries)"}")
65
+
62
66
  timestamp = Time.now.to_i
63
67
  data = copy_and_clear_stats
64
68
  data.each do |url, url_stats|
@@ -89,13 +93,17 @@ module Rack
89
93
  true
90
94
  end
91
95
  rescue IOError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EPIPE
96
+ log(:error, "Connection problem: #{$!.message}")
97
+
92
98
  # Don't retry immediately (preventing loops), next run will retry
93
99
  @socket = nil
94
100
  rescue
95
101
  begin
102
+ log(:info, "Connecting to #{host}:#{port}")
96
103
  @socket = TCPSocket.new(@host, @port)
97
104
  retry
98
105
  rescue
106
+ log(:error, "Connection problem:#{$!.message}")
99
107
  # will do no retry in this case
100
108
  end
101
109
  end
@@ -112,6 +120,12 @@ module Rack
112
120
  copy
113
121
  end
114
122
 
123
+ def log(level, message)
124
+ if(@logger.respond_to? level)
125
+ @logger.send level, "Rack::Monitor::OpenTSDB::Reporter - #{message}"
126
+ end
127
+ end
128
+
115
129
  end
116
130
  end
117
131
  end
@@ -4,7 +4,7 @@ module Rack
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- NANO = 1
7
+ NANO = 2
8
8
 
9
9
  VERSION = "#{MAJOR}.#{MINOR}.#{NANO}"
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-monitor-opentsdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rainer Jung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake