Class: Splash::Processes::ProcessNotifier
- Inherits:
-
Object
- Object
- Splash::Processes::ProcessNotifier
- 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
-
#initialize(options = {}) ⇒ ProcessNotifier
constructor
A new instance of ProcessNotifier.
-
#notify ⇒ Bool
send metrics to Prometheus PushGateway.
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(={}) @config = get_config @url = @config.prometheus_pushgateway_url @name = [:name] @status = [:status] @cpu_percent = [:cpu_percent] @mem_percent = [:mem_percent] end |
Instance Method Details
#notify ⇒ Bool
send metrics to Prometheus PushGateway
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 |