class Gruf::Interceptors::Instrumentation::Statsd
Adds increment and timing stats to gRPC routes, pushing data to StatsD
Public Instance Methods
call() { || ... }
click to toggle source
Push data to StatsD, only doing so if a client is set
# File lib/gruf/interceptors/instrumentation/statsd.rb, line 28 def call(&block) unless client Gruf.logger.error 'Statsd module loaded, but no client configured!' return yield end client.increment(route_key) result = Gruf::Interceptors::Timer.time(&block) client.increment("#{route_key}.#{postfix(result.successful?)}") client.timing(route_key, result.elapsed) raise result.message unless result.successful? result.message end
Private Instance Methods
client()
click to toggle source
@return [::Statsd] Return the given StatsD client
# File lib/gruf/interceptors/instrumentation/statsd.rb, line 74 def client @client ||= options.fetch(:client, nil) end
key_prefix()
click to toggle source
@return [String] Return the sanitized key prefix for the statsd metric key
# File lib/gruf/interceptors/instrumentation/statsd.rb, line 66 def key_prefix prefix = options.fetch(:prefix, '').to_s prefix.empty? ? '' : "#{prefix}." end
postfix(successful)
click to toggle source
@param [Boolean] successful Whether or not the request was successful @return [String] The appropriate postfix for the key dependent on response status
# File lib/gruf/interceptors/instrumentation/statsd.rb, line 52 def postfix(successful) successful ? 'success' : 'failure' end
route_key()
click to toggle source
@return [String] Return a composed route key that is used in the statsd metric
# File lib/gruf/interceptors/instrumentation/statsd.rb, line 59 def route_key "#{key_prefix}#{request.method_name}" end