lib/splash/daemon/metrics.rb in prometheus-splash-0.7.0 vs lib/splash/daemon/metrics.rb in prometheus-splash-0.8.0
- old
+ new
@@ -15,12 +15,12 @@
@@manager=nil
# metrics manager factory
# @return [Splash::Daemon::Metrics::Manager]
- def get_metrics_manager
- return @@manager ||= Manager::new
+ def get_metrics_manager(session)
+ return @@manager ||= Manager::new(:session => session)
end
# Metrics Manager (collect and sending to Prometheus)
class Manager
@@ -30,11 +30,12 @@
attr_reader :monitoring_logs_count
# metric : processes monitoring count during Splash daemon uptime
attr_reader :monitoring_processes_count
# Constructor prepare prometheus-client, defined metrics and init attributes
- def initialize
+ def initialize(options ={})
+ @session = options[:session]
@config = get_config
@starttime = Time.now
@execution_count = 0
@monitoring_logs_count = 0
@monitoring_processes_count = 0
@@ -73,24 +74,23 @@
# Send metrics to Prometheus PushGateway
# @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
def notify
log = get_logger
- session = get_session
unless verify_service url: @config.prometheus_pushgateway_url then
return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
end
- log.debug "Sending Splash self metrics to PushGateway." , session
+ log.ok "Sending Splash self metrics to PushGateway." , @session
@metric_uptime.set uptime
@metric_execution.set execution_count
@metric_logs_monitoring.set monitoring_logs_count
@metric_processes_monitoring.set monitoring_processes_count
hostname = Socket.gethostname
url = @config.prometheus_pushgateway_url
Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
- log.debug "Sending to Prometheus PushGateway done.", session
+ log.debug "Sending to Prometheus PushGateway done.", @session
return {:case => :quiet_exit }
end