emrb 0.1.2 → 0.1.4
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/instruments/instruments.rb +13 -0
- 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: 28e29346fc4f54537087ca4b1ca4b179bc33f70266d4dc78de4cbdf5065dcd5a
|
4
|
+
data.tar.gz: eb0ef1dfb40da2d96604380880646b793837d8e5f1a8bd62146ff5ee1f24a3cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 225ca18957ba3fc5cc5b26236a7fd0a38311a01bccae67ab3730ce053e8ef74e5fe7be1f589db9df1cc61833a051b5afdf6c179fab00872cdd88b3f51035cfa8
|
7
|
+
data.tar.gz: d999b2801431ba962d6ae0177f1d976b0568ce2c847248e2091f74c241f3645ff2c5fdfd68d7e3d4f7104e836bea988e6dc8d6aa6db197449449e8dcd1663e06
|
data/.editorconfig
ADDED
data/.rubocop.yml
CHANGED
data/compose.yaml
ADDED
data/example/http/Gemfile.lock
CHANGED
data/example/push/Gemfile.lock
CHANGED
@@ -176,6 +176,19 @@ module Emrb
|
|
176
176
|
# end
|
177
177
|
def push(job, **) = State.push(job, **)
|
178
178
|
|
179
|
+
# Periodically invokes #push in a given frequency.
|
180
|
+
#
|
181
|
+
# job - Job identifier
|
182
|
+
# frequency - Frequency, in seconds, in which #push will be called.
|
183
|
+
#
|
184
|
+
# Returns nothing.
|
185
|
+
def push_periodically(job, frequency = 10)
|
186
|
+
Thread.new do
|
187
|
+
sleep(frequency)
|
188
|
+
push(job)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
179
192
|
# Allows instruments to be declared with preset labels.
|
180
193
|
#
|
181
194
|
# labels - A hash containing the preset labels and values
|
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.4
|
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:
|