Class: Gruf::Prometheus::Hook
- Inherits:
-
Hooks::Base
- Object
- Hooks::Base
- Gruf::Prometheus::Hook
- Defined in:
- lib/gruf/prometheus/hook.rb
Overview
Hook for implementing prometheus stats before a gruf server starts
Instance Method Summary collapse
-
#after_server_stop ⇒ Object
Handle proper shutdown of the prometheus server.
-
#before_server_start(server:) ⇒ Object
Startup the instrumentors for collection of gRPC and process metrics prior to server start.
Instance Method Details
#after_server_stop ⇒ Object
Handle proper shutdown of the prometheus server
48 49 50 51 52 53 |
# File 'lib/gruf/prometheus/hook.rb', line 48 def after_server_stop(*) stop_collectors prometheus_server.stop rescue StandardError => e logger.error "[gruf-prometheus][#{::Gruf::Prometheus.process_name}] Failed to stop gruf instrumentation - #{e.} - #{e.backtrace[0..4].join("\n")}" end |
#before_server_start(server:) ⇒ Object
Startup the instrumentors for collection of gRPC and process metrics prior to server start
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gruf/prometheus/hook.rb', line 29 def before_server_start(server:) logger.info "[gruf-prometheus][#{::Gruf::Prometheus.process_name}] Starting #{server.class}" prometheus_server.add_type_collector(::Gruf::Prometheus::TypeCollector.new) prometheus_server.add_type_collector(::Gruf::Prometheus::Server::TypeCollector.new) prometheus_server.add_type_collector(::Gruf::Prometheus::Client::TypeCollector.new) prometheus_server.add_type_collector(::PrometheusExporter::Server::ActiveRecordCollector.new) custom_type_collectors.each do |tc| prometheus_server.add_type_collector(tc) end prometheus_server.start sleep 2 unless ENV['RACK_ENV'] == 'test' # wait for server to come online start_collectors(server: server) rescue StandardError => e logger.error "[gruf-prometheus][#{::Gruf::Prometheus.process_name}] Failed to start gruf instrumentation - #{e.} - #{e.backtrace[0..4].join("\n")}" end |