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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/prometheus/client/push.rb', line 32 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.
30 31 32 |
# File 'lib/prometheus/client/push.rb', line 30 def gateway @gateway end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
30 31 32 |
# File 'lib/prometheus/client/push.rb', line 30 def job @job end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/prometheus/client/push.rb', line 30 def path @path end |
Instance Method Details
#add(registry) ⇒ Object
58 59 60 61 62 |
# File 'lib/prometheus/client/push.rb', line 58 def add(registry) synchronize do request(Net::HTTP::Post, registry) end end |
#basic_auth(user, password) ⇒ Object
53 54 55 56 |
# File 'lib/prometheus/client/push.rb', line 53 def basic_auth(user, password) @user = user @password = password end |
#delete ⇒ Object
70 71 72 73 74 |
# File 'lib/prometheus/client/push.rb', line 70 def delete synchronize do request(Net::HTTP::Delete) end end |
#replace(registry) ⇒ Object
64 65 66 67 68 |
# File 'lib/prometheus/client/push.rb', line 64 def replace(registry) synchronize do request(Net::HTTP::Put, registry) end end |