lib/influxdb/rails/middleware/simple_subscriber.rb in influxdb-rails-1.0.0.beta3 vs lib/influxdb/rails/middleware/simple_subscriber.rb in influxdb-rails-1.0.0.beta4
- old
+ new
@@ -5,41 +5,28 @@
module Middleware
# Subscriber acts as base class for different *Subscriber classes,
# which are intended as ActiveSupport::Notifications.subscribe
# consumers.
class SimpleSubscriber < Subscriber
- attr_reader :series_name
-
- def initialize(configuration, series_name)
- super(configuration)
- @series_name = series_name
- end
-
- def call(_name, started, finished, _unique_id, payload)
+ def call(_name, started, finished, _id, payload)
return unless enabled?
- begin
- InfluxDB::Rails.client.write_point series_name,
- values: values(started, finished, payload),
- tags: tags(payload),
- timestamp: timestamp(finished.utc)
- rescue StandardError => e
- log :error, "[InfluxDB::Rails] Unable to write points: #{e.message}"
- end
+ InfluxDB::Rails.client.write_point \
+ configuration.measurement_name,
+ values: values(started, finished, payload),
+ tags: tags(payload),
+ timestamp: timestamp(finished)
+ rescue StandardError => e
+ ::Rails.logger.error("[InfluxDB::Rails] Unable to write points: #{e.message}")
end
private
def values(started, finished, _payload)
- { value: ((finished - started) * 1000).ceil }
- end
-
- def timestamp(finished)
- InfluxDB.convert_timestamp(finished.utc, configuration.time_precision)
- end
-
- def enabled?
- super && series_name.present?
+ result = { value: ((finished - started) * 1000).ceil }
+ result.merge(InfluxDB::Rails.current.values).reject do |_, value|
+ value.nil? || value == ""
+ end
end
end
end
end
end