lib/splash/daemon/metrics.rb in prometheus-splash-0.5.3 vs lib/splash/daemon/metrics.rb in prometheus-splash-0.6.0

- old
+ new

@@ -1,28 +1,39 @@ +# coding: utf-8 + +# base Splash module module Splash + + # global daemon module module Daemon + + # Metrics management modulefor Splash daemon module Metrics include Splash::Constants include Splash::Helpers include Splash::Config include Splash::Loggers @@manager=nil - # factory of Configuration Class instance - # @param [String] config_file the path of the YAML Config file - # @return [SPlash::Config::Configuration] + + # metrics manager factory + # @return [Splash::Daemon::Metrics::Manager] def get_metrics_manager return @@manager ||= Manager::new end - + # Metrics Manager (collect and sending to Prometheus) class Manager + # metric : commands executions count during Splash daemon uptime attr_reader :execution_count + # metric : logs monitoring count during Splash daemon uptime 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 @config = get_config @starttime = Time.now @execution_count = 0 @monitoring_logs_count = 0 @@ -38,28 +49,32 @@ @registry.register(@metric_execution) @registry.register(@metric_logs_monitoring) @registry.register(@metric_processes_monitoring) end - + # virtual accessor uptime def uptime return Time.now - @starttime end + # increment metric : execution_count def inc_execution @execution_count += 1 end - + # increment metric : monitoring_logs_count def inc_logs_monitoring @monitoring_logs_count += 1 end + # increment metric : monitoring_processes_count def inc_processes_monitoring @monitoring_processes_count += 1 end + # 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 host: @config.prometheus_pushgateway_host ,port: @config.prometheus_pushgateway_port then return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." } @@ -70,10 +85,10 @@ @metric_execution.set execution_count @metric_logs_monitoring.set monitoring_logs_count @metric_processes_monitoring.set monitoring_processes_count hostname = Socket.gethostname - url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}" + url = "http://#{@config.prometheus_pushgateway_host}:#{@config.prometheus_pushgateway_port}/#{@config.prometheus_pushgateway_path}" Prometheus::Client::Push.new('Splash',hostname, url).add(@registry) log.debug "Sending to Prometheus PushGateway done.", session return {:case => :quiet_exit } end