Class: Splash::Processes::ProcessNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/splash/processes.rb

Constant Summary collapse

@@registry =
Prometheus::Client::Registry::new
@@metric_status =
Prometheus::Client::Gauge.new(:process_status, docstring: 'SPLASH metric process status', labels: [:process ])
@@metric_cpu_percent =
Prometheus::Client::Gauge.new(:process_cpu_percent, docstring: 'SPLASH metric process CPU usage in percent', labels: [:process ])
@@metric_mem_percent =
Prometheus::Client::Gauge.new(:process_mem_percent, docstring: 'SPLASH metric process MEM usage in percent', labels: [:process ])

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProcessNotifier

Returns a new instance of ProcessNotifier.



21
22
23
24
25
26
27
28
# File 'lib/splash/processes.rb', line 21

def initialize(options={})
  @config = get_config
  @url = @config.prometheus_pushgateway_url
  @name = options[:name]
  @status = options[:status]
  @cpu_percent = options[:cpu_percent]
  @mem_percent = options[:mem_percent]
end

Instance Method Details

#notifyBool

send metrics to Prometheus PushGateway

Returns:

  • (Bool)


32
33
34
35
36
37
38
39
40
41
# File 'lib/splash/processes.rb', line 32

def notify
  unless verify_service url: @url then
    return { :case => :service_dependence_missing, :more => "Prometheus Notification not send."}
  end
  @@metric_mem_percent.set(@mem_percent, labels: { process: @name })
  @@metric_cpu_percent.set(@cpu_percent, labels: { process: @name })
  @@metric_status.set(@status, labels: { process: @name })
  hostname = Socket.gethostname
  return Prometheus::Client::Push.new("Splash", hostname, @url).add(@@registry)
end