yabeda-puma-plugin 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -0
- data/lib/puma/plugin/yabeda_prometheus.rb +47 -0
- data/lib/yabeda/puma/plugin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ec5a12b14554eb6e0a7b62d76ab1360501f600348c71e779005a4bca8624a3d
|
4
|
+
data.tar.gz: 9be1f9b5b0f6d7516848673d7a2e49e1ab18282d1c7ae1c1dbd79612d0befa5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 250d92d5d1fb71f8a9b5d04d07e2ce33e5cad0cb61428c2f728b22df567d13c87959e4e0f3add1aefd1bf29112d2e2686edb4a0cae2f857e988b716a48579060
|
7
|
+
data.tar.gz: 5b637cd1c1c3cc0ae935beaf9c0bc05a65053bc3aec696f09e2b3920c0164cdaac3692a100a8c4a8d944399174317576feabddfde2179446ab7db3b25d32b4b2
|
data/README.md
CHANGED
@@ -34,6 +34,8 @@ And then execute:
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
+
### Collecting metrics
|
38
|
+
|
37
39
|
Add those 2 lines of code to your `config/puma.rb` file:
|
38
40
|
```ruby
|
39
41
|
activate_control_app
|
@@ -41,6 +43,52 @@ plugin :yabeda
|
|
41
43
|
```
|
42
44
|
It will activate default puma control application working over the unix socket, and runs the `yabeda` puma plugin, for registering and collecting the metrics.
|
43
45
|
|
46
|
+
### Exposing metrics
|
47
|
+
|
48
|
+
Some monitoring system agents (like NewRelic or DataDog) will send metrics automatically in the background. But for some of monitoring systems (like Prometheus) you have to explicitly set up metrics export.
|
49
|
+
|
50
|
+
#### Prometheus
|
51
|
+
|
52
|
+
##### On the same endpoint with your application
|
53
|
+
|
54
|
+
For non-Rails applications place following line in your `config.ru` _before_ running your application:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
use Yabeda::Prometheus::Exporter, path: "/metrics"
|
58
|
+
```
|
59
|
+
|
60
|
+
In Ruby on Rails applications you can add following line in `config/routes.rb` instead:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
mount Yabeda::Prometheus::Exporter => "/metrics"
|
64
|
+
```
|
65
|
+
|
66
|
+
In both cases your Puma instance metrics (along with your application metrics) will be available at `/metrics` endpoint.
|
67
|
+
|
68
|
+
##### On different port
|
69
|
+
|
70
|
+
Sometimes you don't want to expose metrics publicly for security reasons. For that case prometheus exporter plugin is bundled with this gem.
|
71
|
+
|
72
|
+
Don't forget to add either `yabeda-prometheus` or `yabeda-prometheus-mmap` gem into your `Gemfile`!
|
73
|
+
|
74
|
+
Add this plugin into your `config/puma.rb`:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
plugin :yabeda_prometheus
|
78
|
+
```
|
79
|
+
|
80
|
+
By default metrics will be available at `http://0.0.0.0:9394/metrics`.
|
81
|
+
|
82
|
+
Bind host, port, and path can be controlled either by config file option `prometheus_exporter_url`:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
# config/puma.rb
|
86
|
+
prometheus_exporter_url "tcp://127.0.0.1:9395/shmetrics"
|
87
|
+
```
|
88
|
+
|
89
|
+
Or by environment variables `PROMETHEUS_EXPORTER_URL`, `PROMETHEUS_EXPORTER_BIND`, `PROMETHEUS_EXPORTER_PORT`, and `PROMETHEUS_EXPORTER_PATH` (takes precedence over configuration option).
|
90
|
+
|
91
|
+
|
44
92
|
## Details
|
45
93
|
|
46
94
|
In accordance with the [architecture](https://github.com/puma/puma/blob/master/docs/architecture.md) of the puma web server lets look how it works:
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'yabeda/prometheus/exporter'
|
5
|
+
rescue LoadError
|
6
|
+
raise LoadError, 'Please add either yabeda-prometheus or yabeda-prometheus-mmap gem into your Gemfile to use yabeda/prometheus/exporter!'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'uri'
|
10
|
+
require 'rack'
|
11
|
+
|
12
|
+
module Puma
|
13
|
+
class DSL
|
14
|
+
def prometheus_exporter_url(uri)
|
15
|
+
@options[:prometheus_exporter_url] = uri
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Puma::Plugin.create do
|
21
|
+
def start(launcher)
|
22
|
+
events = launcher.events
|
23
|
+
|
24
|
+
uri = launcher.options.fetch(:prometheus_exporter_url, 'tcp://0.0.0.0:9394/metrics')
|
25
|
+
uri = URI.parse(ENV.fetch('PROMETHEUS_EXPORTER_URL', uri))
|
26
|
+
host = ENV.fetch('PROMETHEUS_EXPORTER_BIND', uri.host)
|
27
|
+
port = Integer(ENV.fetch('PROMETHEUS_EXPORTER_PORT', uri.port))
|
28
|
+
path = ENV.fetch('PROMETHEUS_EXPORTER_PATH', uri.path)
|
29
|
+
|
30
|
+
app = Yabeda::Prometheus::Exporter.rack_app(Yabeda::Prometheus::Exporter, path: path)
|
31
|
+
|
32
|
+
metrics = Puma::Server.new app, events
|
33
|
+
metrics.min_threads = 0
|
34
|
+
metrics.max_threads = 1
|
35
|
+
|
36
|
+
events.log "Starting Yabeda Prometheus metrics exporter on http://#{host}:#{port}#{path}"
|
37
|
+
metrics.add_tcp_listener host, port
|
38
|
+
|
39
|
+
events.register(:state) do |state|
|
40
|
+
if %i[halt restart stop].include?(state)
|
41
|
+
metrics.stop(true) unless metrics.shutting_down?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
metrics.run
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yabeda-puma-plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salahutdinov Dmitry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yabeda
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- docs/diagram.png
|
130
130
|
- docs/grafana.png
|
131
131
|
- lib/puma/plugin/yabeda.rb
|
132
|
+
- lib/puma/plugin/yabeda_prometheus.rb
|
132
133
|
- lib/yabeda/puma/plugin.rb
|
133
134
|
- lib/yabeda/puma/plugin/statistics.rb
|
134
135
|
- lib/yabeda/puma/plugin/statistics/fetcher.rb
|