prometheus_exporter 0.1.8 → 0.1.9

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: f90837db285b202f06d0f7360fe0260435a51457361cfbe505e473b573367fc6
4
- data.tar.gz: 9ab075f33187b5cc7563e1236572870d8ce98b421fec46d989b7b00d968ef241
3
+ metadata.gz: 86a92ab30771272b941d1d453d9a48ec06b77f614ec966490702c270b90e369b
4
+ data.tar.gz: c606f0aacbcd0d79607ae3ea7f4bbe63b2632c4c431a8f9d19a86d8b072a8543
5
5
  SHA512:
6
- metadata.gz: 3b34b7b622d684ea9b25f4e8b223cd69b11df7686834a72b0e7f899a1b90bc691194a6bf7695ac0778dd88dba860245981977c67f10b214a9b5f9dcfbf0f31c7
7
- data.tar.gz: 2ecc3d186fa4de3bce308b87f5cab0b1c95f336efc72819e08e6cd1258f2b5ef5b381d8347d686e85eb1a18ac8890d4230479e3f9234889d0631ec4034beab2a
6
+ metadata.gz: 58ec62718537d203ebb9cfa2b2f52ce02ffd878c15845d4fba8a5f0e9c505719b5567af123d075f8e88ff6afed7efdff282178a67a552a335255376cf5799ecd
7
+ data.tar.gz: 2058b506f5485c86033a9534642a8740852dd351dc43a04cb5eb10fb78921bb7dc85a74505d0830b0c4d7b1abcc722ababcc0d3a2c20f6307ed608af9a38f706
data/README.md CHANGED
@@ -113,8 +113,8 @@ gem 'prometheus_exporter'
113
113
 
114
114
  unless Rails.env == "test"
115
115
  require 'prometheus_exporter/middleware'
116
- # insert in position 1
117
- # instrument means method profiler will be injected in Redis and PG
116
+
117
+ # This reports stats per request like HTTP status and timings
118
118
  Rails.application.middleware.unshift PrometheusExporter::Middleware
119
119
  end
120
120
  ```
@@ -125,9 +125,12 @@ You may also be interested in per-process stats, this collects memory and GC sta
125
125
  # in an initializer
126
126
  unless Rails.env == "test"
127
127
  require 'prometheus_exporter/instrumentation'
128
+
129
+ # this reports basic process stats like RSS and GC info
128
130
  PrometheusExporter::Instrumentation::Process.start(type: "master")
129
131
  end
130
132
 
133
+ # in unicorn/puma/passenger be sure to run a new process instrumenter after fork
131
134
  after_fork do
132
135
  require 'prometheus_exporter/instrumentation'
133
136
  PrometheusExporter::Instrumentation::Process.start(type:"web")
@@ -135,7 +138,18 @@ end
135
138
 
136
139
  ```
137
140
 
138
- Ensure you run the exporter via
141
+ Including Sidekiq metrics (how many jobs ran? how many failed? how long did they take?)
142
+
143
+ ```
144
+ Sidekiq.configure_server do |config|
145
+ config.server_middleware do |chain|
146
+ require 'prometheus_exporter/instrumentation'
147
+ chain.add PrometheusExporter::Instrumentation::Sidekiq
148
+ end
149
+ end
150
+ ```
151
+
152
+ Ensure you run the exporter in a monitored background process via
139
153
 
140
154
  ```
141
155
  % bundle exec prometheus_exporter
File without changes
@@ -0,0 +1,25 @@
1
+ module PrometheusExporter::Instrumentation
2
+ class Sidekiq
3
+
4
+ def initialize(client: nil)
5
+ @client = client || PrometheusExporter::Client.default
6
+ end
7
+
8
+ def call(worker, msg, queue)
9
+ success = false
10
+ start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
11
+ result = yield
12
+ success = true
13
+ result
14
+ ensure
15
+ duration = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start
16
+
17
+ @client.send_json(
18
+ type: "sidekiq",
19
+ name: worker.class.to_s,
20
+ success: success,
21
+ duration: duration
22
+ )
23
+ end
24
+ end
25
+ end
@@ -1,2 +1,4 @@
1
1
  require_relative "instrumentation/process"
2
2
  require_relative "instrumentation/method_profiler"
3
+ require_relative "instrumentation/sidekiq"
4
+ require_relative "instrumentation/global"
@@ -34,6 +34,8 @@ module PrometheusExporter::Server
34
34
  observe_web(obj)
35
35
  elsif obj["type"] == "process"
36
36
  observe_process(obj)
37
+ elsif obj["type"] == "sidekiq"
38
+ observe_sidekiq(obj)
37
39
  else
38
40
  metric = @metrics[obj["name"]]
39
41
  if !metric
@@ -145,6 +147,33 @@ module PrometheusExporter::Server
145
147
  @process_metrics << obj
146
148
  end
147
149
 
150
+ def observe_sidekiq(obj)
151
+ ensure_sidekiq_metrics
152
+ @sidekiq_job_duration_seconds.observe(obj["duration"], job_name: obj["name"])
153
+ @sidekiq_job_count.observe(1, job_name: obj["name"])
154
+ @sidekiq_failed_job_count.observe(1, job_name: obj["name"]) if !obj["success"]
155
+ end
156
+
157
+ def ensure_sidekiq_metrics
158
+ if !@sidekiq_job_count
159
+
160
+ @metrics["sidekiq_job_duration_seconds"] =
161
+ @sidekiq_job_duration_seconds =
162
+ PrometheusExporter::Metric::Counter.new(
163
+ "sidekiq_job_duration_seconds", "Total time spent in sidekiq jobs")
164
+
165
+ @metrics["sidekiq_job_count"] =
166
+ @sidekiq_job_count =
167
+ PrometheusExporter::Metric::Counter.new(
168
+ "sidekiq_job_count", "Total number of sidekiq jobs executed")
169
+
170
+ @metrics["sidekiq_failed_job_count"] =
171
+ @sidekiq_failed_job_count =
172
+ PrometheusExporter::Metric::Counter.new(
173
+ "sidekiq_failed_job_count", "Total number failed sidekiq jobs executed")
174
+ end
175
+ end
176
+
148
177
  def register_metric_unsafe(obj)
149
178
  name = obj["name"]
150
179
  help = obj["help"]
@@ -1,3 +1,3 @@
1
1
  module PrometheusExporter
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-30 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,8 +117,10 @@ files:
117
117
  - lib/prometheus_exporter.rb
118
118
  - lib/prometheus_exporter/client.rb
119
119
  - lib/prometheus_exporter/instrumentation.rb
120
+ - lib/prometheus_exporter/instrumentation/global.rb
120
121
  - lib/prometheus_exporter/instrumentation/method_profiler.rb
121
122
  - lib/prometheus_exporter/instrumentation/process.rb
123
+ - lib/prometheus_exporter/instrumentation/sidekiq.rb
122
124
  - lib/prometheus_exporter/metric.rb
123
125
  - lib/prometheus_exporter/metric/base.rb
124
126
  - lib/prometheus_exporter/metric/counter.rb