prometheus_exporter 2.0.6 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -1
- data/.github/workflows/docker.yml +47 -0
- data/CHANGELOG +10 -0
- data/Dockerfile +9 -0
- data/README.md +26 -0
- data/lib/prometheus_exporter/server/metrics_container.rb +66 -0
- data/lib/prometheus_exporter/server/puma_collector.rb +4 -10
- data/lib/prometheus_exporter/server/sidekiq_process_collector.rb +4 -7
- data/lib/prometheus_exporter/server/sidekiq_queue_collector.rb +4 -5
- data/lib/prometheus_exporter/server/sidekiq_stats_collector.rb +4 -5
- data/lib/prometheus_exporter/server/type_collector.rb +2 -0
- data/lib/prometheus_exporter/server/web_server.rb +5 -0
- data/lib/prometheus_exporter/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af71a5656b5fe6a90de6fe6ad1b76efa05ccfb67d4fdb3cdcc740f539097546f
|
4
|
+
data.tar.gz: cd6ef704ecdc7110d5f78dd999354e1ea093adcba51f2355a0211e99e0fb3c67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf3c09a5609699bd055094bc509e997e320a72833b7c2beca03186d0c3d3fa0fa65fc005708b7faf496a9bf32c68c489cc7a1985525eed7a35ceb6b2d53a9df
|
7
|
+
data.tar.gz: 3975585eb3842c5cf409793d9257a184e33af062d4dd45e5bf64164bbba88c87d14aaea946bed519f9db1034afb8695fbdeecef337286bcaf00132cd2cd7a5f2
|
data/.github/workflows/ci.yml
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
name: Docker
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- "v*"
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
packages: write
|
11
|
+
|
12
|
+
env:
|
13
|
+
DOCKER_REPO: ghcr.io/discourse/prometheus_exporter
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
build-and-publish:
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
timeout-minutes: 30
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- name: Set vars
|
22
|
+
id: vars
|
23
|
+
run: |
|
24
|
+
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
25
|
+
|
26
|
+
- uses: actions/checkout@v3
|
27
|
+
- uses: docker/setup-qemu-action@v2
|
28
|
+
- uses: docker/setup-buildx-action@v2
|
29
|
+
|
30
|
+
- name: Login to Github Container Registry
|
31
|
+
uses: docker/login-action@v2
|
32
|
+
with:
|
33
|
+
registry: ghcr.io
|
34
|
+
username: ${{ github.actor }}
|
35
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
36
|
+
|
37
|
+
- name: Build and push images
|
38
|
+
uses: docker/build-push-action@v3
|
39
|
+
with:
|
40
|
+
context: .
|
41
|
+
push: true
|
42
|
+
platforms: linux/amd64,linux/arm64
|
43
|
+
build-args: |
|
44
|
+
GEM_VERSION=${{ steps.vars.outputs.version }}
|
45
|
+
tags: |
|
46
|
+
${{ env.DOCKER_REPO }}:${{ steps.vars.outputs.version }}
|
47
|
+
${{ env.DOCKER_REPO }}:latest
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2.0.8 - 2023-01-20
|
2
|
+
|
3
|
+
- FEATURE: attempting to make our first docker release
|
4
|
+
|
5
|
+
2.0.7 - 2023-01-13
|
6
|
+
|
7
|
+
- FEATURE: allow binding server to both ipv4 and v6
|
8
|
+
- FIX: expire stale sidekiq metrics
|
9
|
+
|
10
|
+
|
1
11
|
2.0.6 - 2022-11-22
|
2
12
|
|
3
13
|
- FIX: use user specified labels over default in merge conflict
|
data/Dockerfile
ADDED
data/README.md
CHANGED
@@ -32,6 +32,7 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
|
|
32
32
|
* [Transport concerns](#transport-concerns)
|
33
33
|
* [JSON generation and parsing](#json-generation-and-parsing)
|
34
34
|
* [Logging](#logging)
|
35
|
+
* [Docker Usage](#docker-usage)
|
35
36
|
* [Contributing](#contributing)
|
36
37
|
* [License](#license)
|
37
38
|
* [Code of Conduct](#code-of-conduct)
|
@@ -857,6 +858,9 @@ prometheus_exporter -p 8080 \
|
|
857
858
|
--prefix 'foo_'
|
858
859
|
```
|
859
860
|
|
861
|
+
You can use `-b` option to bind the `prometheus_exporter` web server to any IPv4 interface with `-b 0.0.0.0`,
|
862
|
+
any IPv6 interface with `-b ::`, or `-b ANY` to any IPv4/IPv6 interfaces available on your host system.
|
863
|
+
|
860
864
|
#### Enabling Basic Authentication
|
861
865
|
|
862
866
|
If you desire authentication on your `/metrics` route, you can enable basic authentication with the `--auth` option.
|
@@ -960,6 +964,28 @@ You can also pass a log level (default is [`Logger::WARN`](https://ruby-doc.org/
|
|
960
964
|
PrometheusExporter::Client.new(log_level: Logger::DEBUG)
|
961
965
|
```
|
962
966
|
|
967
|
+
## Docker Usage
|
968
|
+
|
969
|
+
You can run `prometheus_exporter` project using an official Docker image:
|
970
|
+
|
971
|
+
```bash
|
972
|
+
docker pull discourse/prometheus_exporter:latest
|
973
|
+
# or use specific version
|
974
|
+
docker pull discourse/prometheus_exporter:x.x.x
|
975
|
+
```
|
976
|
+
|
977
|
+
The start the container:
|
978
|
+
|
979
|
+
```bash
|
980
|
+
docker run -p 9394:9394 discourse/prometheus_exporter
|
981
|
+
```
|
982
|
+
|
983
|
+
Additional flags could be included:
|
984
|
+
|
985
|
+
```
|
986
|
+
docker run -p 9394:9394 discourse/prometheus_exporter --verbose --prefix=myapp
|
987
|
+
```
|
988
|
+
|
963
989
|
## Docker/Kubernetes Healthcheck
|
964
990
|
|
965
991
|
A `/ping` endpoint which only returns `PONG` is available so you can run container healthchecks :
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PrometheusExporter::Server
|
4
|
+
class MetricsContainer
|
5
|
+
METRIC_MAX_AGE = 60
|
6
|
+
METRIC_EXPIRE_ATTR = "_expire_at"
|
7
|
+
|
8
|
+
attr_reader :data, :ttl
|
9
|
+
attr_accessor :filter
|
10
|
+
|
11
|
+
def initialize(ttl: METRIC_MAX_AGE, expire_attr: METRIC_EXPIRE_ATTR, filter: nil)
|
12
|
+
@data = []
|
13
|
+
@ttl = ttl
|
14
|
+
@expire_attr = expire_attr
|
15
|
+
@filter = filter
|
16
|
+
end
|
17
|
+
|
18
|
+
def <<(obj)
|
19
|
+
now = get_time
|
20
|
+
obj[@expire_attr] = now + @ttl
|
21
|
+
|
22
|
+
expire(time: now, new_metric: obj)
|
23
|
+
|
24
|
+
@data << obj
|
25
|
+
@data
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
@data.tap { expire }[key]
|
30
|
+
end
|
31
|
+
|
32
|
+
def size(&blk)
|
33
|
+
wrap_expire(:size, &blk)
|
34
|
+
end
|
35
|
+
alias_method :length, :size
|
36
|
+
|
37
|
+
def map(&blk)
|
38
|
+
wrap_expire(:map, &blk)
|
39
|
+
end
|
40
|
+
|
41
|
+
def each(&blk)
|
42
|
+
wrap_expire(:each, &blk)
|
43
|
+
end
|
44
|
+
|
45
|
+
def expire(time: nil, new_metric: nil)
|
46
|
+
time ||= get_time
|
47
|
+
|
48
|
+
@data.delete_if do |metric|
|
49
|
+
expired = metric[@expire_attr] < time
|
50
|
+
expired ||= filter.call(new_metric, metric) if @filter && new_metric
|
51
|
+
expired
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def get_time
|
58
|
+
::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
59
|
+
end
|
60
|
+
|
61
|
+
def wrap_expire(method_name, &blk)
|
62
|
+
expire
|
63
|
+
@data.public_send(method_name, &blk)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -14,7 +14,10 @@ module PrometheusExporter::Server
|
|
14
14
|
}
|
15
15
|
|
16
16
|
def initialize
|
17
|
-
@puma_metrics =
|
17
|
+
@puma_metrics = MetricsContainer.new
|
18
|
+
@puma_metrics.filter = -> (new_metric, old_metric) do
|
19
|
+
new_metric["pid"] == old_metric["pid"] && new_metric["hostname"] == old_metric["hostname"]
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def type
|
@@ -51,15 +54,6 @@ module PrometheusExporter::Server
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def collect(obj)
|
54
|
-
now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
55
|
-
|
56
|
-
obj["created_at"] = now
|
57
|
-
|
58
|
-
@puma_metrics.delete_if do |current|
|
59
|
-
(obj["pid"] == current["pid"] && obj["hostname"] == current["hostname"]) ||
|
60
|
-
(current["created_at"] + MAX_PUMA_METRIC_AGE < now)
|
61
|
-
end
|
62
|
-
|
63
57
|
@puma_metrics << obj
|
64
58
|
end
|
65
59
|
end
|
@@ -12,7 +12,7 @@ module PrometheusExporter::Server
|
|
12
12
|
attr_reader :sidekiq_metrics, :gauges
|
13
13
|
|
14
14
|
def initialize
|
15
|
-
@sidekiq_metrics =
|
15
|
+
@sidekiq_metrics = MetricsContainer.new(ttl: MAX_SIDEKIQ_METRIC_AGE)
|
16
16
|
@gauges = {}
|
17
17
|
end
|
18
18
|
|
@@ -21,6 +21,8 @@ module PrometheusExporter::Server
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def metrics
|
24
|
+
SIDEKIQ_PROCESS_GAUGES.each_key { |name| gauges[name]&.reset! }
|
25
|
+
|
24
26
|
sidekiq_metrics.map do |metric|
|
25
27
|
labels = metric.fetch('labels', {})
|
26
28
|
SIDEKIQ_PROCESS_GAUGES.map do |name, help|
|
@@ -35,12 +37,7 @@ module PrometheusExporter::Server
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def collect(object)
|
38
|
-
|
39
|
-
process = object['process']
|
40
|
-
|
41
|
-
process["created_at"] = now
|
42
|
-
sidekiq_metrics.delete_if { |metric| metric['created_at'] + MAX_SIDEKIQ_METRIC_AGE < now }
|
43
|
-
sidekiq_metrics << process
|
40
|
+
@sidekiq_metrics << object["process"]
|
44
41
|
end
|
45
42
|
end
|
46
43
|
end
|
@@ -11,7 +11,7 @@ module PrometheusExporter::Server
|
|
11
11
|
attr_reader :sidekiq_metrics, :gauges
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@sidekiq_metrics =
|
14
|
+
@sidekiq_metrics = MetricsContainer.new
|
15
15
|
@gauges = {}
|
16
16
|
end
|
17
17
|
|
@@ -20,6 +20,8 @@ module PrometheusExporter::Server
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def metrics
|
23
|
+
SIDEKIQ_QUEUE_GAUGES.each_key { |name| gauges[name]&.reset! }
|
24
|
+
|
23
25
|
sidekiq_metrics.map do |metric|
|
24
26
|
labels = metric.fetch("labels", {})
|
25
27
|
SIDEKIQ_QUEUE_GAUGES.map do |name, help|
|
@@ -34,12 +36,9 @@ module PrometheusExporter::Server
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def collect(object)
|
37
|
-
now = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
38
39
|
object['queues'].each do |queue|
|
39
|
-
queue["created_at"] = now
|
40
40
|
queue["labels"].merge!(object['custom_labels']) if object['custom_labels']
|
41
|
-
sidekiq_metrics
|
42
|
-
sidekiq_metrics << queue
|
41
|
+
@sidekiq_metrics << queue
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
@@ -18,7 +18,7 @@ module PrometheusExporter::Server
|
|
18
18
|
attr_reader :sidekiq_metrics, :gauges
|
19
19
|
|
20
20
|
def initialize
|
21
|
-
@sidekiq_metrics =
|
21
|
+
@sidekiq_metrics = MetricsContainer.new(ttl: MAX_SIDEKIQ_METRIC_AGE)
|
22
22
|
@gauges = {}
|
23
23
|
end
|
24
24
|
|
@@ -27,6 +27,8 @@ module PrometheusExporter::Server
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def metrics
|
30
|
+
SIDEKIQ_STATS_GAUGES.each_key { |name| gauges[name]&.reset! }
|
31
|
+
|
30
32
|
sidekiq_metrics.map do |metric|
|
31
33
|
SIDEKIQ_STATS_GAUGES.map do |name, help|
|
32
34
|
if (value = metric['stats'][name])
|
@@ -40,10 +42,7 @@ module PrometheusExporter::Server
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def collect(object)
|
43
|
-
|
44
|
-
object['created_at'] = now
|
45
|
-
sidekiq_metrics.delete_if { |metric| metric['created_at'] + MAX_SIDEKIQ_METRIC_AGE < now }
|
46
|
-
sidekiq_metrics << object
|
45
|
+
@sidekiq_metrics << object
|
47
46
|
end
|
48
47
|
end
|
49
48
|
end
|
@@ -44,6 +44,11 @@ module PrometheusExporter::Server
|
|
44
44
|
|
45
45
|
@logger.info "Using Basic Authentication via #{@auth}" if @verbose && @auth
|
46
46
|
|
47
|
+
if %w(ALL ANY).include?(@bind)
|
48
|
+
@logger.info "Listening on both 0.0.0.0/:: network interfaces"
|
49
|
+
@bind = nil
|
50
|
+
end
|
51
|
+
|
47
52
|
@server = WEBrick::HTTPServer.new(
|
48
53
|
Port: @port,
|
49
54
|
BindAddress: @bind,
|
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: 2.0.
|
4
|
+
version: 2.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webrick
|
@@ -243,11 +243,13 @@ extensions: []
|
|
243
243
|
extra_rdoc_files: []
|
244
244
|
files:
|
245
245
|
- ".github/workflows/ci.yml"
|
246
|
+
- ".github/workflows/docker.yml"
|
246
247
|
- ".gitignore"
|
247
248
|
- ".rubocop.yml"
|
248
249
|
- Appraisals
|
249
250
|
- CHANGELOG
|
250
251
|
- CODE_OF_CONDUCT.md
|
252
|
+
- Dockerfile
|
251
253
|
- Gemfile
|
252
254
|
- Guardfile
|
253
255
|
- LICENSE.txt
|
@@ -289,6 +291,7 @@ files:
|
|
289
291
|
- lib/prometheus_exporter/server/collector_base.rb
|
290
292
|
- lib/prometheus_exporter/server/delayed_job_collector.rb
|
291
293
|
- lib/prometheus_exporter/server/hutch_collector.rb
|
294
|
+
- lib/prometheus_exporter/server/metrics_container.rb
|
292
295
|
- lib/prometheus_exporter/server/process_collector.rb
|
293
296
|
- lib/prometheus_exporter/server/puma_collector.rb
|
294
297
|
- lib/prometheus_exporter/server/resque_collector.rb
|