Sha256: 93250720f83655489b1d6ca188738cb93d26bc84c73dce4c72e8ba86564029b7
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
require "influxdb/rails/middleware/subscriber" 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}") ensure InfluxDB::Rails.current.reset end private def tags(payload) 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, } super(tags) end def values(started, finished, payload) { controller: ((finished - started) * 1000).ceil, 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 end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
influxdb-rails-1.0.0 | lib/influxdb/rails/middleware/request_subscriber.rb |
influxdb-rails-1.0.0.beta4 | lib/influxdb/rails/middleware/request_subscriber.rb |