barnes 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/barnes/periodic.rb +21 -18
- data/lib/barnes/version.rb +1 -1
- data/lib/barnes.rb +28 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d9d005157afd63f9b202ee0db19fd7ab296f5bf514cf63af3177baadc9d4cca5
|
|
4
|
+
data.tar.gz: 8c7a6e7d399eb0cbb5c58fdbc7fed8a8c8af3a11858123a8c70c94e83b3435e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0fdc30f4f1a66582e0a9e13633973a2e14bd20debccd4820efb3608a26a3f3a8eeccc7d0277c361ad7f5da24642cc16c1a291c5b08a35a132f9241fd947d065f
|
|
7
|
+
data.tar.gz: 407602084efa4533005a61041648c6d4148e5bbc9014b601e5e128c088fff9ed6630c87495811e40e422d4ffd20c3c4283a703020d4fa848f1dac92e1fed2db9
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
## HEAD (unreleased)
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
- Fix: Previously calling `Barnes.start` would result in duplicate reporting threads. Now when this method is called, old threads are stopped before a new thread is started.
|
|
6
|
+
|
|
3
7
|
## 1.0.0
|
|
4
8
|
|
|
5
9
|
- **Breaking**: Replace StatsD with direct HTTP reporting to HEROKU_METRICS_URL
|
data/lib/barnes/periodic.rb
CHANGED
|
@@ -26,11 +26,14 @@ require 'json'
|
|
|
26
26
|
|
|
27
27
|
module Barnes
|
|
28
28
|
class Periodic
|
|
29
|
+
attr_reader :thread
|
|
30
|
+
|
|
29
31
|
def initialize(reporter:, interval: 10, debug: false, panels: [])
|
|
30
32
|
@reporter = reporter
|
|
31
33
|
@debug = debug
|
|
32
34
|
@interval = interval
|
|
33
35
|
@panels = panels
|
|
36
|
+
@stopping = false
|
|
34
37
|
|
|
35
38
|
@thread = Thread.new {
|
|
36
39
|
Thread.current[:barnes_state] = {}
|
|
@@ -40,31 +43,31 @@ module Barnes
|
|
|
40
43
|
end
|
|
41
44
|
|
|
42
45
|
loop do
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
env = {
|
|
47
|
-
STATE => Thread.current[:barnes_state],
|
|
48
|
-
COUNTERS => {},
|
|
49
|
-
GAUGES => {}
|
|
50
|
-
}
|
|
46
|
+
sleep @interval
|
|
47
|
+
break if @stopping
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
env = {
|
|
50
|
+
STATE => Thread.current[:barnes_state],
|
|
51
|
+
COUNTERS => {},
|
|
52
|
+
GAUGES => {}
|
|
53
|
+
}
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
rescue => e
|
|
59
|
-
$stderr.puts "barnes: error during metrics collection: #{e.class}: #{e.message}"
|
|
55
|
+
@panels.each do |panel|
|
|
56
|
+
panel.instrument! env[STATE], env[COUNTERS], env[GAUGES]
|
|
60
57
|
end
|
|
58
|
+
|
|
59
|
+
puts env.to_json if @debug
|
|
60
|
+
@reporter.report env
|
|
61
|
+
rescue => e
|
|
62
|
+
$stderr.puts "barnes: error during metrics collection: #{e.class}: #{e.message}"
|
|
61
63
|
end
|
|
62
64
|
}
|
|
63
|
-
@thread.abort_on_exception = true
|
|
64
65
|
end
|
|
65
66
|
|
|
66
|
-
def stop
|
|
67
|
-
@
|
|
67
|
+
def stop(wait: )
|
|
68
|
+
@stopping = true
|
|
69
|
+
@thread.wakeup if @thread.alive?
|
|
70
|
+
@thread.join if wait
|
|
68
71
|
end
|
|
69
72
|
end
|
|
70
73
|
end
|
data/lib/barnes/version.rb
CHANGED
data/lib/barnes.rb
CHANGED
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
module Barnes
|
|
25
25
|
DEFAULT_INTERVAL = 10
|
|
26
26
|
DEFAULT_PANELS = [].freeze
|
|
27
|
+
@caller = nil
|
|
28
|
+
@periodic = nil
|
|
29
|
+
@mutex = Mutex.new
|
|
27
30
|
|
|
28
31
|
# Starts the metrics reporting client.
|
|
29
32
|
#
|
|
@@ -41,19 +44,34 @@ module Barnes
|
|
|
41
44
|
url = ENV["HEROKU_METRICS_URL"]
|
|
42
45
|
return unless url
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
@mutex.synchronize do
|
|
48
|
+
reporter = Barnes::Reporter.new(url: url)
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
panels = panels.dup
|
|
51
|
+
if panels.empty?
|
|
52
|
+
panels << Barnes::ResourceUsage.new
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if @periodic
|
|
56
|
+
debug("Restarting Barnes. Previously started by caller:")
|
|
57
|
+
debug(@caller.join("\n"))
|
|
58
|
+
@periodic.stop(wait: false)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
@caller = caller
|
|
62
|
+
@periodic = Periodic.new(
|
|
63
|
+
reporter: reporter,
|
|
64
|
+
interval: interval,
|
|
65
|
+
panels: panels,
|
|
66
|
+
debug: ENV['BARNES_DEBUG']
|
|
67
|
+
)
|
|
49
68
|
end
|
|
69
|
+
end
|
|
50
70
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
debug: ENV['BARNES_DEBUG']
|
|
56
|
-
)
|
|
71
|
+
def self.debug(message)
|
|
72
|
+
if ENV["BARNES_DEBUG"]
|
|
73
|
+
puts "Barnes: #{message}"
|
|
74
|
+
end
|
|
57
75
|
end
|
|
58
76
|
end
|
|
59
77
|
|