topological_inventory-providers-common 2.1.3 → 2.1.4
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c17638d4fd82db196de0019069a765bf1c6becdb20498765507ae35a02727eb
|
4
|
+
data.tar.gz: a395cd7243591bc3dab9f841e491bb978a2502d2ba1cfec3fdb004de784523dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba2b33ec9748ef58b4ca7dc30f14d34443c17026e7915fb2bd9aef2a4ec95c4c287a8149a371b91cab88974a0341f7dfd362a987ca55ea644a5b67646adafde6
|
7
|
+
data.tar.gz: 41edf911fa71ef7dcdaa220a417a236e8a593a01e227ab4f0f88e70318141f8736ad8bd9bff7e642d6cef1134d017baa8aea0c1c194987b08770a721a7a2ff00
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
## [2.1.4] - 2020-12-14
|
7
|
+
Common Counter metrics init #71
|
6
8
|
|
7
9
|
## [2.1.3] - 2020-12-14
|
8
10
|
Update travis URL in README file #67
|
@@ -3,18 +3,25 @@ require "prometheus_exporter"
|
|
3
3
|
require "prometheus_exporter/server"
|
4
4
|
require "prometheus_exporter/client"
|
5
5
|
require "prometheus_exporter/instrumentation"
|
6
|
+
require "topological_inventory/providers/common/mixins/statuses"
|
6
7
|
|
7
8
|
module TopologicalInventory
|
8
9
|
module Providers
|
9
10
|
module Common
|
10
11
|
class Metrics
|
12
|
+
include TopologicalInventory::Providers::Common::Mixins::Statuses
|
13
|
+
|
11
14
|
ERROR_COUNTER_MESSAGE = "total number of errors".freeze
|
15
|
+
ERROR_TYPES = %i[general].freeze
|
16
|
+
OPERATIONS = %w[].freeze
|
12
17
|
|
13
18
|
def initialize(port = 9394)
|
14
19
|
return if port == 0
|
15
20
|
|
16
21
|
configure_server(port)
|
17
22
|
configure_metrics
|
23
|
+
|
24
|
+
init_counters
|
18
25
|
end
|
19
26
|
|
20
27
|
def stop_server
|
@@ -25,6 +32,10 @@ module TopologicalInventory
|
|
25
32
|
@error_counter&.observe(1, :type => type.to_s)
|
26
33
|
end
|
27
34
|
|
35
|
+
def record_refresh_timing(labels = {}, &block)
|
36
|
+
record_time(@refresh_timer, labels, &block)
|
37
|
+
end
|
38
|
+
|
28
39
|
def record_operation(name, labels = {})
|
29
40
|
@status_counter&.observe(1, (labels || {}).merge(:name => name))
|
30
41
|
end
|
@@ -55,6 +66,19 @@ module TopologicalInventory
|
|
55
66
|
|
56
67
|
private
|
57
68
|
|
69
|
+
# Set all values to 0 (otherwise the counter is undefined)
|
70
|
+
def init_counters
|
71
|
+
self.class::ERROR_TYPES.each do |err_type|
|
72
|
+
@error_counter&.observe(0, :type => err_type)
|
73
|
+
end
|
74
|
+
|
75
|
+
self.class::OPERATIONS.each do |op|
|
76
|
+
operation_status.each_key do |status|
|
77
|
+
@status_counter&.observe(0, :name => op, :status => status.to_s)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
58
82
|
def configure_server(port)
|
59
83
|
@server = PrometheusExporter::Server::WebServer.new(:port => port)
|
60
84
|
@server.start
|
@@ -67,10 +91,11 @@ module TopologicalInventory
|
|
67
91
|
PrometheusExporter::Metric::Base.default_prefix = default_prefix
|
68
92
|
|
69
93
|
@duration_seconds = PrometheusExporter::Metric::Histogram.new('duration_seconds', 'Duration of processed operation')
|
94
|
+
@refresh_timer = PrometheusExporter::Metric::Histogram.new('refresh_time', 'Duration of full refresh')
|
70
95
|
@error_counter = PrometheusExporter::Metric::Counter.new('errors_total', ERROR_COUNTER_MESSAGE)
|
71
96
|
@status_counter = PrometheusExporter::Metric::Counter.new('status_counter', 'number of processed operations')
|
72
97
|
|
73
|
-
[@duration_seconds, @error_counter, @status_counter].each do |metric|
|
98
|
+
[@duration_seconds, @refresh_timer, @error_counter, @status_counter].each do |metric|
|
74
99
|
@server.collector.register_metric(metric)
|
75
100
|
end
|
76
101
|
end
|