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'.freeze
PATH =
'/metrics/job/%s'.freeze
INSTANCE_PATH =
'/metrics/job/%s/instance/%s'.freeze
SUPPORTED_SCHEMES =
%w(http https).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Push.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/prometheus/client/push.rb', line 23

def initialize(job, instance = nil, gateway = nil)
  @mutex = Mutex.new
  @job = job
  @instance = instance
  @gateway = gateway || DEFAULT_GATEWAY
  @path = build_path(job, instance)
  @uri = parse("#{@gateway}#{@path}")

  @http = Net::HTTP.new(@uri.host, @uri.port)
  @http.use_ssl = (@uri.scheme == 'https')
end

Instance Attribute Details

#gatewayObject (readonly)

Returns the value of attribute gateway.



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

def gateway
  @gateway
end

#instanceObject (readonly)

Returns the value of attribute instance.



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

def instance
  @instance
end

#jobObject (readonly)

Returns the value of attribute job.



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

def job
  @job
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#add(registry) ⇒ Object



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

def add(registry)
  synchronize do
    request(Net::HTTP::Post, registry)
  end
end

#deleteObject



47
48
49
50
51
# File 'lib/prometheus/client/push.rb', line 47

def delete
  synchronize do
    request(Net::HTTP::Delete)
  end
end

#replace(registry) ⇒ Object



41
42
43
44
45
# File 'lib/prometheus/client/push.rb', line 41

def replace(registry)
  synchronize do
    request(Net::HTTP::Put, registry)
  end
end