emrb 0.1.2 → 0.1.3
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/.editorconfig +10 -0
- data/.rubocop.yml +9 -0
- data/compose.yaml +10 -0
- data/example/http/Gemfile.lock +1 -1
- data/example/push/Gemfile.lock +1 -1
- data/lib/emrb/server.rb +60 -0
- data/lib/emrb/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfc0b3aabe0d926c2a7c7ef914fbbf2c064bf3db8a27aefa68f4bd348d6d3d43
|
4
|
+
data.tar.gz: 9d689ec83548b4ed363f5872779b50069e42d70e3f34028074b5eaaab1d27de0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b25cede10a5a9baec6060076ccbd0d7b7b7ef3839d2ba6b0f8a97c1f1b5b915b2516b61bd3a45257f692ea3a8e4406e8438e993d7ab48aeb165f14130213bd9
|
7
|
+
data.tar.gz: 24baf13019ce92585d581578404c532a4e44b2d89471339e5bdd51e2fdc90af70076aedf697ba59377f6c8094c159611061e4f58965f1ee7924a65b7ed672d3d
|
data/.editorconfig
ADDED
data/.rubocop.yml
CHANGED
data/compose.yaml
ADDED
data/example/http/Gemfile.lock
CHANGED
data/example/push/Gemfile.lock
CHANGED
data/lib/emrb/server.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "sinatra/base"
|
5
|
+
rescue LoadError
|
6
|
+
raise(<<~MESSAGE)
|
7
|
+
ERROR: You attempted to use emrb/server, but sinatra is not available.
|
8
|
+
Add sinatra to your application's dependencies before using this feature.
|
9
|
+
MESSAGE
|
10
|
+
end
|
11
|
+
|
12
|
+
begin
|
13
|
+
require "puma"
|
14
|
+
rescue LoadError
|
15
|
+
raise(<<~MESSAGE)
|
16
|
+
ERROR: You attempted to use emrb/server, but puma is not available.
|
17
|
+
Add puma to your application's dependencies before using this feature.
|
18
|
+
MESSAGE
|
19
|
+
end
|
20
|
+
|
21
|
+
module Emrb
|
22
|
+
# expose_metrics starts a simple sinatra server on a given port and
|
23
|
+
# address that exposes a single /metrics endpoint for scrapers to access.
|
24
|
+
# It is a courtesy utility for applications not exposing an HTTP server
|
25
|
+
# by default.
|
26
|
+
#
|
27
|
+
# To use this method, the application calling it must bundle both sinatra
|
28
|
+
# and puma gems.
|
29
|
+
#
|
30
|
+
# port - Port to expose the server
|
31
|
+
# address - Address to expose the server. Defaults to `0.0.0.0`.
|
32
|
+
#
|
33
|
+
# Returns nothing.
|
34
|
+
def self.expose_metrics(port, address = "0.0.0.0")
|
35
|
+
return if @metrics_app
|
36
|
+
|
37
|
+
metrics_app = Class.new(Sinatra::Base) do
|
38
|
+
set :bind, address
|
39
|
+
set :port, port
|
40
|
+
use Emrb::Exporter
|
41
|
+
use Rack::Deflater
|
42
|
+
end
|
43
|
+
|
44
|
+
@metrics_app = metrics_app.new
|
45
|
+
puma_server = Puma::Server.new(metrics_app)
|
46
|
+
puma_server.add_tcp_listener(address, port)
|
47
|
+
@puma_server = puma_server
|
48
|
+
@metrics_thr = Thread.new { puma_server.run }
|
49
|
+
end
|
50
|
+
|
51
|
+
# Stops the metrics server previously started by #expose_metrics.
|
52
|
+
#
|
53
|
+
# Returns nothing.
|
54
|
+
def self.stop_exposing_metrics
|
55
|
+
return unless @metrics_app
|
56
|
+
|
57
|
+
@puma_server.stop(true)
|
58
|
+
@metrics_thr.join
|
59
|
+
end
|
60
|
+
end
|
data/lib/emrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Mariotti
|
@@ -33,11 +33,13 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
+
- ".editorconfig"
|
36
37
|
- ".rspec"
|
37
38
|
- ".rubocop.yml"
|
38
39
|
- CODE_OF_CONDUCT.md
|
39
40
|
- README.md
|
40
41
|
- Rakefile
|
42
|
+
- compose.yaml
|
41
43
|
- example/http/Gemfile
|
42
44
|
- example/http/Gemfile.lock
|
43
45
|
- example/http/main.rb
|
@@ -52,6 +54,7 @@ files:
|
|
52
54
|
- lib/emrb/instruments/exporters.rb
|
53
55
|
- lib/emrb/instruments/instruments.rb
|
54
56
|
- lib/emrb/instruments/state.rb
|
57
|
+
- lib/emrb/server.rb
|
55
58
|
- lib/emrb/version.rb
|
56
59
|
homepage: https://github.com/ofeefo/emrb
|
57
60
|
licenses:
|