statsby 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/statsby/client.rb +12 -14
- data/lib/statsby/context.rb +16 -10
- data/lib/statsby/udp_metrics_writer.rb +26 -0
- data/lib/statsby/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 158693a0295c807d77a240ed7535325d5488dd14
|
|
4
|
+
data.tar.gz: 0c5340f579798b8187a2504e47a49292285ed479
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 07270d223f6df7177e4f53852fab70185c7598ca20a23f2b588b2dd1bc5503fc341089ec060d3b80fefa8c90478ebc8dc30a599fb220046d5895833af41a7de4
|
|
7
|
+
data.tar.gz: 427ece5009e239a92723ab22b2de5e950bf3c9d118165448f21d11a17df8affe89b3bd0c3426dd44aa0e92dee2695db5904bbe1736450d04e1c7c90cbf3d1d6b
|
data/lib/statsby/client.rb
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'statsby/udp_metrics_writer'
|
|
2
2
|
|
|
3
3
|
module Statsby
|
|
4
|
-
# Use a Statsby::Client to send metrics
|
|
4
|
+
# Use a Statsby::Client to send metrics to a StatsD server
|
|
5
5
|
class Client
|
|
6
|
-
|
|
7
|
-
DEFAULT_PORT = 8125
|
|
8
|
-
|
|
9
|
-
attr_reader :socket, :host, :port, :tags, :tags_enabled
|
|
6
|
+
attr_reader :metrics_writer, :tags, :tags_enabled
|
|
10
7
|
|
|
11
8
|
def initialize(
|
|
12
|
-
|
|
13
|
-
port: DEFAULT_PORT,
|
|
9
|
+
metrics_writer: UDPMetricsWriter.new,
|
|
14
10
|
tags: {},
|
|
15
11
|
tags_enabled: true
|
|
16
12
|
)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@tags = Statsby::TagSet.from_hash(tags)
|
|
21
|
-
@tags_enabled = tags_enabled
|
|
13
|
+
self.metrics_writer = metrics_writer
|
|
14
|
+
self.tags = Statsby::TagSet.from_hash(tags)
|
|
15
|
+
self.tags_enabled = tags_enabled
|
|
22
16
|
end
|
|
23
17
|
|
|
24
18
|
def send_message(message)
|
|
25
|
-
|
|
19
|
+
metrics_writer.write(message)
|
|
26
20
|
end
|
|
27
21
|
|
|
28
22
|
def counter(metric_name, value, local_tags = {})
|
|
@@ -53,5 +47,9 @@ module Statsby
|
|
|
53
47
|
def subcontext(tags = {})
|
|
54
48
|
Statsby::Context.new(self, tags)
|
|
55
49
|
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
attr_writer :metrics_writer, :tags, :tags_enabled
|
|
56
54
|
end
|
|
57
55
|
end
|
data/lib/statsby/context.rb
CHANGED
|
@@ -1,46 +1,52 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
1
3
|
require 'statsby/tag_set'
|
|
2
4
|
module Statsby
|
|
3
5
|
# This is meant to be used as a thin layer over a
|
|
4
6
|
# client or another context as a way to organize tags.
|
|
5
7
|
class Context
|
|
6
|
-
attr_reader :
|
|
8
|
+
attr_reader :client, :tags
|
|
7
9
|
|
|
8
|
-
def initialize(
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
def initialize(client, tags = {})
|
|
11
|
+
self.client = client
|
|
12
|
+
self.tags = Statsby::TagSet.from_hash(tags)
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
def counter(metric_name, value, local_tags = {})
|
|
14
16
|
combined_tags = tags.merge(local_tags)
|
|
15
|
-
|
|
17
|
+
client.counter(metric_name, value, combined_tags)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def gauge(metric_name, value, local_tags = {})
|
|
19
21
|
combined_tags = tags.merge(local_tags)
|
|
20
|
-
|
|
22
|
+
client.gauge(metric_name, value, combined_tags)
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def timing(metric_name, value, local_tags = {})
|
|
24
26
|
combined_tags = tags.merge(local_tags)
|
|
25
|
-
|
|
27
|
+
client.timing(metric_name, value, combined_tags)
|
|
26
28
|
end
|
|
27
29
|
|
|
28
30
|
def set(metric_name, value, local_tags = {})
|
|
29
31
|
combined_tags = tags.merge(local_tags)
|
|
30
|
-
|
|
32
|
+
client.set(metric_name, value, combined_tags)
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def format_tags(message_tags = {})
|
|
34
|
-
|
|
36
|
+
client.format_tags(tags.merge(message_tags))
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
def format_message(metric_name, value, type, message_tags = {})
|
|
38
40
|
combined_tags = tags.merge(message_tags)
|
|
39
|
-
|
|
41
|
+
client.format_message(metric_name, value, type, combined_tags)
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
def subcontext(tags = {})
|
|
43
45
|
Statsby::Context.new(self, tags)
|
|
44
46
|
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
attr_writer :client, :tags
|
|
45
51
|
end
|
|
46
52
|
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
|
|
3
|
+
module Statsby
|
|
4
|
+
# Most StatsD endpoints will be UDP.
|
|
5
|
+
# This is a super simple wrapper around UPDSocket
|
|
6
|
+
class UDPMetricsWriter
|
|
7
|
+
DEFAULT_HOST = 'localhost'.freeze
|
|
8
|
+
DEFAULT_PORT = 8125
|
|
9
|
+
|
|
10
|
+
attr_reader :socket, :host, :port
|
|
11
|
+
|
|
12
|
+
def initialize(host = DEFAULT_HOST, port = DEFAULT_PORT)
|
|
13
|
+
self.socket = ::UDPSocket.new
|
|
14
|
+
self.host = host
|
|
15
|
+
self.port = port
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def write(message)
|
|
19
|
+
socket.send(message, 0, host, port)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_writer :socket, :host, :port
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/statsby/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: statsby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- tastybacon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-10-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pry
|
|
@@ -62,6 +62,7 @@ files:
|
|
|
62
62
|
- lib/statsby/client.rb
|
|
63
63
|
- lib/statsby/context.rb
|
|
64
64
|
- lib/statsby/tag_set.rb
|
|
65
|
+
- lib/statsby/udp_metrics_writer.rb
|
|
65
66
|
- lib/statsby/version.rb
|
|
66
67
|
homepage: https://github.com/tastybacon/statsby
|
|
67
68
|
licenses:
|