class Prometheus::Client::Push
Push implements a simple way to transmit a given registry to a given Pushgateway.
Constants
- DEFAULT_GATEWAY
- HEADER
- INSTANCE_PATH
- PATH
Attributes
gateway[R]
instance[R]
job[R]
path[R]
Public Class Methods
new(job, instance = nil, gateway = nil)
click to toggle source
# File lib/prometheus/client/push.rb, line 21 def initialize(job, instance = nil, gateway = nil) @job = job @instance = instance @gateway = gateway || DEFAULT_GATEWAY @uri = parse(@gateway) @path = build_path(job, instance) @http = Net::HTTP.new(@uri.host, @uri.port) end
Public Instance Methods
add(registry)
click to toggle source
# File lib/prometheus/client/push.rb, line 30 def add(registry) request('POST', registry) end
delete()
click to toggle source
# File lib/prometheus/client/push.rb, line 38 def delete @http.send_request('DELETE', path) end
replace(registry)
click to toggle source
# File lib/prometheus/client/push.rb, line 34 def replace(registry) request('PUT', registry) end
Private Instance Methods
build_path(job, instance)
click to toggle source
# File lib/prometheus/client/push.rb, line 56 def build_path(job, instance) if instance format(INSTANCE_PATH, URI.escape(job), URI.escape(instance)) else format(PATH, URI.escape(job)) end end
parse(url)
click to toggle source
# File lib/prometheus/client/push.rb, line 44 def parse(url) uri = URI.parse(url) if uri.scheme == 'http' uri else raise ArgumentError, 'only HTTP gateway URLs are supported currently.' end rescue URI::InvalidURIError => e raise ArgumentError, "#{url} is not a valid URL: #{e}" end
request(method, registry)
click to toggle source
# File lib/prometheus/client/push.rb, line 64 def request(method, registry) data = Formats::Text.marshal(registry) @http.send_request(method, path, data, HEADER) end