Class: Prometheus::Client::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus/client/push.rb

Overview

Push implements a simple way to transmit a given registry to a given Pushgateway.

Constant Summary collapse

DEFAULT_GATEWAY =
'http://localhost:9091'
PATH =
'/metrics/jobs/%s'
INSTANCE_PATH =
'/metrics/jobs/%s/instances/%s'
HEADER =
{ 'Content-Type' => Formats::Text::CONTENT_TYPE }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, instance = nil, gateway = nil) ⇒ Push

Returns a new instance of Push.



22
23
24
25
26
27
28
# File 'lib/prometheus/client/push.rb', line 22

def initialize(job, instance = nil, gateway = nil)
  @job, @instance, @gateway = job, instance, gateway || DEFAULT_GATEWAY

  @uri  = parse(@gateway)
  @path = build_path(job, instance)
  @http = Net::HTTP.new(@uri.host, @uri.port)
end

Instance Attribute Details

#gatewayObject (readonly)

Returns the value of attribute gateway.



20
21
22
# File 'lib/prometheus/client/push.rb', line 20

def gateway
  @gateway
end

#instanceObject (readonly)

Returns the value of attribute instance.



20
21
22
# File 'lib/prometheus/client/push.rb', line 20

def instance
  @instance
end

#jobObject (readonly)

Returns the value of attribute job.



20
21
22
# File 'lib/prometheus/client/push.rb', line 20

def job
  @job
end

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/prometheus/client/push.rb', line 20

def path
  @path
end

Instance Method Details

#add(registry) ⇒ Object



30
31
32
33
34
# File 'lib/prometheus/client/push.rb', line 30

def add(registry)
  data = Formats::Text.marshal(registry)

  @http.send_request('PUT', path, data, HEADER)
end

#replace(registry) ⇒ Object



36
37
38
39
40
# File 'lib/prometheus/client/push.rb', line 36

def replace(registry)
  @http.send_request('DELETE', path)

  add(registry)
end