Class: SemanticLogger::Metric::Signalfx
- Inherits:
-
Appender::Http
- Object
- Base
- Subscriber
- Appender::Http
- SemanticLogger::Metric::Signalfx
- Defined in:
- lib/semantic_logger/metric/signalfx.rb
Constant Summary collapse
- END_POINT =
"v2/datapoint".freeze
Instance Attribute Summary collapse
-
#full_url ⇒ Object
readonly
Returns the value of attribute full_url.
Attributes inherited from Appender::Http
#compress, #continue_timeout, #header, #http, #open_timeout, #path, #port, #proxy_url, #read_timeout, #server, #ssl_options, #url, #username
Attributes inherited from Subscriber
#application, #environment, #formatter, #host, #logger, #metrics
Attributes inherited from Base
Instance Method Summary collapse
-
#batch(logs) ⇒ Object
Logs in batches.
-
#initialize(token:, dimensions: nil, url: "https://ingest.signalfx.com", formatter: nil, **args, &block) ⇒ Signalfx
constructor
Create SignalFx metrics appender.
- #log(log) ⇒ Object
-
#should_log?(log) ⇒ Boolean
Only forward log entries that contain metrics.
Methods inherited from Appender::Http
Methods inherited from Subscriber
#close, #console_output?, #default_formatter, #flush, #level
Methods inherited from Base
#backtrace, #fast_tag, #level, #level=, #measure, #named_tags, #pop_tags, #push_tags, #silence, #tagged, #tags
Constructor Details
#initialize(token:, dimensions: nil, url: "https://ingest.signalfx.com", formatter: nil, **args, &block) ⇒ Signalfx
Create SignalFx metrics appender.
Parameters:
token: [String]
Access Token to use for sending metrics.
Obtain the Signalfx token via the Signalfx Web UI under `Organization` -> `Access Tokens`.
dimensions: [Array<String>]
Dimensions to forward to signalfx when they are present in the named of any log .
By default `application` and `host` are always included as dimensions in all forwarded metrics.
Example: [:user_id, :state]
filter: [Regexp|Proc]
RegExp: Only include log where the class name matches the supplied
regular expression. All other will be ignored.
Proc: Only include log where the supplied Proc returns true.
The Proc must return true or false.
host: [String]
Name of this host to send as a dimension.
Default: SemanticLogger.host
application: [String]
Name of this application to send as a dimension.
Default: SemanticLogger.application
url: [String]
Override the SignalFx service url.
For historical data use: https://backfill.signalfx.com/v1/backfill
Default: https://ingest.signalfx.com
Notes:
When sending a metric to Signalfx, it is necessary to send both a ‘gauge` and a `counter` when a duration is included in the metric, otherwise it is not possible to chart counts of the metric. Unfortunately this doubles the number of metrics, but it is the way Signalfx works. Using a `count` of a `gauge` in a chart will significantly under-count the number of occurrences.
If dimensions are added to the metric, then the metric will be sent as-is and the above logic will not be applied.
Example, Gauge metric, supplying the duration in ‘metric_amount`:
logger.info(metric: 'Filters.average', metric_amount: 1.2, dimensions: {user: 'jbloggs'})
Example, Counter metric:
logger.info(metric: 'Filters.count', dimensions: {user: 'jbloggs'})
Example, Counter metric with a count other than 1:
logger.info(metric: 'Filters.count', metric_amount: 23, dimensions: {user: 'jbloggs'})
When a duration is supplied and no dimensions are supplied:
logger.info(metric: 'Common/User/authorize', duration: 1.4)
Then it is translated into the following 2 log entries under the covers:
logger.info(metric: 'Application.average', metric_amount: 1.4, dimensions: {class: 'Common::User', action: 'authorize'})
logger.info(metric: 'Application.counter', metric_amount: 1, dimensions: {class: 'Common::User', action: 'authorize'})
Similarly with a measure block which automatically supplies the duration:
logger.measure_info(metric: 'Common/User/authorize') do
sleep 1
end
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/semantic_logger/metric/signalfx.rb', line 76 def initialize(token:, dimensions: nil, url: "https://ingest.signalfx.com", formatter: nil, **args, &block) formatter ||= SemanticLogger::Formatters::Signalfx.new(token: token, dimensions: dimensions) super(url: url, formatter: formatter, **args, &block) @header["X-SF-TOKEN"] = token @full_url = "#{url}/#{END_POINT}" end |
Instance Attribute Details
#full_url ⇒ Object (readonly)
Returns the value of attribute full_url.
11 12 13 |
# File 'lib/semantic_logger/metric/signalfx.rb', line 11 def full_url @full_url end |
Instance Method Details
#batch(logs) ⇒ Object
Logs in batches
98 99 100 101 102 |
# File 'lib/semantic_logger/metric/signalfx.rb', line 98 def batch(logs) = formatter.batch(logs, self) logger.trace() post(, full_url) end |
#log(log) ⇒ Object
91 92 93 94 95 |
# File 'lib/semantic_logger/metric/signalfx.rb', line 91 def log(log) = formatter.call(log, self) logger.trace() post(, full_url) end |
#should_log?(log) ⇒ Boolean
Only forward log entries that contain metrics.
105 106 107 |
# File 'lib/semantic_logger/metric/signalfx.rb', line 105 def should_log?(log) log.metric && meets_log_level?(log) && !filtered?(log) end |