Class: Statsby::Client
- Inherits:
-
Object
- Object
- Statsby::Client
- Defined in:
- lib/statsby/client.rb
Overview
Use a Statsby::Client to send metrics to a StatsD server
Instance Attribute Summary collapse
-
#metrics_writer ⇒ Object
readonly
Returns the value of attribute metrics_writer.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#tags_enabled ⇒ Object
readonly
Returns the value of attribute tags_enabled.
Instance Method Summary collapse
- #counter(metric_name, value, local_tags = {}) ⇒ Object
- #format_message(metric_name, value, type, message_tags = {}) ⇒ Object
- #format_tags(message_tags = {}) ⇒ Object
- #gauge(metric_name, value, local_tags = {}) ⇒ Object
-
#initialize(metrics_writer: UDPMetricsWriter.new, tags: {}, tags_enabled: true) ⇒ Client
constructor
A new instance of Client.
- #send_message(message) ⇒ Object
- #set(metric_name, value, local_tags = {}) ⇒ Object
- #subcontext(tags = {}) ⇒ Object
- #timing(metric_name, value, local_tags = {}) ⇒ Object
Constructor Details
#initialize(metrics_writer: UDPMetricsWriter.new, tags: {}, tags_enabled: true) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/statsby/client.rb', line 8 def initialize( metrics_writer: UDPMetricsWriter.new, tags: {}, tags_enabled: true ) self.metrics_writer = metrics_writer self. = Statsby::TagSet.from_hash() self. = end |
Instance Attribute Details
#metrics_writer ⇒ Object
Returns the value of attribute metrics_writer.
6 7 8 |
# File 'lib/statsby/client.rb', line 6 def metrics_writer @metrics_writer end |
#tags ⇒ Object
Returns the value of attribute tags.
6 7 8 |
# File 'lib/statsby/client.rb', line 6 def @tags end |
#tags_enabled ⇒ Object
Returns the value of attribute tags_enabled.
6 7 8 |
# File 'lib/statsby/client.rb', line 6 def @tags_enabled end |
Instance Method Details
#counter(metric_name, value, local_tags = {}) ⇒ Object
22 23 24 |
# File 'lib/statsby/client.rb', line 22 def counter(metric_name, value, = {}) ((metric_name, value, 'c', )) end |
#format_message(metric_name, value, type, message_tags = {}) ⇒ Object
43 44 45 |
# File 'lib/statsby/client.rb', line 43 def (metric_name, value, type, = {}) "#{metric_name}#{()}:#{value}|#{type}" end |
#format_tags(message_tags = {}) ⇒ Object
38 39 40 41 |
# File 'lib/statsby/client.rb', line 38 def ( = {}) = .merge() ",#{}" if && !.empty? end |
#gauge(metric_name, value, local_tags = {}) ⇒ Object
26 27 28 |
# File 'lib/statsby/client.rb', line 26 def gauge(metric_name, value, = {}) ((metric_name, value, 'g', )) end |
#send_message(message) ⇒ Object
18 19 20 |
# File 'lib/statsby/client.rb', line 18 def () metrics_writer.write() end |
#set(metric_name, value, local_tags = {}) ⇒ Object
34 35 36 |
# File 'lib/statsby/client.rb', line 34 def set(metric_name, value, = {}) ((metric_name, value, 's', )) end |
#subcontext(tags = {}) ⇒ Object
47 48 49 |
# File 'lib/statsby/client.rb', line 47 def subcontext( = {}) Statsby::Context.new(self, ) end |
#timing(metric_name, value, local_tags = {}) ⇒ Object
30 31 32 |
# File 'lib/statsby/client.rb', line 30 def timing(metric_name, value, = {}) ((metric_name, value, 'ms', )) end |