tpt-rails 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f34cc827a621a48f4a71602ddf6de4c8da4738a1644708136cb5d0e716795be
|
4
|
+
data.tar.gz: 165dbfd4ffc8e3a149ae0c4a88600ee39319b21ba99882846902ec7d1511fd74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9a6507480b7e46bee217c524c243b89c7994135cd06c1353e30b97fa4b57088cf6dcfac699f1bd10407da15fd0d1c872922bf9ad6d52d4d8a1b8680926da1fc
|
7
|
+
data.tar.gz: bcf18231087259a786e1254c3d81520f383163928043cf42415a0ab4e0af199e28b8aea695ebfa9c2d660c9e5a1e847ddfcb0d0b99a6effd00ebfc3da11d3934
|
data/README.md
CHANGED
@@ -100,6 +100,18 @@ Tpt::Rails provides the following endpoint:
|
|
100
100
|
|
101
101
|
This endpoint reports an error via `Tpt::Rails.report` and emits a metric to Datadog.
|
102
102
|
|
103
|
+
### Puma instrumentation
|
104
|
+
|
105
|
+
Add the following to `config/puma.rb` to have Puma metrics sent to Datadog:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
before_fork do
|
109
|
+
Tpt::Rails::PumaStatsCollector.run(metrics_client: Tpt::Rails.statsd)
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
Note: this currently only collects metrics when running Puma in _clustered_ mode (i.e. w/ more than one worker)
|
114
|
+
|
103
115
|
## Developing this Gem
|
104
116
|
|
105
117
|
### Running tests
|
@@ -70,13 +70,14 @@ service:
|
|
70
70
|
resources:
|
71
71
|
# requests is guaranteed. kubernetes will only put your pod on a node where it can guarantee these
|
72
72
|
# amounts.
|
73
|
-
requests:
|
74
|
-
memory: 256Mi
|
75
|
-
cpu: 200m
|
76
|
-
# limits is when your pod gets killed for using too many resources
|
77
|
-
limits:
|
73
|
+
requests: &requests
|
78
74
|
memory: 512Mi
|
79
|
-
cpu:
|
75
|
+
cpu: 500m
|
76
|
+
# limits is when your pod gets killed for using too many resources. normally these should be set
|
77
|
+
# the same as the "requests" limit, but if you have a unique workload that requires burstable
|
78
|
+
# limits then consult with CloudOps
|
79
|
+
limits:
|
80
|
+
*requests
|
80
81
|
|
81
82
|
app:
|
82
83
|
# this configures your service to be available at <%= Tpt::Rails.app_name %>.<ingress_dns_name>
|
data/lib/tpt/rails.rb
CHANGED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Tpt::Rails::PumaStatsCollector # :nodoc:
|
2
|
+
class PumaStats
|
3
|
+
def initialize(stats)
|
4
|
+
@stats = JSON.parse(stats, symbolize_names: true)
|
5
|
+
end
|
6
|
+
|
7
|
+
def clustered?
|
8
|
+
@stats.has_key?(:workers)
|
9
|
+
end
|
10
|
+
|
11
|
+
def workers
|
12
|
+
@stats.fetch(:workers, 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted_workers
|
16
|
+
@stats.fetch(:booted_workers, 1)
|
17
|
+
end
|
18
|
+
|
19
|
+
def running
|
20
|
+
get_stat(:running)
|
21
|
+
end
|
22
|
+
|
23
|
+
def backlog
|
24
|
+
get_stat(:backlog)
|
25
|
+
end
|
26
|
+
|
27
|
+
def pool_capacity
|
28
|
+
get_stat(:pool_capacity)
|
29
|
+
end
|
30
|
+
|
31
|
+
def max_threads
|
32
|
+
get_stat(:max_threads)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
{
|
37
|
+
workers: workers,
|
38
|
+
booted_workers: booted_workers,
|
39
|
+
running: running,
|
40
|
+
backlog: backlog,
|
41
|
+
pool_capacity: pool_capacity,
|
42
|
+
max_threads: max_threads
|
43
|
+
}.to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def get_stat(name)
|
48
|
+
if clustered?
|
49
|
+
@stats[:worker_status].map { |s| s[:last_status].fetch(name, 0) }.sum
|
50
|
+
else
|
51
|
+
@stats.fetch(name, 0)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class << self
|
57
|
+
def run(metrics_client:, start_delay: 10, collect_interval: 30)
|
58
|
+
Thread.new do
|
59
|
+
# Give Puma time to start
|
60
|
+
sleep start_delay
|
61
|
+
|
62
|
+
# Get pod name if set
|
63
|
+
pod_name = ENV["KUBE_POD"]
|
64
|
+
|
65
|
+
loop do
|
66
|
+
begin
|
67
|
+
stats = PumaStats.new(Puma.stats)
|
68
|
+
|
69
|
+
tags = []
|
70
|
+
# Add pod_name tag if set
|
71
|
+
tags << "pod_name:#{pod_name}" if pod_name
|
72
|
+
|
73
|
+
metrics_client.gauge("puma.workers", stats.workers, tags: tags)
|
74
|
+
metrics_client.gauge("puma.booted_workers", stats.booted_workers, tags: tags)
|
75
|
+
metrics_client.gauge("puma.running", stats.running, tags: tags)
|
76
|
+
metrics_client.gauge("puma.backlog", stats.backlog, tags: tags)
|
77
|
+
metrics_client.gauge("puma.pool_capacity", stats.pool_capacity, tags: tags)
|
78
|
+
metrics_client.gauge("puma.max_threads", stats.max_threads, tags: tags)
|
79
|
+
end
|
80
|
+
|
81
|
+
sleep collect_interval
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/tpt/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tpt-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TpT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/tpt/rails/internal/datadog.rb
|
127
127
|
- lib/tpt/rails/internal/error_reporter.rb
|
128
128
|
- lib/tpt/rails/internal/health_checks.rb
|
129
|
+
- lib/tpt/rails/puma_stats_collector.rb
|
129
130
|
- lib/tpt/rails/version.rb
|
130
131
|
homepage: https://github.com/TeachersPayTeachers/tpt-rails
|
131
132
|
licenses:
|