class Sidekiq::Opentsdb::ServerMiddleware
Constants
- SIDEKIQ_METRICS
Public Class Methods
new(options = {})
click to toggle source
# File lib/sidekiq/opentsdb/server_middleware.rb, line 7 def initialize(options = {}) @options = options if !options.key?(:opentsdb_hostname) || !options.key?(:opentsdb_port) fail '[sidekiq-opentsdb] OpenTSDB configuration not found...' end end
Public Instance Methods
call(*) { || ... }
click to toggle source
# File lib/sidekiq/opentsdb/server_middleware.rb, line 15 def call(*) yield sidekiq_stats_metrics_with_values.each do |metric, value| opentsdb_client.put metric: "#{metric_prefix}sidekiq.#{metric}", value: value, timestamp: Time.now.to_i, tags: tags end rescue ::OpenTSDB::Errors::UnableToConnectError end
Private Instance Methods
metric_prefix()
click to toggle source
# File lib/sidekiq/opentsdb/server_middleware.rb, line 48 def metric_prefix @options.key?(:metric_prefix) ? "#{@options[:metric_prefix]}." : '' end
opentsdb_client()
click to toggle source
# File lib/sidekiq/opentsdb/server_middleware.rb, line 52 def opentsdb_client @opentsdb_client ||= ::OpenTSDB::Client.new hostname: @options[:opentsdb_hostname], port: @options[:opentsdb_port] end
selected_metrics()
click to toggle source
# File lib/sidekiq/opentsdb/server_middleware.rb, line 34 def selected_metrics if @options.key?(:only) SIDEKIQ_METRICS.select { |key| @options[:only].include?(key) } elsif @options.key?(:except) SIDEKIQ_METRICS.select { |key| !@options[:except].include?(key) } else SIDEKIQ_METRICS end end
sidekiq_stats_metrics_with_values()
click to toggle source
# File lib/sidekiq/opentsdb/server_middleware.rb, line 27 def sidekiq_stats_metrics_with_values sidekiq_stats_instance = Sidekiq::Stats.new selected_metrics.inject({}) do |hash, sidekiq_metric| hash.merge("stats.#{sidekiq_metric}" => sidekiq_stats_instance.send(sidekiq_metric)) end end