Class: Batsd::Handler::Gauge
- Inherits:
-
Batsd::Handler
- Object
- Batsd::Handler
- Batsd::Handler::Gauge
- Defined in:
- lib/batsd/handlers/gauge.rb
Overview
Handles gauge measurements ("|g")
Gauge measurements are never aggregated, and are only stored on disk. They are written to disk immediately upon receipt and without manipulation beyond correcting for sample rate (or more accurately, scale), if provided.
Instance Method Summary (collapse)
-
- (Object) handle(key, value, sample_rate)
Process an incoming gauge measurement.
-
- (Gauge) initialize(options)
constructor
Set up a new handler to handle gauges.
Methods inherited from Batsd::Handler
Constructor Details
- (Gauge) initialize(options)
Set up a new handler to handle gauges
-
Set up a redis client
-
Set up a diskstore client to write aggregates to disk
17 18 19 20 21 |
# File 'lib/batsd/handlers/gauge.rb', line 17 def initialize() @redis = Batsd::Redis.new() @diskstore = Batsd::Diskstore.new([:root]) super end |
Instance Method Details
- (Object) handle(key, value, sample_rate)
Process an incoming gauge measurement
-
Normalize for sample rate provided
-
Write current timestamp and value to disk
-
Store the name of the datapoint in Redis
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/batsd/handlers/gauge.rb', line 29 def handle(key, value, sample_rate) @threadpool.queue Time.now.to_i, key, value, sample_rate do |, key, value, sample_rate| puts "Received #{key} #{value} #{sample_rate}" if ENV["VVERBOSE"] if sample_rate value = value.to_f / sample_rate.gsub("@", "").to_f end value = "#{timestamp} #{value}" key = "gauges:#{key}" @diskstore.append_value_to_file(@diskstore.build_filename(key), value) @redis.add_datapoint key end end |