lib/statsd/instrument.rb in statsd-instrument-2.0.12 vs lib/statsd/instrument.rb in statsd-instrument-2.1.0
- old
+ new
@@ -275,11 +275,11 @@
# HTTP.get(url)
# end
def measure(key, value = nil, *metric_options, &block)
if value.is_a?(Hash) && metric_options.empty?
metric_options = [value]
- value = nil
+ value = value.fetch(:value, nil)
end
result = nil
value = 1000 * StatsD::Instrument.duration { result = block.call } if block_given?
metric = collect_metric(hash_argument(metric_options).merge(type: :ms, name: key, value: value))
@@ -299,11 +299,11 @@
# @param metric_options [Hash] (default: {}) Metric options
# @return (see #collect_metric)
def increment(key, value = 1, *metric_options)
if value.is_a?(Hash) && metric_options.empty?
metric_options = [value]
- value = 1
+ value = value.fetch(:value, 1)
end
collect_metric(hash_argument(metric_options).merge(type: :c, name: key, value: value))
end
@@ -311,39 +311,59 @@
# @param key [String] The name of the metric.
# @param value [Numeric] The current value to record.
# @param metric_options [Hash] (default: {}) Metric options
# @return (see #collect_metric)
def gauge(key, value, *metric_options)
+ if value.is_a?(Hash) && metric_options.empty?
+ metric_options = [value]
+ value = value.fetch(:value, nil)
+ end
+
collect_metric(hash_argument(metric_options).merge(type: :g, name: key, value: value))
end
# Emits a histogram metric.
# @param key [String] The name of the metric.
# @param value [Numeric] The value to record.
# @param metric_options [Hash] (default: {}) Metric options
# @return (see #collect_metric)
# @note Supported by the datadog implementation only.
def histogram(key, value, *metric_options)
+ if value.is_a?(Hash) && metric_options.empty?
+ metric_options = [value]
+ value = value.fetch(:value, nil)
+ end
+
collect_metric(hash_argument(metric_options).merge(type: :h, name: key, value: value))
end
# Emits a key/value metric.
# @param key [String] The name of the metric.
# @param value [Numeric] The value to record.
# @param metric_options [Hash] (default: {}) Metric options
# @return (see #collect_metric)
# @note Supported by the statsite implementation only.
def key_value(key, value, *metric_options)
+ if value.is_a?(Hash) && metric_options.empty?
+ metric_options = [value]
+ value = value.fetch(:value, nil)
+ end
+
collect_metric(hash_argument(metric_options).merge(type: :kv, name: key, value: value))
end
# Emits a set metric.
# @param key [String] The name of the metric.
# @param value [Numeric] The value to record.
# @param metric_options [Hash] (default: {}) Metric options
# @return (see #collect_metric)
# @note Supported by the datadog implementation only.
def set(key, value, *metric_options)
+ if value.is_a?(Hash) && metric_options.empty?
+ metric_options = [value]
+ value = value.fetch(:value, nil)
+ end
+
collect_metric(hash_argument(metric_options).merge(type: :s, name: key, value: value))
end
private