lib/influxdb/rails/middleware/request_subscriber.rb in influxdb-rails-1.0.0 vs lib/influxdb/rails/middleware/request_subscriber.rb in influxdb-rails-1.0.1.beta1

- old
+ new

@@ -2,47 +2,42 @@ module InfluxDB module Rails module Middleware class RequestSubscriber < Subscriber # :nodoc: - def call(_name, start, finish, _id, payload) - return unless enabled? - - InfluxDB::Rails.client.write_point \ - configuration.measurement_name, - values: values(start, finish, payload), - tags: tags(payload), - timestamp: timestamp(finish) - rescue StandardError => e - ::Rails.logger.error("[InfluxDB::Rails] Unable to write points: #{e.message}") + def write + super ensure InfluxDB::Rails.current.reset end private - def tags(payload) - tags = { + def tags + { method: "#{payload[:controller]}##{payload[:action]}", hook: "process_action", status: payload[:status], format: payload[:format], http_method: payload[:method], - server: Socket.gethostname, - app_name: configuration.application_name, + exception: payload[:exception]&.first, } - super(tags) end - def values(started, finished, payload) + def values { - controller: ((finished - started) * 1000).ceil, + controller: duration, view: (payload[:view_runtime] || 0).ceil, db: (payload[:db_runtime] || 0).ceil, - started: timestamp(started), - }.merge(InfluxDB::Rails.current.values).reject do |_, value| - value.nil? || value == "" - end + started: started, + } + end + + def started + InfluxDB.convert_timestamp( + start.utc, + configuration.client.time_precision + ) end end end end end