Class: Prometheus::Client::Push
- Inherits:
-
Object
- Object
- Prometheus::Client::Push
- Defined in:
- lib/prometheus/client/push.rb
Overview
Push implements a simple way to transmit a given registry to a given Pushgateway.
Defined Under Namespace
Classes: HttpClientError, HttpError, HttpRedirectError, HttpServerError
Constant Summary collapse
- DEFAULT_GATEWAY =
'http://localhost:9091'.freeze
- PATH =
'/metrics'.freeze
- SUPPORTED_SCHEMES =
%w(http https).freeze
Instance Attribute Summary collapse
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add(registry) ⇒ Object
- #basic_auth(user, password) ⇒ Object
- #delete ⇒ Object
-
#initialize(job:, gateway: DEFAULT_GATEWAY, grouping_key: {}, **kwargs) ⇒ Push
constructor
A new instance of Push.
- #replace(registry) ⇒ Object
Constructor Details
#initialize(job:, gateway: DEFAULT_GATEWAY, grouping_key: {}, **kwargs) ⇒ Push
Returns a new instance of Push.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/prometheus/client/push.rb', line 31 def initialize(job:, gateway: DEFAULT_GATEWAY, grouping_key: {}, **kwargs) raise ArgumentError, "job cannot be nil" if job.nil? raise ArgumentError, "job cannot be empty" if job.empty? @validator = LabelSetValidator.new(expected_labels: grouping_key.keys) @validator.validate_symbols!(grouping_key) @mutex = Mutex.new @job = job @gateway = gateway || DEFAULT_GATEWAY @grouping_key = grouping_key @path = build_path(job, grouping_key) @uri = parse("#{@gateway}#{@path}") validate_no_basic_auth!(@uri) @http = Net::HTTP.new(@uri.host, @uri.port) @http.use_ssl = (@uri.scheme == 'https') @http.open_timeout = kwargs[:open_timeout] if kwargs[:open_timeout] @http.read_timeout = kwargs[:read_timeout] if kwargs[:read_timeout] end |
Instance Attribute Details
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
29 30 31 |
# File 'lib/prometheus/client/push.rb', line 29 def gateway @gateway end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
29 30 31 |
# File 'lib/prometheus/client/push.rb', line 29 def job @job end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/prometheus/client/push.rb', line 29 def path @path end |
Instance Method Details
#add(registry) ⇒ Object
57 58 59 60 61 |
# File 'lib/prometheus/client/push.rb', line 57 def add(registry) synchronize do request(Net::HTTP::Post, registry) end end |
#basic_auth(user, password) ⇒ Object
52 53 54 55 |
# File 'lib/prometheus/client/push.rb', line 52 def basic_auth(user, password) @user = user @password = password end |
#delete ⇒ Object
69 70 71 72 73 |
# File 'lib/prometheus/client/push.rb', line 69 def delete synchronize do request(Net::HTTP::Delete) end end |
#replace(registry) ⇒ Object
63 64 65 66 67 |
# File 'lib/prometheus/client/push.rb', line 63 def replace(registry) synchronize do request(Net::HTTP::Put, registry) end end |