litmus_paper 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/litmus_paper/app.rb +19 -0
- data/lib/litmus_paper/metric/big_brother_service.rb +4 -0
- data/lib/litmus_paper/metric/constant_metric.rb +4 -0
- data/lib/litmus_paper/metric/cpu_load.rb +6 -0
- data/lib/litmus_paper/metric/haproxy_backends_health.rb +4 -0
- data/lib/litmus_paper/metric/internet_health.rb +4 -0
- data/lib/litmus_paper/metric/script.rb +4 -0
- data/lib/litmus_paper/metric/unix_socket_utilization.rb +20 -12
- data/lib/litmus_paper/service.rb +2 -0
- data/lib/litmus_paper/version.rb +1 -1
- data/spec/litmus_paper/app_spec.rb +30 -0
- data/spec/litmus_paper/metric/cpu_load_spec.rb +10 -0
- data/spec/litmus_paper/metric/unix_socket_utilization_spec.rb +18 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9167b4c597e469bded0f8b14fad5fc3d1e13f1b75dc34026f2e864c6dc9d51f5
|
4
|
+
data.tar.gz: 577ae4f3475c9674549c8b4fa9c7a46566302e841b0596a331cd4990d25c13cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e24c3869e8c0b64809cd05f21f3039cc7427201dea6d5f8e9273b35aa9a3c2c9e75769ea2b91b6a178649fcf0fb17e29fd520f236aa314cf6e959e44f490d35e
|
7
|
+
data.tar.gz: abe0f3b37f24f939bdffe680515b69e870fe51f4fdadd17d3fc908b07260b302264a5c687551b626abdadff5dd1247605a94bcef7eb0a8993e23850fec589b52
|
data/lib/litmus_paper/app.rb
CHANGED
@@ -97,6 +97,25 @@ module LitmusPaper
|
|
97
97
|
_create_status_file(StatusFile.service_up_file(params[:service]))
|
98
98
|
end
|
99
99
|
|
100
|
+
get "/:service/metrics" do
|
101
|
+
cache_key = "#{params[:service]}_metrics"
|
102
|
+
metrics = _cache.get(cache_key)
|
103
|
+
|
104
|
+
if metrics != nil
|
105
|
+
return _text(200, metrics)
|
106
|
+
end
|
107
|
+
|
108
|
+
metrics = LitmusPaper.services[params[:service]].checks.map do |check|
|
109
|
+
check.stats.map do |key, value|
|
110
|
+
%(#{key}{service="#{params[:service]}"} #{value} #{(Time.now.utc.to_f * 1000).to_i})
|
111
|
+
end.join("\n")
|
112
|
+
end.join("\n") + "\n"
|
113
|
+
|
114
|
+
_cache.set(cache_key, metrics)
|
115
|
+
|
116
|
+
_text(200, metrics)
|
117
|
+
end
|
118
|
+
|
100
119
|
get "/test/error" do
|
101
120
|
raise "an error"
|
102
121
|
end
|
@@ -7,24 +7,32 @@ module LitmusPaper
|
|
7
7
|
@weight = weight
|
8
8
|
@socket_path = socket_path
|
9
9
|
@maxconn = maxconn
|
10
|
-
@active = 0
|
11
|
-
@queued = 0
|
12
10
|
end
|
13
11
|
|
14
12
|
def current_health
|
15
13
|
stats = _stats
|
16
|
-
|
17
|
-
|
18
|
-
if @queued == 0
|
14
|
+
|
15
|
+
if stats.queued == 0
|
19
16
|
return @weight
|
20
|
-
else
|
21
|
-
return [
|
22
|
-
@weight - (
|
23
|
-
(@weight * @active.to_f) / (3 * @maxconn.to_f) +
|
24
|
-
(2 * @weight * @queued.to_f) / (3 * @maxconn.to_f)
|
25
|
-
), 1
|
26
|
-
].max
|
27
17
|
end
|
18
|
+
|
19
|
+
[
|
20
|
+
@weight - (
|
21
|
+
(@weight * stats.active.to_f) / (3 * @maxconn.to_f) +
|
22
|
+
(2 * @weight * stats.queued.to_f) / (3 * @maxconn.to_f)
|
23
|
+
),
|
24
|
+
1
|
25
|
+
].max
|
26
|
+
end
|
27
|
+
|
28
|
+
def stats
|
29
|
+
stats = _stats
|
30
|
+
|
31
|
+
{
|
32
|
+
:socket_active => stats.active,
|
33
|
+
:socket_queued => stats.queued,
|
34
|
+
:socket_utilization => ((stats.queued / @maxconn.to_f) * 100).round,
|
35
|
+
}
|
28
36
|
end
|
29
37
|
|
30
38
|
def _stats
|
data/lib/litmus_paper/service.rb
CHANGED
data/lib/litmus_paper/version.rb
CHANGED
@@ -459,6 +459,36 @@ describe LitmusPaper::App do
|
|
459
459
|
end
|
460
460
|
end
|
461
461
|
|
462
|
+
describe "GET /:service/metrics" do
|
463
|
+
it "returns the forced health value for a healthy service" do
|
464
|
+
LitmusPaper::Metric::UnixSocketUtilitization.any_instance.stub(
|
465
|
+
:_stats => OpenStruct.new({:queued => 7, :active => 10}),
|
466
|
+
)
|
467
|
+
LitmusPaper::Metric::CPULoad.any_instance.stub(
|
468
|
+
:load_average => 0.1
|
469
|
+
)
|
470
|
+
cpu_load = LitmusPaper::Metric::CPULoad.new(50)
|
471
|
+
socket_utilization = LitmusPaper::Metric::UnixSocketUtilitization.new(100, '/var/run/foo.sock', 10)
|
472
|
+
internet_health = LitmusPaper::Metric::InternetHealth.new(100, [
|
473
|
+
"127.0.0.1:3000",
|
474
|
+
"127.0.0.1:3001",
|
475
|
+
])
|
476
|
+
test_service = LitmusPaper::Service.new('test', [AlwaysAvailableDependency.new], [
|
477
|
+
cpu_load,
|
478
|
+
socket_utilization,
|
479
|
+
internet_health,
|
480
|
+
])
|
481
|
+
LitmusPaper.services['test'] = test_service
|
482
|
+
|
483
|
+
get "/test/metrics"
|
484
|
+
last_response.should be_ok
|
485
|
+
last_response.body.should match %r(cpu_load_average{service="test"} 0.1)
|
486
|
+
last_response.body.should match %r(active{service="test"} 10)
|
487
|
+
last_response.body.should match %r(queued{service="test"} 7)
|
488
|
+
last_response.body.should match %r(utilization{service="test"} 70)
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
462
492
|
describe "server errors" do
|
463
493
|
it "responds with a text/plain 500 response" do
|
464
494
|
old_environment = :test
|
@@ -50,6 +50,16 @@ describe LitmusPaper::Metric::CPULoad do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
describe "#stats" do
|
54
|
+
it "reports metrics" do
|
55
|
+
File.should_receive(:read).with('/proc/loadavg').and_return("0.08 0.12 0.15 2/1190 9152\n")
|
56
|
+
cpu_load = LitmusPaper::Metric::CPULoad.new(50)
|
57
|
+
cpu_load.stats.should == {
|
58
|
+
:cpu_load_average => 0.08
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
describe "#to_s" do
|
54
64
|
it "is the check name and the maximum weight" do
|
55
65
|
cpu_load = LitmusPaper::Metric::CPULoad.new(50)
|
@@ -38,4 +38,22 @@ describe LitmusPaper::Metric::UnixSocketUtilitization do
|
|
38
38
|
health.should == 1
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe "#stats" do
|
43
|
+
it "reports metrics" do
|
44
|
+
LitmusPaper::Metric::UnixSocketUtilitization.any_instance.stub(
|
45
|
+
:_stats => OpenStruct.new({:queued => 7, :active => 10}),
|
46
|
+
)
|
47
|
+
metric = LitmusPaper::Metric::UnixSocketUtilitization.new(
|
48
|
+
100,
|
49
|
+
'/var/run/foo.sock',
|
50
|
+
10
|
51
|
+
)
|
52
|
+
metric.stats.should == {
|
53
|
+
:socket_active => 10,
|
54
|
+
:socket_queued => 7,
|
55
|
+
:socket_utilization => 70,
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
41
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litmus_paper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braintreeps
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -262,8 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
262
|
- !ruby/object:Gem::Version
|
263
263
|
version: '0'
|
264
264
|
requirements: []
|
265
|
-
|
266
|
-
rubygems_version: 2.5.2.1
|
265
|
+
rubygems_version: 3.0.3
|
267
266
|
signing_key:
|
268
267
|
specification_version: 4
|
269
268
|
summary: Backend health tester for HA Services, partner project of big_brother
|