module StatsCloud::StatsmeterHelper

This helper configures StatsmeterClient.

Private Instance Methods

buffer() click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 92
def buffer
  ::LEON::StringBuffer
end
initialize_plugin_threads(plugins) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 10
def initialize_plugin_threads(plugins)
  @plugins = plugins
  @mutex = mutex_service
end
mutex_service() click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 88
def mutex_service
  Mutex.new
end
process_single_event(event) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 37
def process_single_event(event)
  name = get_event_name(event)
  measurement = get_event_measurement(event)&.to_f

  return unless @names_map && @names_map[name]

  binary_length = get_binary_length(@event_name_size_in_bytes)
  plain_length = get_plain_length(name, measurement)

  flush_events if flush_condition(binary_length, plain_length)
  record_binary_event(name, measurement, binary_length)
  record_plain_event(name, measurement, plain_length)
end
record_binary_event(name, measurement, binary_length) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 51
def record_binary_event(name, measurement, binary_length)
  @pending_binary_events.writeInt32LE(@names_map[name], @pending_binary_offset)
  @pending_binary_events = @pending_binary_events.slice(0, @pending_binary_offset + @event_name_size_in_bytes)
  measurement.zero? ? record_binary_zero : record_binary_measurement(measurement)
  @pending_binary_offset += binary_length
end
record_binary_measurement(data) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 58
def record_binary_measurement(data)
  @pending_binary_events.writeFloatBE(data, (@pending_binary_offset + @event_name_size_in_bytes))
end
record_binary_zero() click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 66
def record_binary_zero
  @pending_binary_events.writeInt32BE(0, (@pending_binary_offset + @event_name_size_in_bytes))
end
record_plain_event(name, measurement, plain_length) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 78
def record_plain_event(name, measurement, plain_length)
  @pending_plain_events.write(name, @pending_plain_offset)
  if measurement
    @pending_plain_events.write(",", @pending_plain_offset + name.length)
    measurement.zero? ? record_plain_zero(name) : record_plain_measurement(measurement, name)
  end
  @pending_plain_events.write(";", @pending_plain_offset + plain_length - 1)
  @pending_plain_offset += plain_length
end
record_plain_measurement(data, name) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 62
def record_plain_measurement(data, name)
  @pending_plain_events.writeFloatBE(data, @pending_plain_offset + name.length + 1)
end
record_plain_zero(name) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 70
def record_plain_zero(name)
  record_zero(@pending_plain_events, @pending_plain_offset + name.length + 1)
end
record_zero(buffer, offset) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 74
def record_zero(buffer, offset)
  buffer.writeInt32BE(0, offset)
end
set_client_to_nil() click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 21
def set_client_to_nil
  @client = nil
end
set_config(url, token, tags) click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 15
def set_config(url, token, tags)
  @url = url
  @token = token
  @tags = tags.map { |t| t.gsub(/[^a-z0-9_-]/, "_") }
end
set_pending_values() click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 25
def set_pending_values
  @pending_plain_events = buffer.new
  @pending_plain_offset = 0
  @pending_binary_events = buffer.new
  @pending_binary_offset = 0
end
set_socket_values() click to toggle source
# File lib/statscloud/helpers/statsmeter_client/statsmeter_helper.rb, line 32
def set_socket_values
  @names_map = {}
  @event_name_size_in_bytes = 0
end