-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom collectors to Prometheus registry (#16)
The gem `prometheus-client` doesn't support a custom collectors [issue 90](prometheus/client_ruby#90). This PL add missing functionality, but only if the management server is used.
- Loading branch information
Showing
5 changed files
with
62 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lib/bm/instrumentations/internal/prometheus_registry_custom_collectors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module BM | ||
module Instrumentations | ||
# Extends the Prometheus registry to support custom metric collectors | ||
# | ||
# @see https://github.com/prometheus/client_ruby/issues/90 | ||
module PrometheusRegistryCustomCollectors | ||
# Initialize custom_collectors array | ||
def initialize(*args, **kwargs) | ||
super(*args, **kwargs) | ||
@custom_collectors = [] | ||
end | ||
|
||
# Registers an updater that poll and update metrics periodically | ||
# | ||
# @param collector [Proc] | ||
def add_custom_collector(&collector) | ||
@mutex.synchronize do | ||
@custom_collectors << collector | ||
end | ||
end | ||
|
||
# Invokes all registered custom collectors to update metrics | ||
# | ||
# @return [void] | ||
def custom_collectors! | ||
@custom_collectors.each(&:call) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Prometheus::Client::Registry.prepend(BM::Instrumentations::PrometheusRegistryCustomCollectors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters