gruf-prometheus 1.0.2 → 2.1.0

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.
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright (c) 2019-present, BigCommerce Pty. Ltd. All rights reserved
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
- # documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
- # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
- # persons to whom the Software is furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
- # Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
- # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
- # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
- #
18
- module Gruf
19
- module Prometheus
20
- module TypeCollectors
21
- ##
22
- # Type Collector for prometheus and grpc instrumentation
23
- #
24
- class Grpc < PrometheusExporter::Server::TypeCollector
25
- ##
26
- # Initialize the collector
27
- #
28
- def initialize
29
- @pool_jobs_waiting_total = PrometheusExporter::Metric::Gauge.new('grpc_pool_jobs_waiting_total', 'Number jobs in the gRPC thread pool that are actively waiting')
30
- @pool_ready_workers_total = PrometheusExporter::Metric::Gauge.new('grpc_pool_ready_workers_total', 'The amount of non-busy workers in the thread pool')
31
- @pool_workers_total = PrometheusExporter::Metric::Gauge.new('grpc_pool_workers_total', 'Number of workers in the gRPC thread pool')
32
- @pool_initial_size = PrometheusExporter::Metric::Gauge.new('grpc_pool_initial_size', 'Initial size of the gRPC thread pool')
33
- @poll_period = PrometheusExporter::Metric::Gauge.new('grpc_poll_period', 'Polling period for the gRPC thread pool')
34
- @thread_pool_exhausted = PrometheusExporter::Metric::Counter.new('grpc_thread_pool_exhausted', 'Times the gRPC thread pool has been exhausted')
35
- end
36
-
37
- ##
38
- # @return [String]
39
- #
40
- def type
41
- 'grpc'
42
- end
43
-
44
- ##
45
- # @return [Array]
46
- #
47
- def metrics
48
- return [] unless @pool_jobs_waiting_total
49
-
50
- [
51
- @pool_jobs_waiting_total,
52
- @pool_ready_workers_total,
53
- @pool_workers_total,
54
- @pool_initial_size,
55
- @poll_period,
56
- @thread_pool_exhausted
57
- ]
58
- end
59
-
60
- ##
61
- # Collect the object into the buffer
62
- #
63
- def collect(obj)
64
- default_labels = {}
65
- default_labels['environment'] = obj['environment'] if obj['environment']
66
-
67
- custom_labels = obj['custom_labels'] || {}
68
- labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
69
-
70
- @pool_jobs_waiting_total.observe(obj['pool_jobs_waiting_total'].to_i, labels)
71
- @pool_ready_workers_total.observe(obj['pool_ready_workers_total'].to_i, labels)
72
- @pool_workers_total.observe(obj['pool_workers_total'].to_i, labels)
73
- @pool_initial_size.observe(obj['pool_initial_size'].to_i, labels)
74
- @poll_period.observe(obj['poll_period'].to_i, labels)
75
- @thread_pool_exhausted.observe(obj['thread_pool_exhausted'].to_i, labels)
76
- end
77
- end
78
- end
79
- end
80
- end